瀏覽代碼

Merge branch 'prometheus_annotation_deduplication' of https://github.com/mtanda/grafana into mtanda-prometheus_annotation_deduplication

Torkel Ödegaard 6 年之前
父節點
當前提交
c7c0ba5a5a
共有 1 個文件被更改,包括 9 次插入3 次删除
  1. 9 3
      public/app/plugins/datasource/prometheus/datasource.ts

+ 9 - 3
public/app/plugins/datasource/prometheus/datasource.ts

@@ -355,10 +355,11 @@ export class PrometheusDatasource implements DataSourceApi<PromQuery> {
           })
           .value();
 
+        const dupCheck = {};
         for (const value of series.values) {
           const valueIsTrue = value[1] === '1'; // e.g. ALERTS
           if (valueIsTrue || annotation.useValueForTime) {
-            const event = {
+            const event: any = {
               annotation: annotation,
               title: self.resultTransformer.renderTemplate(titleFormat, series.metric),
               tags: tags,
@@ -366,9 +367,14 @@ export class PrometheusDatasource implements DataSourceApi<PromQuery> {
             };
 
             if (annotation.useValueForTime) {
-              event['time'] = Math.floor(parseFloat(value[1]));
+              const timestampValue = Math.floor(parseFloat(value[1]));
+              if (dupCheck[timestampValue]) {
+                continue;
+              }
+              dupCheck[timestampValue] = true;
+              event.time = timestampValue;
             } else {
-              event['time'] = Math.floor(parseFloat(value[0])) * 1000;
+              event.time = Math.floor(parseFloat(value[0])) * 1000;
             }
 
             eventList.push(event);