-
Notifications
You must be signed in to change notification settings - Fork 25.4k
OTLP: add support for counters and gauges #133702
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
Merged
Changes from 7 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
1ab3d89
OTLP: add support for counters and gauges
felixbarny e33f774
[CI] Auto commit changes from spotless
f9ecbd2
Apply suggestions from code review
felixbarny 21d656e
Revert changes to action and doc builder
felixbarny bc35f6e
Add unit tests
felixbarny 453a292
Merge branch 'main' into otlp-counter-gauge
felixbarny dcfa5b6
Add unit tests for BufferedByteStringAccessor
felixbarny 2f7bcd3
Add unit tests for AttributeListTsidFunnel
felixbarny 27ee86e
Address review comments
felixbarny c0ae9d7
[CI] Auto commit changes from spotless
0241e48
Inline and remove unnecessary DataPointDimensionsTsidFunnel
felixbarny 744ff19
Remove scope schema_url and version from grouping
felixbarny b1f2157
Merge remote-tracking branch 'origin/main' into otlp-counter-gauge
felixbarny 69859a7
Merge remote-tracking branch 'felixbarny/otlp-counter-gauge' into otl…
felixbarny 70fc512
Merge branch 'main' into otlp-counter-gauge
felixbarny 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
137 changes: 137 additions & 0 deletions
137
...in/otel-data/src/main/java/org/elasticsearch/xpack/oteldata/otlp/datapoint/DataPoint.java
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 |
---|---|---|
@@ -0,0 +1,137 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.oteldata.otlp.datapoint; | ||
|
||
import io.opentelemetry.proto.common.v1.KeyValue; | ||
import io.opentelemetry.proto.metrics.v1.Metric; | ||
import io.opentelemetry.proto.metrics.v1.NumberDataPoint; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import static io.opentelemetry.proto.metrics.v1.AggregationTemporality.AGGREGATION_TEMPORALITY_CUMULATIVE; | ||
|
||
/** | ||
* Represents a metrics data point in the OpenTelemetry metrics data model. | ||
* This interface defines methods to access various properties of a data point, | ||
* such as its timestamp, attributes, unit, metric name, and methods to build | ||
* the metric value in a specific format. | ||
* The reason this class is needed is that the generated classes from the | ||
* OpenTelemetry proto definitions don't implement a common interface, | ||
* which makes it difficult to handle different types of data points uniformly. | ||
*/ | ||
public interface DataPoint { | ||
|
||
/** | ||
* Returns the timestamp of the data point in Unix nanoseconds. | ||
* | ||
* @return the timestamp in nanoseconds | ||
*/ | ||
long getTimestampUnixNano(); | ||
|
||
/** | ||
* Returns the start timestamp of the data point in Unix nanoseconds. | ||
* This allows detecting when a sequence of observations is unbroken. | ||
* This field indicates to consumers the start time for points with cumulative and delta temporality, | ||
* and can support correct rate calculation. | ||
* | ||
* @return the start timestamp in nanoseconds | ||
*/ | ||
long getStartTimestampUnixNano(); | ||
|
||
/** | ||
* Returns the attributes associated with the data point. | ||
* | ||
* @return a list of key-value pairs representing the attributes | ||
*/ | ||
List<KeyValue> getAttributes(); | ||
|
||
/** | ||
* Returns the unit of measurement for the data point. | ||
* | ||
* @return the unit as a string | ||
*/ | ||
String getUnit(); | ||
|
||
/** | ||
* Returns the name of the metric associated with the data point. | ||
* | ||
* @return the metric name as a string | ||
*/ | ||
String getMetricName(); | ||
|
||
/** | ||
* Returns the dynamic template name for the data point based on its type and value. | ||
* This is used to dynamically map the appropriate field type according to the data point's characteristics. | ||
* | ||
* @return the dynamic template name as a string | ||
*/ | ||
String getDynamicTemplate(); | ||
|
||
/** | ||
* Validates whether the data point can be indexed into Elasticsearch. | ||
* | ||
* @param errors a set to collect validation error messages | ||
* @return true if the data point is valid, false otherwise | ||
*/ | ||
boolean isValid(Set<String> errors); | ||
|
||
record Number(NumberDataPoint dataPoint, Metric metric) implements DataPoint { | ||
|
||
@Override | ||
public long getTimestampUnixNano() { | ||
return dataPoint.getTimeUnixNano(); | ||
} | ||
|
||
@Override | ||
public List<KeyValue> getAttributes() { | ||
return dataPoint.getAttributesList(); | ||
} | ||
|
||
@Override | ||
public long getStartTimestampUnixNano() { | ||
return dataPoint.getStartTimeUnixNano(); | ||
} | ||
|
||
@Override | ||
public String getUnit() { | ||
return metric.getUnit(); | ||
} | ||
|
||
@Override | ||
public String getMetricName() { | ||
return metric.getName(); | ||
} | ||
|
||
@Override | ||
public String getDynamicTemplate() { | ||
String type; | ||
if (metric.hasSum() | ||
// TODO add support for delta counters - for now we represent them as gauges | ||
&& metric.getSum().getAggregationTemporality() == AGGREGATION_TEMPORALITY_CUMULATIVE | ||
// TODO add support for up/down counters - for now we represent them as gauges | ||
&& metric.getSum().getIsMonotonic()) { | ||
type = "counter_"; | ||
} else { | ||
type = "gauge_"; | ||
} | ||
if (dataPoint.getValueCase() == NumberDataPoint.ValueCase.AS_INT) { | ||
return type + "long"; | ||
} else if (dataPoint.getValueCase() == NumberDataPoint.ValueCase.AS_DOUBLE) { | ||
return type + "double"; | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isValid(Set<String> errors) { | ||
return true; | ||
} | ||
} | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.