Skip to content

Commit

Permalink
chore: record errors in Config
Browse files Browse the repository at this point in the history
  • Loading branch information
Vihas Splunk committed Mar 15, 2024
1 parent 0d009fc commit 1d77126
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
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

0 comments on commit 1d77126

Please sign in to comment.