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

Avoid conflicts in Micrometer description mapping #5452

Merged
merged 3 commits into from
Mar 8, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
final class Bridging {

private static final Cache<String, AttributeKey<String>> tagsCache = Cache.bounded(1024);
private static final Cache<String, String> descriptionsCache = Cache.bounded(1024);

static Attributes tagsAsAttributes(Meter.Id id, NamingConvention namingConvention) {
Iterable<Tag> tags = id.getTagsAsIterable();
Expand All @@ -36,9 +37,14 @@ static String name(Meter.Id id, NamingConvention namingConvention) {
return namingConvention.name(id.getName(), id.getType(), id.getBaseUnit());
}

static String description(Meter.Id id) {
String description = id.getDescription();
return description == null ? "" : description;
// TODO: remove the cache usage once the SDK is able to handle different descriptions
static String description(String name, Meter.Id id) {
fstab marked this conversation as resolved.
Show resolved Hide resolved
return descriptionsCache.computeIfAbsent(
name,
n -> {
String description = id.getDescription();
return description == null ? "" : description;
});
}

static String baseUnit(Meter.Id id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ final class OpenTelemetryCounter implements Counter, RemovableMeter {
this.id = id;

this.attributes = tagsAsAttributes(id, namingConvention);
String conventionName = name(id, namingConvention);
this.otelCounter =
otelMeter
.counterBuilder(name(id, namingConvention))
.setDescription(description(id))
.counterBuilder(conventionName)
.setDescription(description(conventionName, id))
.setUnit(baseUnit(id))
.ofDoubles()
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ final class OpenTelemetryDistributionSummary extends AbstractDistributionSummary
this.otelHistogram =
otelMeter
.histogramBuilder(conventionName)
.setDescription(description(id))
.setDescription(description(conventionName, id))
.setUnit(baseUnit(id))
.build();
this.maxHandle =
asyncInstrumentRegistry.buildGauge(
conventionName + ".max",
description(id),
description(conventionName, id),
baseUnit(id),
attributes,
max,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ final class OpenTelemetryFunctionCounter<T> implements FunctionCounter, Removabl
AsyncInstrumentRegistry asyncInstrumentRegistry) {
this.id = id;

String conventionName = name(id, namingConvention);
countMeasurementHandle =
asyncInstrumentRegistry.buildDoubleCounter(
name(id, namingConvention),
description(id),
conventionName,
description(conventionName, id),
baseUnit(id),
tagsAsAttributes(id, namingConvention),
obj,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,22 @@ final class OpenTelemetryFunctionTimer<T> implements FunctionTimer, RemovableMet
this.id = id;
this.baseTimeUnit = baseTimeUnit;

String countMeterName = name(id, namingConvention) + ".count";
String totalTimeMeterName = name(id, namingConvention) + ".sum";
String conventionName = name(id, namingConvention);
Attributes attributes = tagsAsAttributes(id, namingConvention);

countMeasurementHandle =
asyncInstrumentRegistry.buildLongCounter(
countMeterName, description(id), /* baseUnit = */ "1", attributes, obj, countFunction);
conventionName + ".count",
description(conventionName, id),
/* baseUnit = */ "1",
attributes,
obj,
countFunction);

totalTimeMeasurementHandle =
asyncInstrumentRegistry.buildDoubleCounter(
totalTimeMeterName,
description(id),
conventionName + ".sum",
description(conventionName, id),
getUnitString(baseTimeUnit),
attributes,
obj,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ final class OpenTelemetryGauge<T> implements Gauge, RemovableMeter {

this.id = id;

String conventionName = name(id, namingConvention);
gaugeMeasurementHandle =
asyncInstrumentRegistry.buildGauge(
name(id, namingConvention),
description(id),
conventionName,
description(conventionName, id),
baseUnit(id),
tagsAsAttributes(id, namingConvention),
obj,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ final class OpenTelemetryLongTaskTimer extends DefaultLongTaskTimer implements R
this.activeTasksHandle =
asyncInstrumentRegistry.buildUpDownLongCounter(
conventionName + ".active",
description(id),
description(conventionName, id),
"tasks",
attributes,
this,
DefaultLongTaskTimer::activeTasks);
this.durationHandle =
asyncInstrumentRegistry.buildUpDownDoubleCounter(
conventionName + ".duration",
description(id),
description(conventionName, id),
getUnitString(baseTimeUnit),
attributes,
this,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ final class OpenTelemetryMeter implements Meter, RemovableMeter {
List<AsyncMeasurementHandle> measurementHandles = new ArrayList<>();
for (Measurement measurement : measurements) {
String name = statisticInstrumentName(id, measurement.getStatistic(), namingConvention);
String description = description(id);
String description = description(name, id);
String baseUnit = baseUnit(id);

switch (measurement.getStatistic()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ final class OpenTelemetryTimer extends AbstractTimer implements RemovableMeter {
this.otelHistogram =
otelMeter
.histogramBuilder(conventionName)
.setDescription(description(id))
.setDescription(description(conventionName, id))
.setUnit(getUnitString(baseTimeUnit))
.build();
this.maxHandle =
asyncInstrumentRegistry.buildGauge(
conventionName + ".max",
description(id),
description(conventionName, id),
getUnitString(baseTimeUnit),
attributes,
max,
Expand Down