Search in sources :

Example 6 with TelemetryClient

use of com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient in project ApplicationInsights-Java by microsoft.

the class RpConfigurationPollingTest method shouldUpdate.

@Test
void shouldUpdate() throws URISyntaxException {
    // given
    RpConfiguration rpConfiguration = new RpConfiguration();
    rpConfiguration.connectionString = "InstrumentationKey=11111111-1111-1111-1111-111111111111";
    rpConfiguration.sampling.percentage = 90;
    rpConfiguration.configPath = Paths.get(RpConfigurationPollingTest.class.getResource("/applicationinsights-rp.json").toURI());
    rpConfiguration.lastModifiedTime = 0;
    TelemetryClient telemetryClient = TelemetryClient.createForTest();
    telemetryClient.setConnectionString("InstrumentationKey=00000000-0000-0000-0000-000000000000");
    AppIdSupplier appIdSupplier = new AppIdSupplier(telemetryClient);
    BytecodeUtilImpl.samplingPercentage = 100;
    // pre-check
    assertThat(telemetryClient.getInstrumentationKey()).isEqualTo("00000000-0000-0000-0000-000000000000");
    assertThat(BytecodeUtilImpl.samplingPercentage).isEqualTo(100);
    assertThat(getCurrentSamplingPercentage()).isEqualTo(100);
    // when
    new RpConfigurationPolling(rpConfiguration, new Configuration(), telemetryClient, appIdSupplier).run();
    // then
    assertThat(telemetryClient.getInstrumentationKey()).isEqualTo("00000000-0000-0000-0000-000000000000");
    assertThat(BytecodeUtilImpl.samplingPercentage).isEqualTo(10);
    assertThat(getCurrentSamplingPercentage()).isEqualTo(10);
}
Also used : Configuration(com.microsoft.applicationinsights.agent.internal.configuration.Configuration) RpConfiguration(com.microsoft.applicationinsights.agent.internal.configuration.RpConfiguration) RpConfiguration(com.microsoft.applicationinsights.agent.internal.configuration.RpConfiguration) TelemetryClient(com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient) Test(org.junit.jupiter.api.Test)

Example 7 with TelemetryClient

use of com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient in project ApplicationInsights-Java by microsoft.

the class RpConfigurationPollingTest method shouldBePopulatedByEnvVars.

@Test
void shouldBePopulatedByEnvVars() throws URISyntaxException {
    // given
    RpConfiguration rpConfiguration = new RpConfiguration();
    rpConfiguration.connectionString = "InstrumentationKey=11111111-1111-1111-1111-111111111111";
    rpConfiguration.sampling.percentage = 90;
    rpConfiguration.configPath = Paths.get(RpConfigurationPollingTest.class.getResource("/applicationinsights-rp.json").toURI());
    rpConfiguration.lastModifiedTime = 0;
    TelemetryClient telemetryClient = TelemetryClient.createForTest();
    telemetryClient.setConnectionString("InstrumentationKey=00000000-0000-0000-0000-000000000000");
    AppIdSupplier appIdSupplier = new AppIdSupplier(telemetryClient);
    BytecodeUtilImpl.samplingPercentage = 100;
    envVars.set("APPLICATIONINSIGHTS_CONNECTION_STRING", "InstrumentationKey=00000000-0000-0000-0000-000000000000");
    envVars.set("APPLICATIONINSIGHTS_SAMPLING_PERCENTAGE", "90");
    // pre-check
    assertThat(telemetryClient.getInstrumentationKey()).isEqualTo("00000000-0000-0000-0000-000000000000");
    assertThat(BytecodeUtilImpl.samplingPercentage).isEqualTo(100);
    assertThat(getCurrentSamplingPercentage()).isEqualTo(100);
    // when
    new RpConfigurationPolling(rpConfiguration, new Configuration(), telemetryClient, appIdSupplier).run();
    // then
    assertThat(telemetryClient.getInstrumentationKey()).isEqualTo("00000000-0000-0000-0000-000000000000");
    assertThat(BytecodeUtilImpl.samplingPercentage).isEqualTo(100);
    assertThat(getCurrentSamplingPercentage()).isEqualTo(100);
}
Also used : Configuration(com.microsoft.applicationinsights.agent.internal.configuration.Configuration) RpConfiguration(com.microsoft.applicationinsights.agent.internal.configuration.RpConfiguration) RpConfiguration(com.microsoft.applicationinsights.agent.internal.configuration.RpConfiguration) TelemetryClient(com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient) Test(org.junit.jupiter.api.Test)

Example 8 with TelemetryClient

use of com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient in project ApplicationInsights-Java by microsoft.

the class QuickPulseIntegrationTests method getQuickPulsePingSender.

