Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Read-only File System #1945

Merged
merged 19 commits into from
Nov 4, 2021
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,15 @@ private void start(Instrumentation instrumentation) {

Cache<String, String> ikeyEndpointMap = Cache.builder().setMaximumSize(100).build();
StatsbeatModule statsbeatModule = new StatsbeatModule(ikeyEndpointMap);
// TODO (heya) apply Builder design pattern to TelemetryClient
TelemetryClient telemetryClient =
new TelemetryClient(
config.customDimensions,
metricFilters,
ikeyEndpointMap,
statsbeatModule,
config.preview.authentication);
new TelemetryClient.Builder()
.withCustomDimensions(config.customDimensions)
.withMetricFilters(metricFilters)
.withIkeyEndpointMap(ikeyEndpointMap)
.withStatsbeatModule(statsbeatModule)
.withAadAuthentication(config.preview.authentication)
.build();

TelemetryClientInitializer.initialize(telemetryClient, config);
TelemetryClient.setActive(telemetryClient);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,60 +86,38 @@ public class TelemetryClient {
// * cloud role instance
// * sdk version
// * application version (if provided in customDimensions)
private final Map<String, String> globalTags;
private Map<String, String> globalTags;
heyams marked this conversation as resolved.
Show resolved Hide resolved
// contains customDimensions from json configuration
private final Map<String, String> globalProperties;
private Map<String, String> globalProperties;

private final List<MetricFilter> metricFilters;
private List<MetricFilter> metricFilters;

private final Cache<String, String> ikeyEndpointMap;
private final StatsbeatModule statsbeatModule;
private Cache<String, String> ikeyEndpointMap;
private StatsbeatModule statsbeatModule;

@Nullable private final Configuration.AadAuthentication aadAuthentication;
@Nullable private Configuration.AadAuthentication aadAuthentication;

private final Object channelInitLock = new Object();
private volatile @MonotonicNonNull BatchSpanProcessor channelBatcher;
private volatile @MonotonicNonNull BatchSpanProcessor statsbeatChannelBatcher;

// only used by tests
public TelemetryClient() {
this(
new HashMap<>(),
new ArrayList<>(),
Cache.builder().build(),
new StatsbeatModule(null),
null);
private TelemetryClient(Builder builder) {
this.globalTags = builder.globalTags;
this.globalProperties = builder.globalProperties;
this.metricFilters = builder.metricFilters;
this.ikeyEndpointMap = builder.ikeyEndpointMap;
this.statsbeatModule = builder.statsbeatModule;
this.aadAuthentication = builder.aadAuthentication;
}

public TelemetryClient(
Map<String, String> customDimensions,
List<MetricFilter> metricFilters,
Cache<String, String> ikeyEndpointMap,
StatsbeatModule statsbeatModule,
@Nullable Configuration.AadAuthentication aadAuthentication) {
StringSubstitutor substitutor = new StringSubstitutor(System.getenv());
Map<String, String> globalProperties = new HashMap<>();
Map<String, String> globalTags = new HashMap<>();
for (Map.Entry<String, String> entry : customDimensions.entrySet()) {
String key = entry.getKey();
if (key.equals("service.version")) {
globalTags.put(
ContextTagKeys.AI_APPLICATION_VER.toString(), substitutor.replace(entry.getValue()));
} else {
globalProperties.put(key, substitutor.replace(entry.getValue()));
}
}

globalTags.put(
ContextTagKeys.AI_INTERNAL_SDK_VERSION.toString(),
PropertyHelper.getQualifiedSdkVersionString());

this.globalProperties = globalProperties;
this.globalTags = globalTags;
this.metricFilters = metricFilters;
this.ikeyEndpointMap = ikeyEndpointMap;
this.statsbeatModule = statsbeatModule;
this.aadAuthentication = aadAuthentication;
// only used by tests
public TelemetryClient() {
new TelemetryClient.Builder()
.withCustomDimensions(new HashMap<>())
.withMetricFilters(new ArrayList<>())
.withIkeyEndpointMap(Cache.builder().build())
.withStatsbeatModule(new StatsbeatModule(null))
.build();
}

public static TelemetryClient getActive() {
Expand Down Expand Up @@ -470,4 +448,63 @@ private void initTelemetry(
monitorBase.setBaseType(baseType);
monitorBase.setBaseData(data);
}

public static class Builder {

private Map<String, String> globalTags;
private Map<String, String> globalProperties;
private List<MetricFilter> metricFilters;
private Cache<String, String> ikeyEndpointMap;
private StatsbeatModule statsbeatModule;
@Nullable private Configuration.AadAuthentication aadAuthentication;

public Builder withCustomDimensions(Map<String, String> customDimensions) {
StringSubstitutor substitutor = new StringSubstitutor(System.getenv());
Map<String, String> globalProperties = new HashMap<>();
Map<String, String> globalTags = new HashMap<>();
for (Map.Entry<String, String> entry : customDimensions.entrySet()) {
String key = entry.getKey();
if (key.equals("service.version")) {
globalTags.put(
ContextTagKeys.AI_APPLICATION_VER.toString(), substitutor.replace(entry.getValue()));
} else {
globalProperties.put(key, substitutor.replace(entry.getValue()));
}
}

globalTags.put(
ContextTagKeys.AI_INTERNAL_SDK_VERSION.toString(),
PropertyHelper.getQualifiedSdkVersionString());

this.globalProperties = globalProperties;
this.globalTags = globalTags;

return this;
}

public Builder withMetricFilters(List<MetricFilter> metricFilters) {
this.metricFilters = metricFilters;
return this;
}

public Builder withIkeyEndpointMap(Cache<String, String> ikeyEndpointMap) {
this.ikeyEndpointMap = ikeyEndpointMap;
return this;
}

public Builder withStatsbeatModule(StatsbeatModule statsbeatModule) {
this.statsbeatModule = statsbeatModule;
return this;
}

public Builder withAadAuthentication(Configuration.AadAuthentication aadAuthentication) {
this.aadAuthentication = aadAuthentication;
return this;
}

public TelemetryClient build() {
TelemetryClient telemetryClient = new TelemetryClient(this);
return telemetryClient;
heyams marked this conversation as resolved.
Show resolved Hide resolved
}
}
}