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 c41a0b754b Preserve operation context in alert labels
c41a0b754b is described below

commit c41a0b754b375164737125422c3bb8b4fb435ec3
Author: Logic <[email protected]>
AuthorDate: Wed Jun 10 08:44:42 2026 +0800

    Preserve operation context in alert labels
---
 web-next/lib/alert-setting/view-model.test.ts | 26 +++++++++++++++++++++++++-
 web-next/lib/signal-route-context.test.ts     | 20 ++++++++++++++++++++
 web-next/lib/signal-route-context.ts          |  2 ++
 3 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/web-next/lib/alert-setting/view-model.test.ts 
b/web-next/lib/alert-setting/view-model.test.ts
index cd35f22373..3ff4645f32 100644
--- a/web-next/lib/alert-setting/view-model.test.ts
+++ b/web-next/lib/alert-setting/view-model.test.ts
@@ -119,10 +119,13 @@ describe('alert setting view model', () => {
         source: 'otlp',
         traceId: 'trace-123',
         spanId: 'span-456',
+        operationName: 'POST /checkout',
         collector: 'collector-a',
         template: 'spring-boot',
         alertQuery: 'operationName=POST /checkout\nerrorOnly=true',
         alertQueryType: 'traces',
+        alertDatasource: 'sql',
+        alertTemplate: 'TraceTemplate',
         returnTo: '/trace/manage?traceId=trace-123&returnLabel=Trace'
       },
       t
@@ -135,7 +138,7 @@ describe('alert setting view model', () => {
       sourceQuery: 'operationName=POST /checkout\nerrorOnly=true',
       sourceQueryType: 'traces',
       labelsText:
-        'hertzbeat.signal:traces, hertzbeat.entity.id:7, 
service.name:checkout, service.namespace:payments, deployment.environment:prod, 
trace_id:trace-123, span_id:span-456, hertzbeat.source:otlp, 
hertzbeat.collector:collector-a, hertzbeat.template:spring-boot'
+        'hertzbeat.signal:traces, hertzbeat.entity.id:7, 
service.name:checkout, service.namespace:payments, operation.name:POST 
/checkout, deployment.environment:prod, trace_id:trace-123, span_id:span-456, 
hertzbeat.source:otlp, hertzbeat.collector:collector-a, 
hertzbeat.template:spring-boot, hertzbeat.alert.datasource:sql, 
hertzbeat.alert.query_type:traces, hertzbeat.alert.template:TraceTemplate'
     });
     expect(context?.rows.map(row => 
row.label)).toContain(t('signal.context.trace.label'));
     expect(context?.rows).toContainEqual({
@@ -143,6 +146,21 @@ describe('alert setting view model', () => {
       value: 'operationName=POST /checkout\nerrorOnly=true',
       meta: 'traces'
     });
+    expect(context?.workflowActions.map(action => 
action.key)).toEqual(['notice', 'group', 'silence', 'inhibit']);
+    context?.workflowActions.forEach(action => {
+      const url = new URL(action.href, 'http://localhost');
+      expect(url.pathname).toBe(`/alert/${action.key}`);
+      expect(url.searchParams.get('signal')).toBe('traces');
+      expect(url.searchParams.get('traceId')).toBe('trace-123');
+      expect(url.searchParams.get('spanId')).toBe('span-456');
+      expect(url.searchParams.get('operationName')).toBe('POST /checkout');
+      expect(url.searchParams.get('collector')).toBe('collector-a');
+      expect(url.searchParams.get('alertQueryType')).toBe('traces');
+      expect(url.searchParams.get('alertDatasource')).toBe('sql');
+      expect(url.searchParams.get('alertTemplate')).toBe('TraceTemplate');
+      
expect(url.searchParams.get('returnTo')).toBe('/trace/manage?traceId=trace-123');
+      expect(url.searchParams.get('returnLabel')).toBeNull();
+    });
   });
 
   it('localizes threshold evidence context and inherited rows outside zh-CN', 
() => {
@@ -173,5 +191,11 @@ describe('alert setting view model', () => {
     });
     expect(context?.rows.map(row => [row.label, row.value, row.meta].join(' 
')).join(' ')).not.toMatch(/[\u4e00-\u9fff]/);
     expect(context?.rows.map(row => row.label)).toContain('Trace context');
+    expect(context?.workflowActions.map(action => action.label)).toEqual([
+      'Configure notification policy',
+      'Configure grouping',
+      'Create silence',
+      'Create inhibit'
+    ]);
   });
 });
diff --git a/web-next/lib/signal-route-context.test.ts 
b/web-next/lib/signal-route-context.test.ts
index ac16c019f2..0268f99703 100644
--- a/web-next/lib/signal-route-context.test.ts
+++ b/web-next/lib/signal-route-context.test.ts
@@ -2,6 +2,8 @@ import { describe, expect, it } from 'vitest';
 import {
   appendSignalRouteContext,
   buildSignalAlertHandlingHref,
+  buildSignalAlertGroupKeys,
+  buildSignalAlertMatchLabels,
   buildSignalEntityContextRows,
   copySignalRouteContextParams,
   isDashboardReturnContext,
@@ -172,6 +174,24 @@ describe('signal route context', () => {
     expect(isDashboardReturnContext('//example.com/dashboard')).toBe(false);
   });
 
+  it('keeps operation context in alert match labels and group keys', () => {
+    const context = {
+      entityId: '7',
+      serviceName: 'checkout',
+      serviceNamespace: 'payments',
+      operationName: 'POST /checkout',
+      environment: 'prod',
+      traceId: 'trace-1'
+    };
+
+    expect(buildSignalAlertMatchLabels('traces', context)).toBe(
+      'hertzbeat.signal:traces, hertzbeat.entity.id:7, service.name:checkout, 
service.namespace:payments, operation.name:POST /checkout, 
deployment.environment:prod, trace_id:trace-1'
+    );
+    expect(buildSignalAlertGroupKeys('traces', context)).toBe(
+      'hertzbeat.signal, hertzbeat.entity.id, service.name, service.namespace, 
operation.name, deployment.environment'
+    );
+  });
+
   it('builds alert handling links for firing alert closure instead of 
threshold-rule configuration', () => {
     const logWorkbenchLabel = String.fromCodePoint(0x65e5, 0x5fd7, 0x5de5, 
0x4f5c, 0x53f0);
     const href = buildSignalAlertHandlingHref('logs', {
diff --git a/web-next/lib/signal-route-context.ts 
b/web-next/lib/signal-route-context.ts
index 4f6b1f1ce5..b487d8fd51 100644
--- a/web-next/lib/signal-route-context.ts
+++ b/web-next/lib/signal-route-context.ts
@@ -82,6 +82,7 @@ export function buildSignalAlertMatchLabels(signal: string | 
undefined, context:
     ['hertzbeat.entity.type', context.entityType],
     ['service.name', context.serviceName],
     ['service.namespace', context.serviceNamespace],
+    ['operation.name', context.operationName],
     ['deployment.environment', context.environment],
     ['trace_id', context.traceId],
     ['span_id', context.spanId],
@@ -110,6 +111,7 @@ export function buildSignalAlertGroupKeys(signal: string | 
undefined, context: S
     ['hertzbeat.entity.type', context.entityType],
     ['service.name', context.serviceName],
     ['service.namespace', context.serviceNamespace],
+    ['operation.name', context.operationName],
     ['deployment.environment', context.environment],
     ['hertzbeat.source', context.source],
     ['hertzbeat.collector', context.collector],


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to