private QuickPulsePingSender getQuickPulsePingSender() {
    TelemetryClient telemetryClient = TelemetryClient.createForTest();
    telemetryClient.setConnectionString(connectionString);
    return new QuickPulsePingSender(getHttpPipeline(), telemetryClient, "machine1", "instance1", "qpid123");
}
Also used : TelemetryClient(com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient)

Example 9 with TelemetryClient

use of com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient in project ApplicationInsights-Java by microsoft.

the class QuickPulseIntegrationTests method getQuickPulsePingSenderWithValidator.

private QuickPulsePingSender getQuickPulsePingSenderWithValidator(HttpPipelinePolicy validator) {
    TelemetryClient telemetryClient = TelemetryClient.createForTest();
    telemetryClient.setConnectionString(connectionString);
    return new QuickPulsePingSender(getHttpPipeline(validator), telemetryClient, "machine1", "instance1", "qpid123");
}
Also used : TelemetryClient(com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient)

Example 10 with TelemetryClient

use of com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient in project ApplicationInsights-Java by microsoft.

the class QuickPulsePingSenderTests method endpointChangesWithRedirectHeaderAndGetNewPingInterval.

@Test
void endpointChangesWithRedirectHeaderAndGetNewPingInterval() {
    Map<String, String> headers = new HashMap<>();
    headers.put("x-ms-qps-service-polling-interval-hint", "1000");
    headers.put("x-ms-qps-service-endpoint-redirect", "https://new.endpoint.com");
    headers.put("x-ms-qps-subscribed", "true");
    HttpHeaders httpHeaders = new HttpHeaders(headers);
    TelemetryClient telemetryClient = TelemetryClient.createForTest();
    telemetryClient.setInstrumentationKey("fake-ikey");
    HttpPipeline httpPipeline = new HttpPipelineBuilder().httpClient(request -> Mono.just(new MockHttpResponse(request, 200, httpHeaders))).build();
    QuickPulsePingSender quickPulsePingSender = new QuickPulsePingSender(httpPipeline, telemetryClient, "machine1", "instance1", "qpid123");
    QuickPulseHeaderInfo quickPulseHeaderInfo = quickPulsePingSender.ping(null);
    assertThat(QuickPulseStatus.QP_IS_ON).isEqualTo(quickPulseHeaderInfo.getQuickPulseStatus());
    assertThat(1000).isEqualTo(quickPulseHeaderInfo.getQpsServicePollingInterval());
    assertThat("https://new.endpoint.com").isEqualTo(quickPulseHeaderInfo.getQpsServiceEndpointRedirect());
}
Also used : Test(org.junit.jupiter.api.Test) TelemetryClient(com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HttpPipeline(com.azure.core.http.HttpPipeline) URISyntaxException(java.net.URISyntaxException) Map(java.util.Map) MockHttpResponse(com.microsoft.applicationinsights.agent.internal.MockHttpResponse) HashMap(java.util.HashMap) Mono(reactor.core.publisher.Mono) HttpHeaders(com.azure.core.http.HttpHeaders) URI(java.net.URI) HttpPipelineBuilder(com.azure.core.http.HttpPipelineBuilder) HttpHeaders(com.azure.core.http.HttpHeaders) HashMap(java.util.HashMap) HttpPipeline(com.azure.core.http.HttpPipeline) HttpPipelineBuilder(com.azure.core.http.HttpPipelineBuilder) TelemetryClient(com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient) MockHttpResponse(com.microsoft.applicationinsights.agent.internal.MockHttpResponse) Test(org.junit.jupiter.api.Test)

Aggregations

TelemetryClient (com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient)28 Test (org.junit.jupiter.api.Test)21 TelemetryItem (com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem)7 Configuration (com.microsoft.applicationinsights.agent.internal.configuration.Configuration)6 URI (java.net.URI)5 FinalCounters (com.microsoft.applicationinsights.agent.internal.quickpulse.QuickPulseDataCollector.FinalCounters)4 RpConfiguration (com.microsoft.applicationinsights.agent.internal.configuration.RpConfiguration)3 Date (java.util.Date)3 HttpHeaders (com.azure.core.http.HttpHeaders)2 HttpPipeline (com.azure.core.http.HttpPipeline)2 HttpPipelineBuilder (com.azure.core.http.HttpPipelineBuilder)2 MockHttpResponse (com.microsoft.applicationinsights.agent.internal.MockHttpResponse)2 ProcessorConfig (com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProcessorConfig)2 AiLegacyHeaderSpanProcessor (com.microsoft.applicationinsights.agent.internal.legacyheaders.AiLegacyHeaderSpanProcessor)2 URISyntaxException (java.net.URISyntaxException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Mono (reactor.core.publisher.Mono)2 HttpRequest (com.azure.core.http.HttpRequest)1