Skip to content
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

chore: record errors in Config #426

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/main/java/com/splunk/kafka/connect/SplunkSinkConnector.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,17 @@ private void validateSplunkConfigurations(final Map<String, String> configs) thr
if (configs.containsKey(DISABLE_VALIDATION) && Boolean.parseBoolean(configs.get(DISABLE_VALIDATION))) {
return;
}
if (configs.getOrDefault(TOKEN_CONF,"").equals("")
|| configs.getOrDefault(URI_CONF,"").equals("")) {
String errorMessage = String.format(
"Either one of '%s' or '%s' must be set for Splunk validation check.",
TOKEN_CONF,
URI_CONF
);
addErrorMessage(TOKEN_CONF, errorMessage);
addErrorMessage(URI_CONF, errorMessage);
return;
}
SplunkSinkConnectorConfig connectorConfig = new SplunkSinkConnectorConfig(configs);
String[] indexes = split(connectorConfig.indexes, ",");
if(indexes == null || indexes.length == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,19 @@ public void config() {
ConfigDef config = connector.config();
Assert.assertNotNull(config);
}

@Test
public void testErrorWithoutUriConf() {
final Map<String, String> configs = new HashMap<>();
SinkConnector connector = new SplunkSinkConnector();
configs.put("topics", "b");
configs.put("splunk.indexes", "b");
MockHecClientWrapper clientInstance = new MockHecClientWrapper();
((SplunkSinkConnector) connector).setHecInstance(clientInstance);
Config result = connector.validate(configs);
assertHasErrorMessage(result, URI_CONF, "Either one of 'splunk.hec.token' or 'splunk.hec.uri' must be set for Splunk validation check.", 1);
assertHasErrorMessage(result, TOKEN_CONF, "Either one of 'splunk.hec.token' or 'splunk.hec.uri' must be set for Splunk validation check.", 1);
}

@Test
public void testValidKerberosBothEmpty() {
final Map<String, String> configs = new HashMap<>();
Expand Down Expand Up @@ -304,12 +316,15 @@ private void addNecessaryConfigs(Map<String, String> configs) {
configs.put(URI_CONF, TEST_URI);
configs.put(TOKEN_CONF, "blah");
}

private void assertHasErrorMessage(Config config, String property, String msg) {
assertHasErrorMessage(config, property, msg, 0);
}
private void assertHasErrorMessage(Config config, String property, String msg, int idx) {
for (ConfigValue configValue : config.configValues()) {
if (configValue.name().equals(property)) {
System.out.print(configValue.errorMessages());
assertFalse(configValue.errorMessages().isEmpty());
assertTrue(configValue.errorMessages().get(0).contains(msg));
assertTrue(configValue.errorMessages().get(idx).contains(msg));
}
}
}
Expand Down
Loading