Skip to content

Commit

Permalink
Merge main into vnext (#2099)
Browse files Browse the repository at this point in the history
* Support Statsbeat in EU regions (#2082)

* Use a diff statsbeat ikey in eu regions

* Use lowercase

* Fix spotless

* Reserve statsbeat config when applicable

* Make test easier to understand

* Remove unused constants

* Decouple TelemetryClient

* Add comments

* Refactor

* Fix spotless

* Remove assignment

* Fix tests

* Convert url to string

* Use regex

* Strict protocol

* No need to escape dash

* Remove escape

* Add a startup profiler for debugging (#2085)

* Add StartupProfiler

* Fix errorprone

* Fix spotless

* Invoke before premain

Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>

* Create dump in applicationinsights folder

* Show the full path of the dump

* Fix lgtm

* Allow sout

* Fix lgtm

* Supress systemout at the method level

* Fix style complain

* Address comments

* Fix spotless

* Address comments

* Return when exception occurs

* Remove comment

Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>

* Use getBoolean for system property

Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>

* Fix startup profiling (#2092)

* Fix startup profiling

* errorprone

* Shorten host property in network statsbeat (#2087)

* Shorten host

* Use regex

* Fix spotless

* Strict protocol

* Remove sout debugging

* Remove escape .

* Send endpointUrl when region is not found

* Turn off oshi logging (#2086)

* Turn off oshi logging

* Update oshi logger level

* Don't mark throttle as error (#2079)

* Update azure-core dependency (#2095)

Co-authored-by: Helen Y <56097766+heyams@users.noreply.github.com>
  • Loading branch information
trask and heyams committed Feb 9, 2022
1 parent c42fa53 commit 747a9ff
Show file tree
Hide file tree
Showing 14 changed files with 507 additions and 105 deletions.
21 changes: 9 additions & 12 deletions agent/agent-profiler/agent-profiler-api/gradle.lockfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
# This is a Gradle generated file for dependency locking.
# Manual edits can break the build and are not advised.
# This file is expected to be part of source control.
com.azure:azure-core:1.21.0=runtimeClasspath
com.fasterxml.jackson.core:jackson-annotations:2.12.5=runtimeClasspath
com.fasterxml.jackson.core:jackson-core:2.12.5=runtimeClasspath
com.fasterxml.jackson.core:jackson-databind:2.12.5=runtimeClasspath
com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.12.5=runtimeClasspath
com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.12.5=runtimeClasspath
com.fasterxml.jackson.module:jackson-module-jaxb-annotations:2.12.5=runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.12.5=runtimeClasspath
com.fasterxml.woodstox:woodstox-core:6.2.4=runtimeClasspath
com.azure:azure-core:1.25.0=runtimeClasspath
com.fasterxml.jackson.core:jackson-annotations:2.13.1=runtimeClasspath
com.fasterxml.jackson.core:jackson-core:2.13.1=runtimeClasspath
com.fasterxml.jackson.core:jackson-databind:2.13.1=runtimeClasspath
com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.13.1=runtimeClasspath
com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.13.1=runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.13.1=runtimeClasspath
com.fasterxml.woodstox:woodstox-core:6.2.7=runtimeClasspath
com.google.guava:guava-bom:31.0.1-jre=runtimeClasspath
com.squareup.moshi:moshi:1.11.0=runtimeClasspath
com.squareup.okio:okio:1.17.5=runtimeClasspath
Expand All @@ -19,9 +18,7 @@ io.netty:netty-tcnative-classes:2.0.46.Final=runtimeClasspath
io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom-alpha:1.10.0+ai.patches-alpha=runtimeClasspath
io.opentelemetry:opentelemetry-bom-alpha:1.10.0-alpha=runtimeClasspath
io.opentelemetry:opentelemetry-bom:1.10.0=runtimeClasspath
io.projectreactor:reactor-core:3.4.10=runtimeClasspath
jakarta.activation:jakarta.activation-api:1.2.1=runtimeClasspath
jakarta.xml.bind:jakarta.xml.bind-api:2.3.2=runtimeClasspath
io.projectreactor:reactor-core:3.4.13=runtimeClasspath
org.codehaus.woodstox:stax2-api:4.2.1=runtimeClasspath
org.junit:junit-bom:5.7.2=runtimeClasspath
org.reactivestreams:reactive-streams:1.0.3=runtimeClasspath
Expand Down
33 changes: 15 additions & 18 deletions agent/agent-profiler/agent-service-profiler/gradle.lockfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
# This is a Gradle generated file for dependency locking.
# Manual edits can break the build and are not advised.
# This file is expected to be part of source control.
com.azure:azure-core-http-netty:1.11.2=runtimeClasspath
com.azure:azure-core:1.22.0=runtimeClasspath
com.azure:azure-storage-blob:12.14.2=runtimeClasspath
com.azure:azure-storage-common:12.14.1=runtimeClasspath
com.azure:azure-storage-internal-avro:12.1.2=runtimeClasspath
com.fasterxml.jackson.core:jackson-annotations:2.12.5=runtimeClasspath
com.fasterxml.jackson.core:jackson-core:2.12.5=runtimeClasspath
com.fasterxml.jackson.core:jackson-databind:2.12.5=runtimeClasspath
com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.12.5=runtimeClasspath
com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.12.5=runtimeClasspath
com.fasterxml.jackson.module:jackson-module-jaxb-annotations:2.12.5=runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.12.5=runtimeClasspath
com.fasterxml.woodstox:woodstox-core:6.2.4=runtimeClasspath
com.azure:azure-core-http-netty:1.11.6=runtimeClasspath
com.azure:azure-core:1.25.0=runtimeClasspath
com.azure:azure-storage-blob:12.14.3=runtimeClasspath
com.azure:azure-storage-common:12.14.2=runtimeClasspath
com.azure:azure-storage-internal-avro:12.1.3=runtimeClasspath
com.fasterxml.jackson.core:jackson-annotations:2.13.1=runtimeClasspath
com.fasterxml.jackson.core:jackson-core:2.13.1=runtimeClasspath
com.fasterxml.jackson.core:jackson-databind:2.13.1=runtimeClasspath
com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.13.1=runtimeClasspath
com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.13.1=runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.13.1=runtimeClasspath
com.fasterxml.woodstox:woodstox-core:6.2.7=runtimeClasspath
com.google.guava:guava-bom:31.0.1-jre=runtimeClasspath
com.microsoft.jfr:jfr-streaming:1.2.0=runtimeClasspath
com.squareup.moshi:moshi-adapters:1.11.0=runtimeClasspath
Expand Down Expand Up @@ -44,11 +43,9 @@ io.netty:netty-transport:4.1.72.Final=runtimeClasspath
io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom-alpha:1.10.0+ai.patches-alpha=runtimeClasspath
io.opentelemetry:opentelemetry-bom-alpha:1.10.0-alpha=runtimeClasspath
io.opentelemetry:opentelemetry-bom:1.10.0=runtimeClasspath
io.projectreactor.netty:reactor-netty-core:1.0.11=runtimeClasspath
io.projectreactor.netty:reactor-netty-http:1.0.11=runtimeClasspath
io.projectreactor:reactor-core:3.4.10=runtimeClasspath
jakarta.activation:jakarta.activation-api:1.2.1=runtimeClasspath
jakarta.xml.bind:jakarta.xml.bind-api:2.3.2=runtimeClasspath
io.projectreactor.netty:reactor-netty-core:1.0.14=runtimeClasspath
io.projectreactor.netty:reactor-netty-http:1.0.14=runtimeClasspath
io.projectreactor:reactor-core:3.4.13=runtimeClasspath
org.codehaus.woodstox:stax2-api:4.2.1=runtimeClasspath
org.junit:junit-bom:5.7.2=runtimeClasspath
org.reactivestreams:reactive-streams:1.0.3=runtimeClasspath
Expand Down
35 changes: 16 additions & 19 deletions agent/agent-tooling/gradle.lockfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,19 @@ ch.qos.logback.contrib:logback-json-classic:0.1.5=runtimeClasspath
ch.qos.logback.contrib:logback-json-core:0.1.5=runtimeClasspath
ch.qos.logback:logback-classic:1.2.8=runtimeClasspath
ch.qos.logback:logback-core:1.2.8=runtimeClasspath
com.azure:azure-core-http-netty:1.11.2=runtimeClasspath
com.azure:azure-core:1.22.0=runtimeClasspath
com.azure:azure-identity:1.3.6=runtimeClasspath
com.azure:azure-storage-blob:12.14.2=runtimeClasspath
com.azure:azure-storage-common:12.14.1=runtimeClasspath
com.azure:azure-storage-internal-avro:12.1.2=runtimeClasspath
com.fasterxml.jackson.core:jackson-annotations:2.12.5=runtimeClasspath
com.fasterxml.jackson.core:jackson-core:2.12.5=runtimeClasspath
com.fasterxml.jackson.core:jackson-databind:2.12.5=runtimeClasspath
com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.12.5=runtimeClasspath
com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.12.5=runtimeClasspath
com.fasterxml.jackson.module:jackson-module-jaxb-annotations:2.12.5=runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.12.5=runtimeClasspath
com.fasterxml.woodstox:woodstox-core:6.2.4=runtimeClasspath
com.azure:azure-core-http-netty:1.11.7=runtimeClasspath
com.azure:azure-core:1.25.0=runtimeClasspath
com.azure:azure-identity:1.4.4=runtimeClasspath
com.azure:azure-storage-blob:12.14.3=runtimeClasspath
com.azure:azure-storage-common:12.14.2=runtimeClasspath
com.azure:azure-storage-internal-avro:12.1.3=runtimeClasspath
com.fasterxml.jackson.core:jackson-annotations:2.13.1=runtimeClasspath
com.fasterxml.jackson.core:jackson-core:2.13.1=runtimeClasspath
com.fasterxml.jackson.core:jackson-databind:2.13.1=runtimeClasspath
com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.13.1=runtimeClasspath
com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.13.1=runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.13.1=runtimeClasspath
com.fasterxml.woodstox:woodstox-core:6.2.7=runtimeClasspath
com.github.oshi:oshi-core:5.8.0=runtimeClasspath
com.github.stephenc.jcip:jcip-annotations:1.0-1=runtimeClasspath
com.google.code.findbugs:annotations:3.0.1=runtimeClasspath
Expand Down Expand Up @@ -97,11 +96,9 @@ io.opentelemetry:opentelemetry-sdk-metrics:1.10.0-alpha=runtimeClasspath
io.opentelemetry:opentelemetry-sdk-trace:1.10.0=runtimeClasspath
io.opentelemetry:opentelemetry-sdk:1.10.0=runtimeClasspath
io.opentelemetry:opentelemetry-semconv:1.10.0-alpha=runtimeClasspath
io.projectreactor.netty:reactor-netty-core:1.0.11=runtimeClasspath
io.projectreactor.netty:reactor-netty-http:1.0.11=runtimeClasspath
io.projectreactor:reactor-core:3.4.10=runtimeClasspath
jakarta.activation:jakarta.activation-api:1.2.1=runtimeClasspath
jakarta.xml.bind:jakarta.xml.bind-api:2.3.2=runtimeClasspath
io.projectreactor.netty:reactor-netty-core:1.0.14=runtimeClasspath
io.projectreactor.netty:reactor-netty-http:1.0.14=runtimeClasspath
io.projectreactor:reactor-core:3.4.13=runtimeClasspath
net.bytebuddy:byte-buddy-dep:1.12.6=runtimeClasspath
net.bytebuddy:byte-buddy:1.12.6=runtimeClasspath
net.java.dev.jna:jna-platform:5.8.0=runtimeClasspath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,8 @@ public static class Statsbeat {
// when something goes wrong.
public boolean disabledAll = false;

public String instrumentationKey =
"c4a29126-a7cb-47e5-b348-11414998b11e"; // workspace-aistatsbeat
public String endpoint =
DefaultEndpoints.INGESTION_ENDPOINT; // this supports the government cloud
public String instrumentationKey;
public String endpoint;
public long shortIntervalSeconds = MINUTES.toSeconds(15); // default to 15 minutes
public long longIntervalSeconds = DAYS.toSeconds(1); // default to daily
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public LoggingLevelConfigurator(String levelStr) {
}

public void initLoggerLevels(LoggerContext loggerContext) {
updateLoggerLevel(loggerContext.getLogger("oshi"));
updateLoggerLevel(loggerContext.getLogger("reactor.netty"));
updateLoggerLevel(loggerContext.getLogger("reactor.util"));
updateLoggerLevel(loggerContext.getLogger("io.netty"));
Expand All @@ -62,7 +63,9 @@ public void initLoggerLevels(LoggerContext loggerContext) {
public void updateLoggerLevel(Logger logger) {
Level loggerLevel;
String name = logger.getName();
if (name.startsWith("reactor.netty") || name.startsWith("io.netty")) {
if (name.startsWith("oshi")) {
loggerLevel = getOshiLoggerLevel(level);
} else if (name.startsWith("reactor.netty") || name.startsWith("io.netty")) {
loggerLevel = getNettyLevel(level);
} else if (name.startsWith("reactor.util")) {
loggerLevel = getDefaultLibraryLevel(level);
Expand Down Expand Up @@ -125,6 +128,15 @@ private static Level getNettyLevel(Level level) {
}
}

private static Level getOshiLoggerLevel(Level level) {
if (level == Level.INFO || level == Level.WARN || level == Level.ERROR) {
return Level.OFF;
} else if (level == Level.DEBUG) {
return Level.INFO;
}
return level;
}

private static Level getDefaultLibraryLevel(Level level) {
if (level == Level.INFO) {
return Level.WARN;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Consumer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.checkerframework.checker.lock.qual.GuardedBy;

public class NetworkStatsbeat extends BaseStatsbeat {
Expand All @@ -39,6 +41,8 @@ public class NetworkStatsbeat extends BaseStatsbeat {
private static final String EXCEPTION_COUNT_METRIC_NAME = "Exception Count";
private static final String BREEZE_ENDPOINT = "breeze";

private static final Pattern hostPattern = Pattern.compile("^https?://(?:www\\.)?([^/.]+)");

private final Object lock = new Object();

@GuardedBy("lock")
Expand Down Expand Up @@ -237,25 +241,16 @@ private double getRequestDurationAvg() {

/**
* e.g. endpointUrl 'https://westus-0.in.applicationinsights.azure.com/v2.1/track' host will
* return 'westus-0.in.applicationinsights.azure.com'
* return 'westus-0'
*/
static String getHost(String endpointUrl) {
assert (endpointUrl != null && !endpointUrl.isEmpty());
int start = endpointUrl.indexOf("://");
if (start != -1) {
int end = endpointUrl.indexOf("/", start + 3);
if (end != -1) {
return endpointUrl.substring(start + 3, end);
}

return endpointUrl.substring(start + 3);
}
Matcher matcher = hostPattern.matcher(endpointUrl);

int end = endpointUrl.indexOf("/");
if (end != -1) {
return endpointUrl.substring(0, end);
if (matcher.find()) {
return matcher.group(1);
}

// it's better to send bad endpointUrl to Statsbeat for troubleshooting.
return endpointUrl;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.net.URL;
import java.util.Map;
import java.util.TreeMap;
import javax.annotation.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -51,16 +52,27 @@ public static void parseInto(String connectionString, TelemetryClient telemetryC
}

public static void updateStatsbeatConnectionString(
String ikey, String endpoint, TelemetryClient config)
@Nullable String ikey, @Nullable String endpoint, TelemetryClient telemetryClient)
throws InvalidConnectionStringException {
if (Strings.isNullOrEmpty(ikey)) {
logger.warn("Missing Statsbeat '" + Keywords.INSTRUMENTATION_KEY + "'");
}

config.setStatsbeatInstrumentationKey(ikey);
// if customer is in EU region and their statsbeat config is not in EU region, customer is
// responsible for breaking the EU data boundary violation.
// Statsbeat config setting has the highest precedence.
if (ikey == null || ikey.isEmpty()) {
StatsbeatConnectionString.InstrumentationKeyEndpointPair pair =
StatsbeatConnectionString.getInstrumentationKeyAndEndpointPair(
telemetryClient.getEndpointProvider().getIngestionEndpoint().toString());
ikey = pair.instrumentationKey;
endpoint = pair.endpoint;
}

telemetryClient.setStatsbeatInstrumentationKey(ikey);

if (!Strings.isNullOrEmpty(endpoint)) {
config
telemetryClient
.getEndpointProvider()
.setStatsbeatEndpoint(toUrlOrThrow(endpoint, Keywords.INGESTION_ENDPOINT));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* ApplicationInsights-Java
* Copyright (c) Microsoft Corporation
* All rights reserved.
*
* MIT License
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
* software and associated documentation files (the ""Software""), to deal in the Software
* without restriction, including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software, and to permit
* persons to whom the Software is furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
* THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/

package com.microsoft.applicationinsights.agent.internal.telemetry;

import java.util.HashSet;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.annotation.Nullable;

final class StatsbeatConnectionString {

// visible for testing
static final String EU_REGION_STATSBEAT_IKEY =
"7dc56bab-3c0c-4e9f-9ebb-d1acadee8d0f"; // westeu-aistatsbeat
static final String EU_REGION_STATSBEAT_ENDPOINT =
"https://westeurope-5.in.applicationinsights.azure.com/";
static final String NON_EU_REGION_STATSBEAT_IKEY =
"c4a29126-a7cb-47e5-b348-11414998b11e"; // workspace-aistatsbeat
static final String NON_EU_REGION_STATSBEAT_ENDPOINT =
"https://westus-0.in.applicationinsights.azure.com/";

private static final Pattern pattern = Pattern.compile("^https?://(?:www\\.)?([^/.-]+)");

private static final Set<String> EU_REGION_GEO_SET = new HashSet<>(10);

static {
EU_REGION_GEO_SET.add("westeurope");
EU_REGION_GEO_SET.add("northeurope");
EU_REGION_GEO_SET.add("francecentral");
EU_REGION_GEO_SET.add("francesouth");
EU_REGION_GEO_SET.add("germanywestcentral");
EU_REGION_GEO_SET.add("norwayeast");
EU_REGION_GEO_SET.add("norwaywest");
EU_REGION_GEO_SET.add("swedencentral");
EU_REGION_GEO_SET.add("switzerlandnorth");
EU_REGION_GEO_SET.add("switzerlandwest");
}

// visible for testing
static InstrumentationKeyEndpointPair getInstrumentationKeyAndEndpointPair(
String customerEndpoint) {
String geo = getGeoWithoutStampSpecific(customerEndpoint);
if (EU_REGION_GEO_SET.contains(geo.toLowerCase())) {
return new InstrumentationKeyEndpointPair(
EU_REGION_STATSBEAT_IKEY, EU_REGION_STATSBEAT_ENDPOINT);
}

return new InstrumentationKeyEndpointPair(
NON_EU_REGION_STATSBEAT_IKEY, NON_EU_REGION_STATSBEAT_ENDPOINT);
}

// visible for testing
@Nullable
static String getGeoWithoutStampSpecific(String endpointUrl) {
Matcher matcher = pattern.matcher(endpointUrl);
if (matcher.find()) {
return matcher.group(1);
}

return null;
}

private StatsbeatConnectionString() {}

static class InstrumentationKeyEndpointPair {
public final String instrumentationKey;
public final String endpoint;

public InstrumentationKeyEndpointPair(String instrumentationKey, String endpoint) {
this.instrumentationKey = instrumentationKey;
this.endpoint = endpoint;
}
}
}
Loading

0 comments on commit 747a9ff

Please sign in to comment.