forked from logstash-plugins/logstash-input-http
-
Notifications
You must be signed in to change notification settings - Fork 4
JSON Array splitting #77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d2ea232
Allow splitting incoming messages with JSON array format
51-code 48f022e
Fix rebase
51-code 19729d2
Use try-with-resources when loading configuration file
51-code d750c72
Add object equality tests for ConversionFactory
51-code daa42ea
Split object equality test into two tests in RegexPayloadTest
51-code 2472f7d
Added missing equals and hashCode functions, added equality tests
51-code 7b30235
Add missing hashCodes to ConversionFactory and LookupConfig
51-code 45d05b4
Remove checking System Properties in ConversionFactory, make end-to-e…
51-code fd57f54
Use rlo_06 for asserting payload correctness, add multithreading test
51-code 5bb31cd
Use expected message amounts instead of result list size as an expect…
51-code File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/main/java/com/teragrep/lsh_01/config/Configuration.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
logstash-http-input to syslog bridge | ||
Copyright 2024 Suomen Kanuuna Oy | ||
|
||
Derivative Work of Elasticsearch | ||
Copyright 2012-2015 Elasticsearch | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package com.teragrep.lsh_01.config; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
public interface Configuration { | ||
|
||
/** | ||
* Get configuration as an unmodifiable map so that it can't be altered anymore. | ||
* | ||
* @return configuration as an unmodifiable map | ||
* @throws IOException if configuration file is not found | ||
*/ | ||
Map<String, String> deepCopyAsUnmodifiableMap() throws IOException; | ||
} |
142 changes: 142 additions & 0 deletions
142
src/main/java/com/teragrep/lsh_01/config/ConversionFactory.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
/* | ||
logstash-http-input to syslog bridge | ||
Copyright 2024 Suomen Kanuuna Oy | ||
|
||
Derivative Work of Elasticsearch | ||
Copyright 2012-2015 Elasticsearch | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package com.teragrep.lsh_01.config; | ||
|
||
import com.teragrep.lsh_01.authentication.BasicAuthentication; | ||
import com.teragrep.lsh_01.conversion.IMessageHandler; | ||
import com.teragrep.lsh_01.conversion.JsonConversion; | ||
import com.teragrep.lsh_01.conversion.RegexConversion; | ||
import com.teragrep.lsh_01.conversion.RelpConversion; | ||
import com.teragrep.lsh_01.pool.IManagedRelpConnection; | ||
import com.teragrep.lsh_01.pool.Pool; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
import java.util.Map; | ||
import java.util.regex.Pattern; | ||
import java.util.regex.PatternSyntaxException; | ||
|
||
public final class ConversionFactory { | ||
|
||
private final static Logger LOGGER = LogManager.getLogger(ConversionFactory.class); | ||
|
||
private final String splitType; | ||
private final String regexPattern; | ||
private final Pool<IManagedRelpConnection> pool; | ||
private final SecurityConfig securityConfig; | ||
private final BasicAuthentication basicAuthentication; | ||
private final LookupConfig lookupConfig; | ||
|
||
public ConversionFactory( | ||
Map<String, String> configuration, | ||
Pool<IManagedRelpConnection> pool, | ||
SecurityConfig securityConfig, | ||
BasicAuthentication basicAuthentication, | ||
LookupConfig lookupConfig | ||
) { | ||
// if system property is not specified, defaults to config file (the Map) | ||
this( | ||
kortemik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
System.getProperty("payload.splitType", configuration.get("payload.splitType")), | ||
System | ||
.getProperty( | ||
"payload.splitType.regex.pattern", configuration.get("payload.splitType.regex.pattern") | ||
), | ||
pool, | ||
securityConfig, | ||
basicAuthentication, | ||
lookupConfig | ||
); | ||
} | ||
|
||
public ConversionFactory( | ||
String splitType, | ||
String regexPattern, | ||
Pool<IManagedRelpConnection> pool, | ||
SecurityConfig securityConfig, | ||
BasicAuthentication basicAuthentication, | ||
LookupConfig lookupConfig | ||
) { | ||
this.splitType = splitType; | ||
this.regexPattern = regexPattern; | ||
this.pool = pool; | ||
this.securityConfig = securityConfig; | ||
this.basicAuthentication = basicAuthentication; | ||
this.lookupConfig = lookupConfig; | ||
} | ||
|
||
public IMessageHandler conversion() { | ||
LOGGER | ||
.info( | ||
"Creating IMessageHandler with given configuration: payload.splitType=<[{}]>, payload.splitType.regex.pattern=<[{}]>", | ||
splitType, regexPattern | ||
); | ||
|
||
validateConfiguration(); | ||
|
||
IMessageHandler conversion = new RelpConversion(pool, securityConfig, basicAuthentication, lookupConfig); | ||
|
||
// apply splitting if configured. "none" value is skipped | ||
switch (splitType) { | ||
case "regex": | ||
conversion = new RegexConversion(conversion, regexPattern); | ||
break; | ||
case "json_array": | ||
conversion = new JsonConversion(conversion); | ||
break; | ||
} | ||
|
||
return conversion; | ||
} | ||
|
||
private void validateConfiguration() { | ||
switch (splitType) { | ||
case "regex": | ||
try { | ||
Pattern.compile(regexPattern); | ||
} | ||
catch (PatternSyntaxException e) { | ||
throw new IllegalArgumentException( | ||
"Configuration has an invalid regex (payload.splitType.regex.pattern): " + regexPattern | ||
); | ||
} | ||
break; | ||
case "json_array": | ||
case "none": | ||
break; | ||
default: | ||
throw new IllegalArgumentException( | ||
"Configuration has an invalid splitType: " + splitType | ||
+ ". Has to be 'regex', 'json_array' or 'none'." | ||
); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) | ||
return true; | ||
if (o == null || getClass() != o.getClass()) | ||
return false; | ||
final ConversionFactory cast = (ConversionFactory) o; | ||
return splitType.equals(cast.splitType) && regexPattern.equals(cast.regexPattern) && pool | ||
.equals(cast.pool) && securityConfig.equals(cast.securityConfig) | ||
&& basicAuthentication.equals(cast.basicAuthentication) && lookupConfig.equals(cast.lookupConfig); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.