Skip to content

Commit 9fd35ad

Browse files
author
anders-wartoft
committed
1.06-SNAPSHOT
1 parent aa566e1 commit 9fd35ad

73 files changed

Lines changed: 254 additions & 244 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ java -jar target/LogGenerator-with-dependencies.jar -i kafka -icn test2 -itn tes
1616
When running the last command, press Ctrl-C to see the gaps in the received data. Since we started the counter on 100, there should at least be one gap: 1-99.
1717

1818
### Latest Release notes
19-
#### 1.05
20-
- SelectFilter added. Use a regular expression to specify what to keep in each event
21-
- GapDetection will now print gaps each time the statistics is printed. Events that appear out of order will now be reflected without need to shut down the receiver.
19+
#### 1.06-SNAPSHOT
20+
- DropFilter added. Use a regular expression to specify events to drop
21+
- DateSubstitute now supports epoch format
22+
- Moved headers to last in event chain. Headers will now be created after all other filters have been executed
23+
- The eps limiter can now use floating points, so to send one event every 4 seconds, use -e 0.25
2224

2325
### Input modules:
2426
There are input module for the following tasks:
@@ -274,6 +276,8 @@ In another command window, start the client (same jar file):
274276
### Filter modules:
275277
- Add a header
276278
- Replace by regex
279+
- Select by regex
280+
- Drop by regex
277281
- Replace variables
278282
- Remove transaction messages
279283
- Detect gaps
@@ -302,6 +306,22 @@ and for example want to extract the first word after the timestamp, you can use
302306

303307
`-se '\.\d{3} (\S+) '`
304308

309+
### Drop by regex
310+
If you want to drop an event depending on a regular expression, use the DropFilter.
311+
Use a regex to specify the content to search for. If the DropFilter finds a match, the event will be dropped.
312+
313+
Parameters: `-df {regex}`
314+
315+
Example: `-df 'INFO'`
316+
317+
If you have events that are formatted like this:
318+
319+
`[Sat Dec 03 00:35:57.399 Usb Host Notification Apple80211Set: seqNum 5460 Total 1 chg 0 en0]`
320+
321+
and for example want to discard all events that contain `chg 0`, you can use the following parameters:
322+
323+
`-df 'chg 0'`
324+
305325
#### Replace by regex
306326
A use case is if you have a lot of nice logs, but the date is not possible to use. You can load the file and add a regex to find the date, then replace the date with a {date:...} variable or a static string.
307327
There must be a capture group in the regex. The text matched by the capture group will be replaced by the value.
@@ -386,13 +406,14 @@ So, the gap detection can detect events that should have been delivered earlier,
386406
### Variables
387407
#### Date
388408
A Date variable will take the current time and format according to a Java
389-
date format string.
409+
date format string. Epoch timestamps are supported but only the version with 13 digits.
390410

391-
Syntax: `{date:(?<datepattern>[yYmMHhsz+-dD:\d'T. ]+)(/(?<locale>[^}]+))?}`
411+
Syntax: `{date:(?<datepattern>[yYmMHhsz+-dD:\d'T. ]+|epoch)(/(?<locale>[^}]+))?}`
392412

393413
Example (at new year 2023)
394414
- `{date:yyyyMMdd}` might be resolved to: `20230101`
395415
- `{date:MMM dd HH:mm:ss/en:US}` might be resolved to `Jan 01 00:00:00`
416+
- `{date:epoch}` might be resolved to e.g., `0946681200000` (for Jan 01, 2000)
396417

397418
Date can also have an offset with the `-to` (`--time-offset`) parameter. Time offset can be used to add or remove a number of milliseconds from the date variable.
398419

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>nu.sitia.LogGenerator</groupId>
66
<artifactId>LogGenerator</artifactId>
7-
<version>1.05-SNAPSHOT</version>
7+
<version>1.06-SNAPSHOT</version>
88
<packaging>jar</packaging>
99

