This is an automated email from the ASF dual-hosted git repository.
zqr10159 pushed a commit to branch 2.0.0
in repository https://gitbox.apache.org/repos/asf/hertzbeat.git
The following commit(s) were added to refs/heads/2.0.0 by this push:
new a3e8dbe136 Expose metrics operation context
a3e8dbe136 is described below
commit a3e8dbe1369fc528c54fe0c1eb88559c80e732f7
Author: Logic <[email protected]>
AuthorDate: Wed Jun 10 09:25:36 2026 +0800
Expose metrics operation context
---
.../common/observability/dto/metrics/OtlpMetricsConsoleDto.java | 2 ++
.../common/observability/dto/OtlpWorkspaceDtoMigrationTest.java | 2 +-
.../ingestion/service/impl/OtlpIngestionWorkspaceServiceImpl.java | 5 +++++
.../ingestion/controller/OtlpIngestionControllerTest.java | 8 +++++---
.../service/impl/OtlpIngestionWorkspaceServiceImplTest.java | 2 ++
web-next/lib/types.ts | 1 +
6 files changed, 16 insertions(+), 4 deletions(-)
diff --git
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/observability/dto/metrics/OtlpMetricsConsoleDto.java
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/observability/dto/metrics/OtlpMetricsConsoleDto.java
index a2a9793bc5..b880009322 100644
---
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/observability/dto/metrics/OtlpMetricsConsoleDto.java
+++
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/observability/dto/metrics/OtlpMetricsConsoleDto.java
@@ -66,6 +66,8 @@ public class OtlpMetricsConsoleDto {
private String environment;
+ private String operationName;
+
private Long start;
private Long end;
diff --git
a/hertzbeat-common-core/src/test/java/org/apache/hertzbeat/common/observability/dto/OtlpWorkspaceDtoMigrationTest.java
b/hertzbeat-common-core/src/test/java/org/apache/hertzbeat/common/observability/dto/OtlpWorkspaceDtoMigrationTest.java
index 08956dd9ea..243726b701 100644
---
a/hertzbeat-common-core/src/test/java/org/apache/hertzbeat/common/observability/dto/OtlpWorkspaceDtoMigrationTest.java
+++
b/hertzbeat-common-core/src/test/java/org/apache/hertzbeat/common/observability/dto/OtlpWorkspaceDtoMigrationTest.java
@@ -59,7 +59,7 @@ class OtlpWorkspaceDtoMigrationTest {
);
OtlpMetricsConsoleDto console = new OtlpMetricsConsoleDto(
new OtlpMetricsConsoleDto.Context(1L, "service", "checkout",
"checkout", "commerce", "prod",
- 1000L, 2000L),
+ null, 1000L, 2000L),
"sum(rate(http_requests_total[5m]))",
"greptime",
"promql",
diff --git
a/hertzbeat-observability/src/main/java/org/apache/hertzbeat/observability/ingestion/service/impl/OtlpIngestionWorkspaceServiceImpl.java
b/hertzbeat-observability/src/main/java/org/apache/hertzbeat/observability/ingestion/service/impl/OtlpIngestionWorkspaceServiceImpl.java
index 94214dd978..b51d31b2eb 100644
---
a/hertzbeat-observability/src/main/java/org/apache/hertzbeat/observability/ingestion/service/impl/OtlpIngestionWorkspaceServiceImpl.java
+++
b/hertzbeat-observability/src/main/java/org/apache/hertzbeat/observability/ingestion/service/impl/OtlpIngestionWorkspaceServiceImpl.java
@@ -711,6 +711,7 @@ public class OtlpIngestionWorkspaceServiceImpl implements
OtlpIngestionWorkspace
);
String resolvedQuery = trimToNull(query);
String normalizedOperationName = trimToNull(operationName);
+ context.setOperationName(normalizedOperationName);
List<String> resolvedQueries;
if (!StringUtils.hasText(resolvedQuery)) {
OtlpMetricsConsoleDto autoResolvedConsole =
queryDefaultMetricsConsole(
@@ -871,6 +872,7 @@ public class OtlpIngestionWorkspaceServiceImpl implements
OtlpIngestionWorkspace
);
String normalizedFilter = trimToNull(filter);
String normalizedOperationName = trimToNull(operationName);
+ context.setOperationName(normalizedOperationName);
List<OtlpRelatedMetricsDto.ResourceMatcher> resourceMatchers =
parseRelatedMetricResourceMatchers(normalizedFilter);
List<OtlpRelatedMetricsDto.Candidate> candidates =
buildRelatedMetricCandidates(
context, resourceMatchers, normalizedOperationName,
resolvedStart, resolvedEnd, resolvedLimit
@@ -1926,6 +1928,7 @@ public class OtlpIngestionWorkspaceServiceImpl implements
OtlpIngestionWorkspace
resolvedServiceName,
resolvedServiceNamespace,
resolvedEnvironment,
+ null,
start,
end
);
@@ -1967,6 +1970,7 @@ public class OtlpIngestionWorkspaceServiceImpl implements
OtlpIngestionWorkspace
trimToNull(snapshot.getServiceName()),
trimToNull(snapshot.getServiceNamespace()),
trimToNull(snapshot.getEnvironmentName()),
+ operationName,
resolvedStart,
resolvedEnd
))
@@ -2505,6 +2509,7 @@ public class OtlpIngestionWorkspaceServiceImpl implements
OtlpIngestionWorkspace
trimToNull(candidate.getServiceName()),
trimToNull(candidate.getServiceNamespace()),
trimToNull(candidate.getEnvironment()),
+ trimToNull(candidate.getOperationName()),
resolvedStart,
resolvedEnd
);
diff --git
a/hertzbeat-observability/src/test/java/org/apache/hertzbeat/observability/ingestion/controller/OtlpIngestionControllerTest.java
b/hertzbeat-observability/src/test/java/org/apache/hertzbeat/observability/ingestion/controller/OtlpIngestionControllerTest.java
index 9fd83b2165..ac1b2dc3a9 100644
---
a/hertzbeat-observability/src/test/java/org/apache/hertzbeat/observability/ingestion/controller/OtlpIngestionControllerTest.java
+++
b/hertzbeat-observability/src/test/java/org/apache/hertzbeat/observability/ingestion/controller/OtlpIngestionControllerTest.java
@@ -205,7 +205,7 @@ class OtlpIngestionControllerTest {
void shouldReturnWrappedMetricsConsolePayload() throws Exception {
OtlpMetricsConsoleDto console = new OtlpMetricsConsoleDto(
new OtlpMetricsConsoleDto.Context(42L, "service", "Checkout
API", "checkout", "commerce", "prod",
- 1000L, 2000L),
+ "POST /checkout", 1000L, 2000L),
"sum by (__name__) ({service_name=\"checkout\"})",
"Greptime-promql",
"promql",
@@ -252,6 +252,7 @@ class OtlpIngestionControllerTest {
.andExpect(jsonPath("$.code").value(0))
.andExpect(jsonPath("$.data.context.entityId").value(42))
.andExpect(jsonPath("$.data.context.entityType").value("service"))
+
.andExpect(jsonPath("$.data.context.operationName").value("POST /checkout"))
.andExpect(jsonPath("$.data.query").value("sum by (__name__)
({service_name=\"checkout\"})"))
.andExpect(jsonPath("$.data.datasource").value("Greptime-promql"))
.andExpect(jsonPath("$.data.stats.totalSeries").value(1))
@@ -266,7 +267,7 @@ class OtlpIngestionControllerTest {
void shouldReturnWrappedMetricsInventoryPayload() throws Exception {
OtlpMetricsInventoryDto inventory = new OtlpMetricsInventoryDto(
new OtlpMetricsConsoleDto.Context(42L, "service", "Checkout
API", "checkout", "commerce", "prod",
- 1000L, 2000L),
+ null, 1000L, 2000L),
"promql-inventory",
1,
List.of(new OtlpMetricsInventoryDto.Item(
@@ -307,7 +308,7 @@ class OtlpIngestionControllerTest {
void shouldReturnWrappedRelatedMetricsPayload() throws Exception {
OtlpRelatedMetricsDto related = new OtlpRelatedMetricsDto(
new OtlpMetricsConsoleDto.Context(42L, "service", "Checkout
API", "checkout", "commerce", "prod",
- 1000L, 2000L),
+ "POST /checkout", 1000L, 2000L),
"k8s.pod.name=\"checkout-7d9\"",
"POST /checkout",
"backend-related-metrics",
@@ -340,6 +341,7 @@ class OtlpIngestionControllerTest {
.andExpect(jsonPath("$.code").value(0))
.andExpect(jsonPath("$.data.context.entityId").value(42))
.andExpect(jsonPath("$.data.context.entityType").value("service"))
+
.andExpect(jsonPath("$.data.context.operationName").value("POST /checkout"))
.andExpect(jsonPath("$.data.operationName").value("POST
/checkout"))
.andExpect(jsonPath("$.data.source").value("backend-related-metrics"))
.andExpect(jsonPath("$.data.resourceMatchers[0].label").value("k8s_pod_name"))
diff --git
a/hertzbeat-observability/src/test/java/org/apache/hertzbeat/observability/ingestion/service/impl/OtlpIngestionWorkspaceServiceImplTest.java
b/hertzbeat-observability/src/test/java/org/apache/hertzbeat/observability/ingestion/service/impl/OtlpIngestionWorkspaceServiceImplTest.java
index 35e0b65fdd..51b3c365c8 100644
---
a/hertzbeat-observability/src/test/java/org/apache/hertzbeat/observability/ingestion/service/impl/OtlpIngestionWorkspaceServiceImplTest.java
+++
b/hertzbeat-observability/src/test/java/org/apache/hertzbeat/observability/ingestion/service/impl/OtlpIngestionWorkspaceServiceImplTest.java
@@ -891,6 +891,7 @@ class OtlpIngestionWorkspaceServiceImplTest {
);
assertEquals(httpRouteQuery, console.getQuery());
+ assertEquals("POST /checkout",
console.getContext().getOperationName());
assertEquals(1, console.getStats().getNonEmptySeries());
verify(metricQueryRepository).queryPromqlRange(
eq("otlp-metrics-console"),
@@ -1244,6 +1245,7 @@ class OtlpIngestionWorkspaceServiceImplTest {
);
assertEquals("POST /checkout", related.getOperationName());
+ assertEquals("POST /checkout",
related.getContext().getOperationName());
assertTrue(related.getCandidates().stream().anyMatch(candidate ->
"http_server_duration".equals(candidate.getQuery())
&& "operation".equals(candidate.getSource())
diff --git a/web-next/lib/types.ts b/web-next/lib/types.ts
index b6da0ab3e5..95d2207efa 100644
--- a/web-next/lib/types.ts
+++ b/web-next/lib/types.ts
@@ -344,6 +344,7 @@ export interface OtlpMetricsConsole {
serviceName?: string | null;
serviceNamespace?: string | null;
environment?: string | null;
+ operationName?: string | null;
start?: number | null;
end?: number | null;
};
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]