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

[Dynatrace v2] Only serialize metadata when set on the meter #4247

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,9 @@ private String createGaugeLine(Meter meter, Map<String, String> seenMetadata, Me
return null;
}
MetricLineBuilder.GaugeStep gaugeStep = createTypeStep(meter).gauge();
storeMetadata(enrichMetadata(gaugeStep.metadata(), meter), seenMetadata);
if (shouldExportMetadata(meter.getId())) {
storeMetadata(enrichMetadata(gaugeStep.metadata(), meter), seenMetadata);
}
return gaugeStep.value(value).timestamp(Instant.ofEpochMilli(clock.wallTime())).build();
}
catch (MetricException e) {
Expand All @@ -242,7 +244,9 @@ Stream<String> toCounterLine(Meter counter, Map<String, String> seenMetadata) {
private String createCounterLine(Meter meter, Map<String, String> seenMetadata, Measurement measurement) {
try {
MetricLineBuilder.CounterStep counterStep = createTypeStep(meter).count();
storeMetadata(enrichMetadata(counterStep.metadata(), meter), seenMetadata);
if (shouldExportMetadata(meter.getId())) {
storeMetadata(enrichMetadata(counterStep.metadata(), meter), seenMetadata);
}
return counterStep.delta(measurement.getValue()).timestamp(Instant.ofEpochMilli(clock.wallTime())).build();
}
catch (MetricException e) {
Expand Down Expand Up @@ -295,7 +299,9 @@ private Stream<String> createSummaryLine(Meter meter, Map<String, String> seenMe
double total, long count) {
try {
MetricLineBuilder.GaugeStep gaugeStep = createTypeStep(meter).gauge();
storeMetadata(enrichMetadata(gaugeStep.metadata(), meter), seenMetadata);
if (shouldExportMetadata(meter.getId())) {
storeMetadata(enrichMetadata(gaugeStep.metadata(), meter), seenMetadata);
}
return Stream.of(gaugeStep.summary(min, max, total, count)
.timestamp(Instant.ofEpochMilli(clock.wallTime()))
.build());
Expand Down Expand Up @@ -447,6 +453,20 @@ private void handleSuccess(int totalSent, HttpSender.Response response) {
}
}

private boolean shouldExportMetadata(Meter.Id id) {
if (!config.exportMeterMetadata()) {
return false;
}
// if at least one of unit or description are set, export metadata.
if (id.getBaseUnit() != null && !id.getBaseUnit().isEmpty()) {
return true;
}
if (id.getDescription() != null && !id.getDescription().isEmpty()) {
return true;
}
return false;
}

private MetricLineBuilder.MetadataStep enrichMetadata(MetricLineBuilder.MetadataStep metadataStep, Meter meter) {
return metadataStep.description(meter.getId().getDescription()).unit(meter.getId().getBaseUnit());
}
Expand Down