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 12e7966dd6 Scope metrics console queries by entity id
12e7966dd6 is described below
commit 12e7966dd685949880b684f22fc8eaaf08cfcdee
Author: Logic <[email protected]>
AuthorDate: Tue Jun 9 20:23:14 2026 +0800
Scope metrics console queries by entity id
---
.../service/impl/OtlpIngestionWorkspaceServiceImpl.java | 8 ++++++++
.../impl/OtlpIngestionWorkspaceServiceImplTest.java | 14 +++++++++-----
2 files changed, 17 insertions(+), 5 deletions(-)
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 0ef6bf930c..fc62fa3962 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
@@ -1790,6 +1790,10 @@ public class OtlpIngestionWorkspaceServiceImpl
implements OtlpIngestionWorkspace
matchers.add("deployment_environment_name=\"" +
escapePromqlLabelValue(context.getEnvironment()) + "\"");
scopedLabels.add("deployment_environment_name");
}
+ if (context.getEntityId() != null) {
+ matchers.add("hertzbeat_entity_id=\"" +
escapePromqlLabelValue(String.valueOf(context.getEntityId())) + "\"");
+ scopedLabels.add("hertzbeat_entity_id");
+ }
if (StringUtils.hasText(context.getEntityType())) {
matchers.add("hertzbeat_entity_type=\"" +
escapePromqlLabelValue(context.getEntityType()) + "\"");
scopedLabels.add("hertzbeat_entity_type");
@@ -1821,6 +1825,10 @@ public class OtlpIngestionWorkspaceServiceImpl
implements OtlpIngestionWorkspace
matchers.add("deployment_environment_name=\"" +
escapePromqlLabelValue(context.getEnvironment()) + "\"");
scopedLabels.add("deployment_environment_name");
}
+ if (context.getEntityId() != null) {
+ matchers.add("hertzbeat_entity_id=\"" +
escapePromqlLabelValue(String.valueOf(context.getEntityId())) + "\"");
+ scopedLabels.add("hertzbeat_entity_id");
+ }
if (StringUtils.hasText(context.getEntityType())) {
matchers.add("hertzbeat_entity_type=\"" +
escapePromqlLabelValue(context.getEntityType()) + "\"");
scopedLabels.add("hertzbeat_entity_type");
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 eaa33fe3ff..341eaaa7e0 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
@@ -718,7 +718,8 @@ class OtlpIngestionWorkspaceServiceImplTest {
when(workspaceQueryGateway.findEntityById(42L)).thenReturn(java.util.Optional.of(entity));
when(workspaceQueryGateway.findIdentitiesByEntityId(42L)).thenReturn(List.of(serviceName,
serviceNamespace));
String checkoutQuery =
groupedMetricPromql("__name__=\"http_server_request_duration_count\", "
- + "service_name=\"checkout\", service_namespace=\"commerce\",
deployment_environment_name=\"prod\"");
+ + "service_name=\"checkout\", service_namespace=\"commerce\",
deployment_environment_name=\"prod\", "
+ + "hertzbeat_entity_id=\"42\"");
stubPromqlQuery(checkoutQuery,
new DatasourceQueryData(
"otlp-metrics-console",
@@ -821,12 +822,13 @@ class OtlpIngestionWorkspaceServiceImplTest {
}
@Test
- void metricsConsoleAppliesRequestedEntityTypeAsPromqlResourceMatcher() {
+ void metricsConsoleAppliesRequestedEntityIdentityAsPromqlResourceMatcher()
{
observabilitySignalIntakeGateway.recordOtlpMetricIntake(
Map.of(
"service.name", "checkout",
"service.namespace", "commerce",
"deployment.environment.name", "prod",
+ "hertzbeat.entity_id", "42",
"hertzbeat.entity_type", "service"
),
2_000L,
@@ -838,7 +840,7 @@ class OtlpIngestionWorkspaceServiceImplTest {
);
String expectedQuery =
groupedMetricPromql("__name__=\"http_server_request_duration_count\", "
+ "service_name=\"checkout\", service_namespace=\"commerce\",
deployment_environment_name=\"prod\", "
- + "hertzbeat_entity_type=\"service\"");
+ + "hertzbeat_entity_id=\"42\",
hertzbeat_entity_type=\"service\"");
DatasourceQueryData emptyQueryData = new
DatasourceQueryData("otlp-metrics-console", 200, null, List.of());
when(metricQueryRepository.hasPromqlExecutor()).thenReturn(true);
when(metricQueryRepository.queryPromqlRange(
@@ -860,7 +862,7 @@ class OtlpIngestionWorkspaceServiceImplTest {
"commerce",
"prod",
null,
- "hertzbeat.entity_type=\"host\"",
+ "hertzbeat.entity_id=\"99\" and
hertzbeat.entity_type=\"host\"",
null,
null,
null,
@@ -868,6 +870,7 @@ class OtlpIngestionWorkspaceServiceImplTest {
null
);
+ assertEquals(42L, console.getContext().getEntityId());
assertEquals("service", console.getContext().getEntityType());
assertEquals(expectedQuery, console.getQuery());
verify(metricQueryRepository).queryPromqlRange(
@@ -912,7 +915,8 @@ class OtlpIngestionWorkspaceServiceImplTest {
when(workspaceQueryGateway.findEntityById(42L)).thenReturn(java.util.Optional.empty());
when(workspaceQueryGateway.findIdentitiesByEntityId(42L)).thenReturn(List.of(serviceName,
serviceNamespace, environment));
String checkoutQuery =
groupedMetricPromql("__name__=\"http_server_request_duration_count\", "
- + "service_name=\"checkout\", service_namespace=\"commerce\",
deployment_environment_name=\"prod\"");
+ + "service_name=\"checkout\", service_namespace=\"commerce\",
deployment_environment_name=\"prod\", "
+ + "hertzbeat_entity_id=\"42\"");
stubPromqlQuery(checkoutQuery,
new DatasourceQueryData(
"otlp-metrics-console",
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]