1010
<name>LogGenerator</name>

src/main/java/nu/sitia/loggenerator/App.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Software.
1111
*
1212
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13-
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
13+
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
1414
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
1515
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1616
*/

src/main/java/nu/sitia/loggenerator/Configuration.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ public class Configuration {
112112
keys.add(new Item("-jf", "--json-filter", "Get a specific node in the JSON input. Use . to traverse the JSON input. If the returned object is an array, the array items are sent in the event chain as new events"));
113113
keys.add(new Item("-jfp", "--json-file-path", "Get a specific node in the JSON file input. Use . to traverse the JSON input. If the returned object is an array, the array items are sent in the event chain as new events"));
114114
keys.add(new Item("-se", "--select", "Remove everything except what matches the next argument's first group. Example -se 'userid:(\\S+)'"));
115+
keys.add(new Item("-df", "--drop-filter", "Drop an event if the supplied regex is found in an event. Example -df 'INFO|DEBUG'"));
115116
}
116117
static final Map<String, String> standardVariables = new HashMap<>();
117118
static {

src/main/java/nu/sitia/loggenerator/ItemProxy.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Software.
1111
*
1212
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13-
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
13+
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
1414
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
1515
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1616
*/
@@ -48,7 +48,7 @@ public class ItemProxy {
4848
private final List<ProcessFilter> filterList;
4949

5050
/** Preferred eps */
51-
private final long eps;
51+
private final double eps;
5252

5353
/** Limit the number of events to send */
5454
private final long limit;
@@ -89,7 +89,7 @@ public ItemProxy(InputItem input, OutputItem output, List<ProcessFilter> filterL
8989

9090
String epsString = config.getValue("-e");
9191
if (null != epsString) {
92-
this.eps = Long.parseLong(epsString);
92+
this.eps = Double.parseDouble(epsString);
9393
} else {
9494
this.eps = 0;
9595
}
@@ -119,8 +119,8 @@ public ItemProxy(InputItem input, OutputItem output, List<ProcessFilter> filterL
119119
shutdownHandlers.add((ShutdownHandler) output);
120120
}
121121

122-
String isContinousGapDetectionString = config.getValue("-cgd");
123-
if (isContinousGapDetectionString != null && isContinousGapDetectionString.equalsIgnoreCase("true")) {
122+
String isContinuousGapDetectionString = config.getValue("-cgd");
123+
if (isContinuousGapDetectionString != null && isContinuousGapDetectionString.equalsIgnoreCase("true")) {
124124
gapDetector = getGapDetector(filterList);
125125
if (null == gapDetector) {
126126
throw new RuntimeException("The flag -cgd cannot be used without a GapDetector (-gd)");
@@ -150,7 +150,7 @@ public ItemProxy(InputItem input, OutputItem output, List<ProcessFilter> filterL
150150

151151

152152
/**
153-
* Search the list of filters and, if present, return a GapDetecttionFilter
153+
* Search the list of filters and, if present, return a GapDetectionFilter
154154
* @param filterList a List<filter> to search
155155
* @return GapDetectionFilter or null
156156
*/
@@ -238,7 +238,7 @@ private void throttle(LogStatistics statistics) {
238238
long sentMessages = statistics.getTransactionMessages();
239239
long now = new Date().getTime();
240240
// how long time should we spend on sending these messages?
241-
long estimatedTime = 1000 * sentMessages / eps;
241+
long estimatedTime = (long)(1000 * sentMessages / eps);
242242
long waitTime = transactionStart + estimatedTime - now;
243243
if (waitTime > 10) {
244244
try {

src/main/java/nu/sitia/loggenerator/ShutdownHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Software.
1111
*
1212
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13-
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
13+
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
1414
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
1515
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1616
*/
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* Copyright 2022 sitia.nu https://github.com/anders-wartoft/LogGenerator
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5+
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
6+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
7+
* persons to whom the Software is furnished to do so, subject to the following conditions:
8+
*
9+
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
10+
* Software.
11+
*
12+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13+
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
14+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
15+
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16+
*/
17+
18+
package nu.sitia.loggenerator.filter;
19+
20+
21+
import java.util.ArrayList;
22+
import java.util.List;
23+
import java.util.regex.Matcher;
24+
import java.util.regex.Pattern;
25+
26+
public class DropFilter implements ProcessFilter {
27+
/** Cached regex pattern */
28+
private final Pattern pattern;
29+
30+
/** for toString() */
31+
private final String regex;
32+
33+
/**
34+
* Create a RegexFilter and set all parameters
35+
* @param regex The value to search for
36+
*/
37+
public DropFilter(String regex) {
38+
this.regex = regex;
39+
// What to look for
40+
if (null == regex) {
41+
throw new RuntimeException("regex is null");
42+
}
43+
pattern = Pattern.compile(regex);
44+
}
45+
46+
/**
47+
* Filter one string
48+
*
49+
* @param toFilter The string to change
50+
* @return toFilter with a header added before the string.
51+
*/
52+
private String filter(String toFilter) {
53+
Matcher matcher = pattern.matcher(toFilter);
54+
if (matcher.find()) {
55+
// Drop this one
56+
return null;
57+
}
58+
return toFilter;
59+
}
60+
61+
@Override
62+
public List<String> filter(List<String> toFilter) {
63+
List<String> filtered = new ArrayList<>();
64+
toFilter.forEach(s -> {
65+
String result = filter(s);
66+
if (result != null) {
67+
filtered.add(result);
68+
}
69+
});
70+
71+
return filtered;
72+
}
73+
74+
/**
75+
* The current configuration
76+
* @return A printout of the current configuration
77+
*/
78+
@Override
79+
public String toString() {
80+
return "DropFilter" + System.lineSeparator() + regex + System.lineSeparator();
81+
}
82+
}

src/main/java/nu/sitia/loggenerator/filter/FilterListFactory.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Software.
1111
*
1212
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13-
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
13+
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
1414
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
1515
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1616
*/
@@ -43,7 +43,8 @@ public List<ProcessFilter> create(Configuration config) {
4343
String jsonFilter = config.getValue("-jf");
4444
String jsonReport = config.getValue("-gdjr");
4545
String select = config.getValue("-se");
46-
46+
String drop = config.getValue("-df");
47+
boolean df = "true".equalsIgnoreCase(drop);
4748
boolean dd = "true".equalsIgnoreCase(doubleDetection);
4849

4950
List<ProcessFilter> filterList = new LinkedList<>();
@@ -52,12 +53,12 @@ public List<ProcessFilter> create(Configuration config) {
5253
filterList.add(new GuardFilter(config));
5354
}
5455

55-
if (regex != null) {
56-
filterList.add(new RegexFilter(regex, value));
56+
if (df) {
57+
filterList.add(new DropFilter(regex));
5758
}
5859

59-
if (header != null) {
60-
filterList.add(new HeaderFilter(header));
60+
if (regex != null) {
61+
filterList.add(new RegexFilter(regex, value));
6162
}
6263

6364
Template template1 = new NoneTemplate();
@@ -83,6 +84,11 @@ public List<ProcessFilter> create(Configuration config) {
8384
if (select != null) {
8485
filterList.add(new SelectFilter(select));
8586
}
87+
88+
if (header != null) {
89+
filterList.add(new HeaderFilter(header));
90+
}
91+
8692
return filterList;
8793
}
8894
}

src/main/java/nu/sitia/loggenerator/filter/GapDetectionFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Software.
1111
*
1212
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13-
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
13+
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
1414
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
1515
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1616
*/

src/main/java/nu/sitia/loggenerator/filter/GuardFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Software.
1111
*
1212
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13-
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
13+
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
1414
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
1515
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1616
*/

0 commit comments

Comments
 (0)