-
Notifications
You must be signed in to change notification settings - Fork 751
[GOBBLIN-2209] Emit GaaS Executor Otel Metrics #4118
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
Open
Blazer-007
wants to merge
6
commits into
apache:master
Choose a base branch
from
Blazer-007:virai_add_mdm_status_metric
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
14fb347
emit otel metrics from executor
Blazer-007 0b8e685
added locking for singleton
Blazer-007 5de4424
fix typo
Blazer-007 832a86c
addressed review comments - 1
Blazer-007 341419a
change log level to debug
Blazer-007 6d21c96
removed unused imports
Blazer-007 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
49 changes: 49 additions & 0 deletions
49
...s/src/main/java/org/apache/gobblin/metrics/opentelemetry/GobblinOpenTelemetryMetrics.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,49 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.gobblin.metrics.opentelemetry; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum GobblinOpenTelemetryMetrics { | ||
/** | ||
* Metric to track the count of Gobblin Jobs for each of its state (GenerateWorkUnit, ProcessWorkUnit, CommitStep). | ||
* Metric Unit: 1 represents each increment will add one data point to the counter. | ||
* */ | ||
GOBBLIN_JOB_STATE("gobblin_job_state", "Gobblin job state counter", "1", OpenTelemetryMetricType.LONG_COUNTER), | ||
|
||
/** | ||
* Metric to track the latency of each Gobblin Job state (GenerateWorkUnit, ProcessWorkUnit, CommitStep). | ||
* Metric Unit: seconds (s) represents the time taken for each state. | ||
* */ | ||
GOBBLIN_JOB_STATE_LATENCY("gobblin_job_state_latency", "Gobblin job state latency", "s", OpenTelemetryMetricType.DOUBLE_HISTOGRAM); | ||
|
||
private final String metricName; | ||
private final String metricDescription; | ||
private final String metricUnit; | ||
private final OpenTelemetryMetricType metricType; | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("Metric{name='%s', description='%s', unit='%s', type=%s}", metricName, metricDescription, metricUnit, metricType); | ||
} | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
...n/java/org/apache/gobblin/metrics/opentelemetry/GobblinOpenTelemetryMetricsConstants.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,40 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.gobblin.metrics.opentelemetry; | ||
|
||
public class GobblinOpenTelemetryMetricsConstants { | ||
|
||
public static class DimensionKeys { | ||
public static final String STATE = "state"; | ||
public static final String CURR_STATE = "currState"; | ||
} | ||
|
||
public static class DimensionValues { | ||
public static final String GENERATE_WU = "generateWU"; | ||
public static final String PROCESS_WU = "processWU"; | ||
public static final String COMMIT_STEP = "commitStep"; | ||
public static final String JOB_START = "jobStart"; | ||
public static final String JOB_COMPLETE = "jobComplete"; | ||
public static final String GENERATE_WU_START = "generateWUStart"; | ||
public static final String GENERATE_WU_COMPLETE = "generateWUComplete"; | ||
public static final String PROCESS_WU_START = "processWUStart"; | ||
public static final String PROCESS_WU_COMPLETE = "processWUComplete"; | ||
public static final String COMMIT_STEP_START = "commitStepStart"; | ||
public static final String COMMIT_STEP_COMPLETE = "commitStepComplete"; | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
.../src/main/java/org/apache/gobblin/metrics/opentelemetry/OpenTelemetryDoubleHistogram.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,87 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.gobblin.metrics.opentelemetry; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import io.opentelemetry.api.common.Attributes; | ||
import io.opentelemetry.api.metrics.DoubleHistogram; | ||
|
||
|
||
/** | ||
* Implementation of {@link OpenTelemetryMetric} that wraps an OpenTelemetry {@link DoubleHistogram}. | ||
* | ||
* <p>This class provides a histogram for recording the distribution of double values. | ||
* It supports recording values with optional additional attributes that can be merged with base attributes.</p> | ||
* | ||
*/ | ||
@Slf4j | ||
@AllArgsConstructor | ||
public class OpenTelemetryDoubleHistogram implements OpenTelemetryMetric { | ||
private String name; | ||
private Attributes baseAttributes; | ||
private DoubleHistogram doubleHistogram; | ||
|
||
/** | ||
* Records the specified value in the histogram with the base attributes. | ||
* | ||
* @param value the double value to record in the histogram | ||
*/ | ||
public void record(double value) { | ||
log.debug("Emitting double histogram metric: {}, value: {}, attributes: {}", this.name, value, this.baseAttributes); | ||
this.doubleHistogram.record(value, this.baseAttributes); | ||
} | ||
|
||
/** | ||
* Records the specified value in the histogram with a combination of base attributes and additional attributes. | ||
* | ||
* @param value the double value to record in the histogram | ||
* @param additionalAttributes the additional attributes to be merged with base attributes | ||
*/ | ||
public void record(double value, Attributes additionalAttributes) { | ||
log.debug("Emitting double histogram metric: {}, value: {}, base attributes: {}, additional attributes: {}", | ||
this.name, value, this.baseAttributes, additionalAttributes); | ||
this.doubleHistogram.record(value, OpenTelemetryHelper.mergeAttributes(this.baseAttributes, additionalAttributes)); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public String getMetricName() { | ||
return this.name; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public OpenTelemetryMetricType getMetricType() { | ||
return OpenTelemetryMetricType.DOUBLE_HISTOGRAM; | ||
} | ||
|
||
/** | ||
* Returns a string representation of this histogram with its name. | ||
*/ | ||
@Override | ||
public String toString() { | ||
return "OpenTelemetryDoubleHistogram{name='" + name + "'}"; | ||
} | ||
|
||
} |
94 changes: 94 additions & 0 deletions
94
...n-metrics/src/main/java/org/apache/gobblin/metrics/opentelemetry/OpenTelemetryHelper.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,94 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.gobblin.metrics.opentelemetry; | ||
|
||
import java.util.Map; | ||
|
||
import lombok.experimental.UtilityClass; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import io.opentelemetry.api.common.Attributes; | ||
import io.opentelemetry.api.common.AttributesBuilder; | ||
|
||
/** | ||
* Utility class for OpenTelemetry related operations. | ||
* | ||
* <p>Provides methods to handle OpenTelemetry attributes, including merging multiple | ||
* {@link Attributes} instances and converting maps to {@link Attributes}. | ||
*/ | ||
@UtilityClass | ||
public class OpenTelemetryHelper { | ||
|
||
private static final String DEFAULT_OPENTELEMETRY_ATTRIBUTE_VALUE = "UNKNOWN"; | ||
|
||
/** | ||
* Returns the provided attribute value when it is non-null and non-empty; | ||
* otherwise returns the default OpenTelemetry attribute placeholder. | ||
* | ||
* @param value candidate attribute value to check | ||
* @return the original value if not empty, or DEFAULT_OPENTELEMETRY_ATTRIBUTE_VALUE otherwise | ||
*/ | ||
public static String getOrDefaultOpenTelemetryAttrValue(String value) { | ||
return StringUtils.defaultIfBlank(value, DEFAULT_OPENTELEMETRY_ATTRIBUTE_VALUE); | ||
} | ||
|
||
/** | ||
* Merges multiple {@link Attributes} instances into a single {@link Attributes}. | ||
* | ||
* <p>Any {@code null} or empty ({@link Attributes#isEmpty()}) instances are ignored. | ||
* The resulting {@link Attributes} contains all key-value pairs from the | ||
* provided non-null, non-empty inputs in the order they are given. | ||
* For duplicate keys, the last occurrence in the array will take precedence. | ||
* | ||
* @param attributesArray array of {@link Attributes} to merge; may contain {@code null} or empty entries | ||
* @return a new {@link Attributes} instance containing all entries from the non-null, | ||
* non-empty inputs; never {@code null} | ||
*/ | ||
public static Attributes mergeAttributes(Attributes... attributesArray) { | ||
AttributesBuilder builder = Attributes.builder(); | ||
for (Attributes attrs : attributesArray) { | ||
if (attrs != null && !attrs.isEmpty()) { | ||
builder.putAll(attrs); | ||
Blazer-007 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
return builder.build(); | ||
} | ||
|
||
/** | ||
* Converts a map of string attributes to an OpenTelemetry {@link Attributes} instance. | ||
* | ||
* <p>Each entry in the map is converted to an OpenTelemetry attribute, using | ||
* {@link #getOrDefaultOpenTelemetryAttrValue(String)} to handle empty values. | ||
* | ||
* @param attributes map of string attributes to convert; may be {@code null} | ||
* @return a new {@link Attributes} instance containing the converted attributes; | ||
* never {@code null} | ||
*/ | ||
public static Attributes toOpenTelemetryAttributes(Map<String, String> attributes) { | ||
AttributesBuilder builder = Attributes.builder(); | ||
if (attributes != null) { | ||
for (Map.Entry<String, String> entry : attributes.entrySet()) { | ||
String key = entry.getKey(); | ||
String value = getOrDefaultOpenTelemetryAttrValue(entry.getValue()); | ||
builder.put(key, value); | ||
} | ||
} | ||
return builder.build(); | ||
} | ||
|
||
} |
Oops, something went wrong.
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.