use of com.microsoft.applicationinsights.agent.internal.configuration.Configuration.PreviewConfiguration in project ApplicationInsights-Java by microsoft.
the class ConfigurationTest method shouldParseProcessorConfiguration.
@Test
void shouldParseProcessorConfiguration() throws IOException {
Configuration configuration = loadConfiguration("ApplicationInsights_SpanProcessor.json");
PreviewConfiguration preview = configuration.preview;
assertThat(configuration.connectionString).isEqualTo("InstrumentationKey=00000000-0000-0000-0000-000000000000");
assertThat(preview.processors.size()).isEqualTo(10);
// insert config test
ProcessorConfig insertConfig = preview.processors.get(0);
assertThat(insertConfig.id).isEqualTo("attributes/insert");
assertThat(insertConfig.type).isEqualTo(ProcessorType.ATTRIBUTE);
assertThat(insertConfig.actions.get(0).action).isEqualTo(ProcessorActionType.INSERT);
assertThat(insertConfig.actions.get(0).value).isEqualTo("123");
assertThat(insertConfig.actions.get(0).key).isEqualTo(AttributeKey.stringKey("attribute1"));
assertThat(insertConfig.actions.get(1).fromAttribute).isEqualTo(AttributeKey.stringKey("anotherKey"));
// update config test
ProcessorConfig updateConfig = preview.processors.get(1);
assertThat(updateConfig.id).isEqualTo("attributes/update");
assertThat(updateConfig.type).isEqualTo(ProcessorType.ATTRIBUTE);
assertThat(updateConfig.actions.get(0).action).isEqualTo(ProcessorActionType.UPDATE);
assertThat(updateConfig.actions.get(0).key).isEqualTo(AttributeKey.stringKey("boo"));
assertThat(updateConfig.actions.get(0).fromAttribute).isEqualTo(AttributeKey.stringKey("foo"));
assertThat(updateConfig.actions.get(1).key).isEqualTo(AttributeKey.stringKey("db.secret"));
// selective processing test
ProcessorConfig selectiveConfig = preview.processors.get(2);
assertThat(selectiveConfig.type).isEqualTo(ProcessorType.ATTRIBUTE);
assertThat(selectiveConfig.id).isEqualTo("attributes/selectiveProcessing");
assertThat(selectiveConfig.include.matchType).isEqualTo(MatchType.STRICT);
assertThat(selectiveConfig.include.spanNames.size()).isEqualTo(2);
assertThat(selectiveConfig.include.spanNames.get(0)).isEqualTo("svcA");
assertThat(selectiveConfig.exclude.matchType).isEqualTo(MatchType.STRICT);
assertThat(selectiveConfig.exclude.attributes.size()).isEqualTo(1);
assertThat(selectiveConfig.exclude.attributes.get(0).key).isEqualTo("redact_trace");
assertThat(selectiveConfig.exclude.attributes.get(0).value).isEqualTo("false");
assertThat(selectiveConfig.actions.size()).isEqualTo(2);
assertThat(selectiveConfig.actions.get(0).key).isEqualTo(AttributeKey.stringKey("credit_card"));
assertThat(selectiveConfig.actions.get(0).action).isEqualTo(ProcessorActionType.DELETE);
// log/update name test
ProcessorConfig logUpdateNameConfig = preview.processors.get(3);
assertThat(logUpdateNameConfig.type).isEqualTo(ProcessorType.LOG);
assertThat(logUpdateNameConfig.id).isEqualTo("log/updateName");
assertThat(logUpdateNameConfig.body.fromAttributes.size()).isEqualTo(1);
assertThat(logUpdateNameConfig.body.fromAttributes.get(0)).isEqualTo("loggerName");
assertThat(logUpdateNameConfig.body.separator).isEqualTo("::");
// log/extractAttributes
ProcessorConfig logExtractAttributesConfig = preview.processors.get(4);
assertThat(logExtractAttributesConfig.type).isEqualTo(ProcessorType.LOG);
assertThat(logExtractAttributesConfig.id).isEqualTo("log/extractAttributes");
assertThat(logExtractAttributesConfig.body.toAttributes.rules.size()).isEqualTo(1);
assertThat(logExtractAttributesConfig.body.toAttributes.rules.get(0)).isEqualTo("^/api/v1/document/(?<documentId>.*)/update$");
// span/update name test
ProcessorConfig spanUpdateNameConfig = preview.processors.get(5);
assertThat(spanUpdateNameConfig.type).isEqualTo(ProcessorType.SPAN);
assertThat(spanUpdateNameConfig.id).isEqualTo("span/updateName");
assertThat(spanUpdateNameConfig.include.matchType).isEqualTo(MatchType.REGEXP);
assertThat(spanUpdateNameConfig.include.spanNames.size()).isEqualTo(1);
assertThat(spanUpdateNameConfig.include.spanNames.get(0)).isEqualTo(".*password.*");
assertThat(spanUpdateNameConfig.name.fromAttributes.size()).isEqualTo(1);
assertThat(spanUpdateNameConfig.name.fromAttributes.get(0)).isEqualTo("loggerName");
assertThat(spanUpdateNameConfig.name.separator).isEqualTo("::");
// span/extractAttributes
ProcessorConfig spanExtractAttributesConfig = preview.processors.get(6);
assertThat(spanExtractAttributesConfig.type).isEqualTo(ProcessorType.SPAN);
assertThat(spanExtractAttributesConfig.id).isEqualTo("span/extractAttributes");
assertThat(spanExtractAttributesConfig.name.toAttributes.rules.size()).isEqualTo(1);
assertThat(spanExtractAttributesConfig.name.toAttributes.rules.get(0)).isEqualTo("^/api/v1/document/(?<documentId>.*)/update$");
// attribute/extract
ProcessorConfig attributesExtractConfig = preview.processors.get(7);
assertThat(attributesExtractConfig.type).isEqualTo(ProcessorType.ATTRIBUTE);
assertThat(attributesExtractConfig.id).isEqualTo("attributes/extract");
assertThat(attributesExtractConfig.actions.size()).isEqualTo(1);
assertThat(attributesExtractConfig.actions.get(0).action).isEqualTo(ProcessorActionType.EXTRACT);
assertThat(attributesExtractConfig.actions.get(0).key).isEqualTo(AttributeKey.stringKey("http.url"));
assertThat(attributesExtractConfig.actions.get(0).extractAttribute).isNotNull();
assertThat(attributesExtractConfig.actions.get(0).extractAttribute.pattern).isNotNull();
assertThat(attributesExtractConfig.actions.get(0).extractAttribute.groupNames.size()).isEqualTo(4);
assertThat(attributesExtractConfig.actions.get(0).extractAttribute.groupNames.get(0)).isEqualTo("httpProtocol");
// metric-filter
ProcessorConfig metricFilterConfig = preview.processors.get(8);
assertThat(metricFilterConfig.type).isEqualTo(ProcessorType.METRIC_FILTER);
assertThat(metricFilterConfig.id).isEqualTo("metric-filter/exclude-two-metrics");
assertThat(metricFilterConfig.exclude.matchType).isEqualTo(MatchType.STRICT);
assertThat(metricFilterConfig.exclude.metricNames.size()).isEqualTo(2);
assertThat(metricFilterConfig.exclude.metricNames.get(0)).isEqualTo("a_test_metric");
assertThat(metricFilterConfig.exclude.metricNames.get(1)).isEqualTo("another_test_metric");
// attribute/mask
ProcessorConfig attributesMaskConfig = preview.processors.get(9);
assertThat(attributesMaskConfig.type).isEqualTo(ProcessorType.ATTRIBUTE);
assertThat(attributesMaskConfig.id).isEqualTo("attributes/mask");
assertThat(attributesMaskConfig.actions.size()).isEqualTo(1);
assertThat(attributesMaskConfig.actions.get(0).action).isEqualTo(ProcessorActionType.MASK);
assertThat(attributesMaskConfig.actions.get(0).key).isEqualTo(AttributeKey.stringKey("http.url"));
assertThat(attributesMaskConfig.actions.get(0).maskAttribute).isNotNull();
assertThat(attributesMaskConfig.actions.get(0).maskAttribute.pattern).isNotNull();
assertThat(attributesMaskConfig.actions.get(0).maskAttribute.groupNames.size()).isEqualTo(3);
assertThat(attributesMaskConfig.actions.get(0).maskAttribute.groupNames.get(0)).isEqualTo("uriNoCard");
assertThat(attributesMaskConfig.actions.get(0).maskAttribute.replace).isEqualTo("${uriNoCard}****${cardEnd}");
}
use of com.microsoft.applicationinsights.agent.internal.configuration.Configuration.PreviewConfiguration in project ApplicationInsights-Java by microsoft.
the class ConfigurationTest method shouldParseAuthenticationConfiguration.
@Test
void shouldParseAuthenticationConfiguration() throws IOException {
Configuration configuration = loadConfiguration("applicationinsights_aadauth.json");
PreviewConfiguration preview = configuration.preview;
assertThat(configuration.connectionString).isEqualTo("InstrumentationKey=00000000-0000-0000-0000-000000000000");
assertThat(preview.authentication.enabled).isTrue();
assertThat(preview.authentication.type).isEqualTo(Configuration.AuthenticationType.SAMI);
assertThat(preview.authentication.clientId).isEqualTo("123xyz");
assertThat(preview.authentication.tenantId).isEqualTo("tenant123");
assertThat(preview.authentication.clientSecret).isEqualTo("clientsecret123");
assertThat(preview.authentication.authorityHost).isEqualTo("https://test.com/microsoft/");
}
Aggregations