-
Notifications
You must be signed in to change notification settings - Fork 332
Update otel proto buf specification #5434
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
Merged
kkondaka
merged 4 commits into
opensearch-project:main
from
sternadsoftware:update-otel-proto-spec
Feb 26, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,30 +8,21 @@ | |
| import com.fasterxml.jackson.core.JsonProcessingException; | ||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import io.opentelemetry.proto.common.v1.AnyValue; | ||
| import io.opentelemetry.proto.common.v1.InstrumentationLibrary; | ||
| import io.opentelemetry.proto.common.v1.InstrumentationScope; | ||
| import io.opentelemetry.proto.common.v1.KeyValue; | ||
| import io.opentelemetry.proto.metrics.v1.ExponentialHistogramDataPoint; | ||
| import io.opentelemetry.proto.metrics.v1.NumberDataPoint; | ||
| import io.opentelemetry.proto.metrics.v1.SummaryDataPoint; | ||
| import io.opentelemetry.proto.resource.v1.Resource; | ||
| import org.apache.commons.codec.binary.Hex; | ||
| import org.opensearch.dataprepper.model.metric.Bucket; | ||
| import org.opensearch.dataprepper.model.metric.DefaultBucket; | ||
| import org.opensearch.dataprepper.model.metric.DefaultExemplar; | ||
| import org.opensearch.dataprepper.model.metric.DefaultQuantile; | ||
| import org.opensearch.dataprepper.model.metric.Exemplar; | ||
| import org.opensearch.dataprepper.model.metric.Quantile; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import java.time.Instant; | ||
| import java.util.ArrayList; | ||
| import java.util.Collection; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Optional; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
| import java.util.function.Function; | ||
| import java.util.stream.Collectors; | ||
|
|
@@ -40,14 +31,7 @@ public final class OTelMetricsProtoHelper { | |
|
|
||
| private static final Logger LOG = LoggerFactory.getLogger(OTelMetricsProtoHelper.class); | ||
| private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); | ||
| private static final String SERVICE_NAME = "service.name"; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for cleaning up these unused methods and names! |
||
| private static final String METRIC_ATTRIBUTES = "metric.attributes"; | ||
| static final String RESOURCE_ATTRIBUTES = "resource.attributes"; | ||
| static final String EXEMPLAR_ATTRIBUTES = "exemplar.attributes"; | ||
| static final String INSTRUMENTATION_LIBRARY_NAME = "instrumentationLibrary.name"; | ||
| static final String INSTRUMENTATION_LIBRARY_VERSION = "instrumentationLibrary.version"; | ||
| static final String INSTRUMENTATION_SCOPE_NAME = "instrumentationScope.name"; | ||
| static final String INSTRUMENTATION_SCOPE_VERSION = "instrumentationScope.version"; | ||
|
|
||
| /** | ||
| * To make it ES friendly we will replace '.' in keys with '@' in all the Keys in {@link io.opentelemetry.proto.common.v1.KeyValue} | ||
|
|
@@ -60,8 +44,6 @@ public final class OTelMetricsProtoHelper { | |
| * Span and Resource attributes are essential for kibana so they should not be nested. SO we will prefix them with "metric.attributes" | ||
| * and "resource.attributes" and "exemplar.attributes". | ||
| */ | ||
| public static final Function<String, String> PREFIX_AND_METRIC_ATTRIBUTES_REPLACE_DOT_WITH_AT = i -> METRIC_ATTRIBUTES + DOT + i.replace(DOT, AT); | ||
| public static final Function<String, String> PREFIX_AND_RESOURCE_ATTRIBUTES_REPLACE_DOT_WITH_AT = i -> RESOURCE_ATTRIBUTES + DOT + i.replace(DOT, AT); | ||
| public static final Function<String, String> PREFIX_AND_EXEMPLAR_ATTRIBUTES_REPLACE_DOT_WITH_AT = i -> EXEMPLAR_ATTRIBUTES + DOT + i.replace(DOT, AT); | ||
|
|
||
| private OTelMetricsProtoHelper() { | ||
|
|
@@ -111,30 +93,6 @@ public static Object convertAnyValue(final AnyValue value) { | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Converts the keys of all attributes in the {@link NumberDataPoint}. | ||
| * Also, casts the underlying data into its actual type | ||
| * | ||
| * @param numberDataPoint The point to process | ||
| * @return A Map containing all attributes of `numberDataPoint` with keys converted into an OS-friendly format | ||
| */ | ||
| public static Map<String, Object> convertKeysOfDataPointAttributes(final NumberDataPoint numberDataPoint) { | ||
| return numberDataPoint.getAttributesList().stream() | ||
| .collect(Collectors.toMap(i -> PREFIX_AND_METRIC_ATTRIBUTES_REPLACE_DOT_WITH_AT.apply(i.getKey()), i -> convertAnyValue(i.getValue()))); | ||
| } | ||
|
|
||
| /** | ||
| * Unpacks the List of {@link KeyValue} object into a Map. | ||
| * Converts the keys into an os friendly format and casts the underlying data into its actual type? | ||
| * | ||
| * @param attributesList The list of {@link KeyValue} objects to process | ||
| * @return A Map containing unpacked {@link KeyValue} data | ||
| */ | ||
| public static Map<String, Object> unpackKeyValueList(List<KeyValue> attributesList) { | ||
| return attributesList.stream() | ||
| .collect(Collectors.toMap(i -> PREFIX_AND_METRIC_ATTRIBUTES_REPLACE_DOT_WITH_AT.apply(i.getKey()), i -> convertAnyValue(i.getValue()))); | ||
| } | ||
|
|
||
| /** | ||
| * Unpacks the List of {@link KeyValue} object into a Map. | ||
| * Converts the keys into an os friendly format and casts the underlying data into its actual type? | ||
|
|
@@ -184,79 +142,11 @@ public static Double getExemplarValueAsDouble(final io.opentelemetry.proto.metri | |
| } | ||
| } | ||
|
|
||
| public static Map<String, Object> getResourceAttributes(final Resource resource) { | ||
| return resource.getAttributesList().stream() | ||
| .collect(Collectors.toMap(i -> PREFIX_AND_RESOURCE_ATTRIBUTES_REPLACE_DOT_WITH_AT.apply(i.getKey()), i -> convertAnyValue(i.getValue()))); | ||
| } | ||
|
|
||
| /** | ||
| * Extracts the name and version of the used instrumentation library used | ||
| * | ||
| * @param instrumentationLibrary instrumentationLibrary | ||
| * @return A map, containing information about the instrumentation library | ||
| */ | ||
| public static Map<String, Object> getInstrumentationLibraryAttributes(final InstrumentationLibrary instrumentationLibrary) { | ||
| final Map<String, Object> instrumentationAttr = new HashMap<>(); | ||
| if (!instrumentationLibrary.getName().isEmpty()) { | ||
| instrumentationAttr.put(INSTRUMENTATION_LIBRARY_NAME, instrumentationLibrary.getName()); | ||
| } | ||
| if (!instrumentationLibrary.getVersion().isEmpty()) { | ||
| instrumentationAttr.put(INSTRUMENTATION_LIBRARY_VERSION, instrumentationLibrary.getVersion()); | ||
| } | ||
| return instrumentationAttr; | ||
| } | ||
|
|
||
| /** | ||
| * Extracts the name and version of the used instrumentation scope used | ||
| * | ||
| * @param instrumentationScope instrumentationScope | ||
| * @return A map, containing information about the instrumentation scope | ||
| */ | ||
| public static Map<String, Object> getInstrumentationScopeAttributes(final InstrumentationScope instrumentationScope) { | ||
| final Map<String, Object> instrumentationScopeAttr = new HashMap<>(); | ||
| if (!instrumentationScope.getName().isEmpty()) { | ||
| instrumentationScopeAttr.put(INSTRUMENTATION_SCOPE_NAME, instrumentationScope.getName()); | ||
| } | ||
| if (!instrumentationScope.getVersion().isEmpty()) { | ||
| instrumentationScopeAttr.put(INSTRUMENTATION_SCOPE_VERSION, instrumentationScope.getVersion()); | ||
| } | ||
| return instrumentationScopeAttr; | ||
| } | ||
|
|
||
|
|
||
| public static String convertUnixNanosToISO8601(final long unixNano) { | ||
| return Instant.ofEpochSecond(0L, unixNano).toString(); | ||
| } | ||
|
|
||
| public static String getStartTimeISO8601(final NumberDataPoint numberDataPoint) { | ||
| return convertUnixNanosToISO8601(numberDataPoint.getStartTimeUnixNano()); | ||
| } | ||
|
|
||
| public static String getTimeISO8601(final NumberDataPoint ndp) { | ||
| return convertUnixNanosToISO8601(ndp.getTimeUnixNano()); | ||
| } | ||
|
|
||
| public static Optional<String> getServiceName(final Resource resource) { | ||
| return resource.getAttributesList().stream() | ||
| .filter(keyValue -> keyValue.getKey().equals(SERVICE_NAME) && !keyValue.getValue().getStringValue().isEmpty()) | ||
| .findFirst() | ||
| .map(i -> i.getValue().getStringValue()); | ||
| } | ||
|
|
||
|
|
||
| public static Map<String, Object> mergeAllAttributes(final Collection<Map<String, Object>> attributes) { | ||
| return attributes.stream() | ||
| .flatMap(map -> map.entrySet().stream()) | ||
| .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); | ||
| } | ||
|
|
||
|
|
||
| public static List<Quantile> getQuantileValues(List<SummaryDataPoint.ValueAtQuantile> quantileValues) { | ||
| return quantileValues.stream() | ||
| .map(q -> new DefaultQuantile(q.getQuantile(), q.getValue())) | ||
| .collect(Collectors.toList()); | ||
| } | ||
|
|
||
| /** | ||
| * Create the buckets, see <a href="https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/metrics/v1/metrics.proto"> | ||
| * the OTel metrics proto spec</a> | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we keep an old version in here and still have tests pass? I'd expect this to be ok since the wire format is unchanged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dlvenable I do not think that's possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not? The wire format is the same is it not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the OTEL version on the client side? If yes, that should work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have verified this locally and it should work.