Skip to content
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
2 changes: 1 addition & 1 deletion agent/agent-gc-monitor/gc-monitor-api/gradle.lockfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# This file is expected to be part of source control.
com.azure:azure-sdk-bom:1.2.26=runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.17.2=runtimeClasspath
com.google.errorprone:error_prone_annotations:2.29.2=runtimeClasspath
com.google.errorprone:error_prone_annotations:2.30.0=runtimeClasspath
io.netty:netty-bom:4.1.112.Final=runtimeClasspath
io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom-alpha:2.6.0-alpha=runtimeClasspath
io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom:2.6.0=runtimeClasspath
Expand Down
2 changes: 1 addition & 1 deletion agent/agent-gc-monitor/gc-monitor-core/gradle.lockfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# This file is expected to be part of source control.
com.azure:azure-sdk-bom:1.2.26=runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.17.2=runtimeClasspath
com.google.errorprone:error_prone_annotations:2.29.2=runtimeClasspath
com.google.errorprone:error_prone_annotations:2.30.0=runtimeClasspath
io.netty:netty-bom:4.1.112.Final=runtimeClasspath
io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom-alpha:2.6.0-alpha=runtimeClasspath
io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom:2.6.0=runtimeClasspath
Expand Down
2 changes: 1 addition & 1 deletion agent/agent-tooling/gradle.lockfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ com.fasterxml.jackson:jackson-bom:2.17.2=runtimeClasspath
com.fasterxml.woodstox:woodstox-core:6.7.0=runtimeClasspath
com.github.oshi:oshi-core:6.6.2=runtimeClasspath
com.github.stephenc.jcip:jcip-annotations:1.0-1=runtimeClasspath
com.google.errorprone:error_prone_annotations:2.29.2=runtimeClasspath
com.google.errorprone:error_prone_annotations:2.30.0=runtimeClasspath
com.microsoft.azure:msal4j-persistence-extension:1.3.0=runtimeClasspath
com.microsoft.azure:msal4j:1.16.1=runtimeClasspath
com.nimbusds:content-type:2.3=runtimeClasspath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import javax.management.AttributeNotFoundException;
Expand Down Expand Up @@ -44,7 +45,7 @@ public static Map<String, Collection<Object>> fetch(
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
Set<ObjectName> objects = server.queryNames(new ObjectName(objectName), null);
if (objects.isEmpty()) {
String errorMsg = String.format("Cannot find object name '%s'", objectName);
String errorMsg = String.format(Locale.ROOT, "Cannot find object name '%s'", objectName);

@trask Trask Stalnaker (trask) Aug 12, 2024

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just fyi, I usually replace this type of String.format usage with string concatenation, similar to upstream: open-telemetry/opentelemetry-java#4887 (comment)

throw new IllegalArgumentException(errorMsg);
}

Expand Down Expand Up @@ -81,7 +82,7 @@ public static List<Object> fetch(String objectName, String attribute) throws Exc
Set<ObjectName> objects = server.queryNames(new ObjectName(objectName), null);
logger.trace("Matching object names for pattern {}: {}", objectName, objects.toString());
if (objects.isEmpty()) {
String errorMsg = String.format("Cannot find object name '%s'", objectName);
String errorMsg = String.format(Locale.ROOT, "Cannot find object name '%s'", objectName);
throw new IllegalArgumentException(errorMsg);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package com.microsoft.applicationinsights.agent.internal.perfcounter;

import com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import org.slf4j.Logger;
Expand Down Expand Up @@ -115,7 +116,8 @@ private static long getProcessBytes(OSProcess processInfo) {
// use for calculating I/O bytes
private static long getProcessBytesLinux(int processId) {
Map<String, String> io =
FileUtil.getKeyValueMapFromFile(String.format(ProcPath.PID_IO, processId), ":");
FileUtil.getKeyValueMapFromFile(
String.format(Locale.ROOT, ProcPath.PID_IO, processId), ":");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is better to use string.format. pattern is inside PID_IO constant.

long bytesRead = ParseUtil.parseLongOrDefault(io.getOrDefault("read_bytes", ""), 0L);
long bytesWritten = ParseUtil.parseLongOrDefault(io.getOrDefault("write_bytes", ""), 0L);
return bytesRead + bytesWritten;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.azure.monitor.opentelemetry.exporter.implementation.utils.ThreadPoolUtils;
import com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -76,9 +77,11 @@ public void setCollectionFrequencyInSec(long collectionFrequencyInSec) {
if (collectionFrequencyInSec < MIN_COLLECTION_FREQUENCY_IN_SEC) {
String errorMessage =
String.format(
Locale.ROOT,
"Collecting Interval: illegal value '%d'. The minimum value, '%d', "
+ "is used instead.",
collectionFrequencyInSec, MIN_COLLECTION_FREQUENCY_IN_SEC);
collectionFrequencyInSec,
MIN_COLLECTION_FREQUENCY_IN_SEC);
logger.error(errorMessage);

collectionFrequencyInSec = MIN_COLLECTION_FREQUENCY_IN_SEC;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand All @@ -22,7 +23,7 @@
public final class TimestampContract {
// Cant use ISO_INSTANT as it does not pad the nanos to 7 figures
private static final DateTimeFormatter FORMATTER =
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.nX");
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.nX", Locale.ROOT);

private static final Pattern TIMESTAMP_PATTERN = Pattern.compile(".*\\.([0-9]+)Z$");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -144,7 +145,7 @@ void testRpConfigurationOverlayWithEnvVarAndSysPropPopulated() throws Exception
envVars.put("APPLICATIONINSIGHTS_SAMPLING_PERCENTAGE", String.valueOf(testSamplingPercentage));
RpConfiguration config = new RpConfiguration();

config.connectionString = String.format("original-%s", testConnectionString);
config.connectionString = String.format(Locale.ROOT, "original-%s", testConnectionString);
config.sampling.percentage = testSamplingPercentage + 1.0;

ConfigurationBuilder.overlayFromEnv(config, this::envVars, this::systemProperties);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.concurrent.ThreadLocalRandom;

public class LocalStringsUtils {

private static final SimpleDateFormat simpleDateFormat =
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZZ");
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZZ", Locale.ROOT);

public static boolean isNullOrEmpty(String value) {
return value == null || value.isEmpty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

package com.microsoft.applicationinsights.telemetry;

import java.util.Locale;
import java.util.Objects;

/**
Expand Down Expand Up @@ -106,11 +107,11 @@ public long getTotalMilliseconds() {
public String toString() {
StringBuilder sb = new StringBuilder();
if (days != 0) {
sb.append(String.format("%02d.", days));
sb.append(String.format(Locale.ROOT, "%02d.", days));
}
sb.append(String.format("%02d:%02d:%02d", hours, minutes, seconds));
sb.append(String.format(Locale.ROOT, "%02d:%02d:%02d", hours, minutes, seconds));
if (milliseconds > 0) {
sb.append(String.format(".%03d0000", milliseconds));
sb.append(String.format(Locale.ROOT, ".%03d0000", milliseconds));
Comment on lines +110 to +114

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here.. it's better to using string.format to keep number of digits

}
return sb.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package com.microsoft.applicationinsights.web.internal.correlation.tracecontext;

import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand All @@ -19,7 +20,7 @@ public final class Tracestate {

private static final String DELIMITER_FORMAT = "[ \\t]*,[ \\t]*";
private static final String MEMBER_FORMAT =
String.format("(%s)(=)(%s)", KEY_FORMAT, VALUE_FORMAT);
String.format(Locale.ROOT, "(%s)(=)(%s)", KEY_FORMAT, VALUE_FORMAT);

private static final Pattern DELIMITER_FORMAT_RE = Pattern.compile(DELIMITER_FORMAT);
private static final Pattern MEMBER_FORMAT_RE = Pattern.compile("^" + MEMBER_FORMAT + "$");
Expand All @@ -40,18 +41,21 @@ public Tracestate(String input) {
for (String item : values) {
Matcher m = MEMBER_FORMAT_RE.matcher(item);
if (!m.find()) {
throw new IllegalArgumentException(String.format("invalid string %s in tracestate", item));
throw new IllegalArgumentException(
String.format(Locale.ROOT, "invalid string %s in tracestate", item));
}
String key = m.group(1);
String value = m.group(3);
if (internalList.get(key) != null) {
throw new IllegalArgumentException(String.format("duplicated keys %s in tracestate", key));
throw new IllegalArgumentException(
String.format(Locale.ROOT, "duplicated keys %s in tracestate", key));
}
internalList.put(key, value);
}
if (internalList.size() > MAX_KEY_VALUE_PAIRS) {
throw new IllegalArgumentException(
String.format("cannot have more than %d key-value pairs", MAX_KEY_VALUE_PAIRS));
String.format(
Locale.ROOT, "cannot have more than %d key-value pairs", MAX_KEY_VALUE_PAIRS));
}
internalString = toInternalString();
}
Expand Down
2 changes: 1 addition & 1 deletion dependencyManagement/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ val DEPENDENCY_BOMS = listOf(

val autoServiceVersion = "1.1.1"
val autoValueVersion = "1.11.0"
val errorProneVersion = "2.29.2"
val errorProneVersion = "2.30.0"
val jmhVersion = "1.37"
val mockitoVersion = "4.11.0"
val slf4jVersion = "2.0.16"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import javax.annotation.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -64,7 +65,8 @@ public static void extractToLocalFolder(File dllOnDisk, String libraryToLoad) th
}
try (InputStream in = classLoader.getResourceAsStream(libraryToLoad)) {
if (in == null) {
throw new IllegalStateException(String.format("Failed to find '%s' in jar", libraryToLoad));
throw new IllegalStateException(
String.format(Locale.ROOT, "Failed to find '%s' in jar", libraryToLoad));
}
byte[] buffer = new byte[8192];
try (OutputStream out = new FileOutputStream(dllOnDisk, false)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

package com.microsoft.applicationinsights.agent.internal.diagnostics.etw.events.model;

import java.util.Locale;

public abstract class IpaEtwEventBase implements IpaEtwEvent {
private String extensionVersion;
private String appName;
Expand Down Expand Up @@ -92,7 +94,7 @@ public String getFormattedMessage() {
if (messageArgs == null || messageArgs.length == 0) {
return fmt == null ? "" : fmt;
} else {
return String.format(fmt, messageArgs);
return String.format(Locale.ROOT, fmt, messageArgs);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.microsoft.applicationinsights.agent.internal.diagnostics.etw.events.model.IpaEtwEventBase;
import com.microsoft.applicationinsights.agent.internal.diagnostics.etw.events.model.IpaEtwEventErrorBase;
import java.io.File;
import java.util.Locale;
import java.util.UUID;
import javax.annotation.Nullable;
import org.apache.commons.lang3.RandomUtils;
Expand Down Expand Up @@ -216,8 +217,13 @@ int sum() {
@Override
public String toString() {
return String.format(
Locale.ROOT,
"{ verbose: %d, info: %d, warn: %d, error: %d, critical: %d }",
verbose, info, warn, error, critical);
verbose,
info,
warn,
error,
critical);
}

void plus(EventCounts operand) {
Expand Down Expand Up @@ -260,23 +266,23 @@ private static void runLoopTest(int iterations) throws Exception {
if (RandomUtils.nextInt(0, warnChance) == 0) {
Throwable exception = null;
if (RandomUtils.nextBoolean()) {
exception = new Exception(String.format("Exeption %d", i));
exception = new Exception(String.format(Locale.ROOT, "Exeption %d", i));
}
ep.writeEvent(createWarn("test.warn", "testEventsOnLoop", exception, "i=%d", i));
accumulator.warn++;
}
if (RandomUtils.nextInt(0, errorChance) == 0) {
Throwable exception = null;
if (RandomUtils.nextBoolean()) {
exception = new Exception(String.format("Exeption %d", i));
exception = new Exception(String.format(Locale.ROOT, "Exeption %d", i));
}
ep.writeEvent(createError("test.error", "testEventsOnLoop", exception, "i=%d", i));
accumulator.error++;
}
if (RandomUtils.nextInt(0, criticalChance) == 0) {
Throwable exception = null;
if (RandomUtils.nextBoolean()) {
exception = new Exception(String.format("Exeption %d", i));
exception = new Exception(String.format(Locale.ROOT, "Exeption %d", i));
}
ep.writeEvent(createCritical("test.critical", "testEventsOnLoop", exception, "i=%d", i));
accumulator.critical++;
Expand All @@ -296,7 +302,9 @@ private static void runLoopTest(int iterations) throws Exception {
+ printTimer
+ "ms "
+ String.format(
"(avg=%.3fms)", ((double) printTimer / (double) accumulator.sum())));
Locale.ROOT,
"(avg=%.3fms)",
((double) printTimer / (double) accumulator.sum())));
printTimer = 0;
accumulator.reset();
}
Expand All @@ -312,6 +320,8 @@ private static void runLoopTest(int iterations) throws Exception {
+ totalElapsedTime
+ "ms "
+ String.format(
"(avg=%.3fms)", ((double) totalElapsedTime / (double) totalEvents.sum())));
Locale.ROOT,
"(avg=%.3fms)",
((double) totalElapsedTime / (double) totalEvents.sum())));
}
}
4 changes: 2 additions & 2 deletions licenses/more-licenses.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

# agent
## Dependency License Report
_2024-08-12 03:55:29 UTC_
_2024-08-12 03:55:56 UTC_
## Apache License, Version 2.0

**1** **Group:** `com.fasterxml.jackson.core` **Name:** `jackson-annotations` **Version:** `2.17.2`
Expand Down Expand Up @@ -36,7 +36,7 @@ _2024-08-12 03:55:29 UTC_
> - **POM Project URL**: [http://stephenc.github.com/jcip-annotations](http://stephenc.github.com/jcip-annotations)
> - **POM License**: Apache License, Version 2.0 - [https://www.apache.org/licenses/LICENSE-2.0](https://www.apache.org/licenses/LICENSE-2.0)

**6** **Group:** `com.google.errorprone` **Name:** `error_prone_annotations` **Version:** `2.29.2`
**6** **Group:** `com.google.errorprone` **Name:** `error_prone_annotations` **Version:** `2.30.0`
> - **Manifest Project URL**: [https://errorprone.info/error_prone_annotations](https://errorprone.info/error_prone_annotations)
> - **Manifest License**: Apache License, Version 2.0 (Not Packaged)
> - **POM License**: Apache License, Version 2.0 - [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)
Expand Down