Просмотр исходного кода

fix: add missing handling for nginx:status responses

Jose Diaz-Gonzalez 2 лет назад
Родитель
Сommit
75b8feb67a

+ 14 - 0
dashboard/src/main/home/cluster-dashboard/expanded-chart/metrics/MetricNormalizer.ts

@@ -42,6 +42,9 @@ export class MetricNormalizer {
     if (this.kind.includes("nginx:errors")) {
     if (this.kind.includes("nginx:errors")) {
       return this.parseNGINXErrorsMetrics(this.metric_results);
       return this.parseNGINXErrorsMetrics(this.metric_results);
     }
     }
+    if (this.kind.includes("nginx:status")) {
+      return this.parseNGINXStatusMetrics(this.metric_results);
+    }
     if (
     if (
       this.kind.includes("nginx:latency") ||
       this.kind.includes("nginx:latency") ||
       this.kind.includes("nginx:latency-histogram")
       this.kind.includes("nginx:latency-histogram")
@@ -126,6 +129,17 @@ export class MetricNormalizer {
     });
     });
   }
   }
 
 
+  private parseNGINXStatusMetrics(
+    arr: MetricsNGINXErrorsDataResponse["results"]
+  ) {
+    return arr.map((d) => {
+      return {
+        date: d.date,
+        value: parseFloat(d.status_code),
+      };
+    });
+  }
+
   private parseNGINXLatencyMetrics(
   private parseNGINXLatencyMetrics(
     arr: MetricsNGINXLatencyDataResponse["results"]
     arr: MetricsNGINXLatencyDataResponse["results"]
   ) {
   ) {

+ 1 - 0
dashboard/src/main/home/cluster-dashboard/expanded-chart/metrics/types.ts

@@ -70,6 +70,7 @@ export type AvailableMetrics =
   | "network"
   | "network"
   | "nginx:errors"
   | "nginx:errors"
   | "nginx:latency"
   | "nginx:latency"
+  | "nginx:status"
   | "cpu_hpa_threshold"
   | "cpu_hpa_threshold"
   | "memory_hpa_threshold"
   | "memory_hpa_threshold"
   | "hpa_replicas";
   | "hpa_replicas";

+ 10 - 7
internal/kubernetes/prometheus/metrics.go

@@ -269,13 +269,14 @@ type promRawQuery struct {
 }
 }
 
 
 type promParsedSingletonQueryResult struct {
 type promParsedSingletonQueryResult struct {
-	Date     interface{} `json:"date,omitempty"`
-	CPU      interface{} `json:"cpu,omitempty"`
-	Replicas interface{} `json:"replicas,omitempty"`
-	Memory   interface{} `json:"memory,omitempty"`
-	Bytes    interface{} `json:"bytes,omitempty"`
-	ErrorPct interface{} `json:"error_pct,omitempty"`
-	Latency  interface{} `json:"latency,omitempty"`
+	Date       interface{} `json:"date,omitempty"`
+	CPU        interface{} `json:"cpu,omitempty"`
+	Replicas   interface{} `json:"replicas,omitempty"`
+	Memory     interface{} `json:"memory,omitempty"`
+	Bytes      interface{} `json:"bytes,omitempty"`
+	ErrorPct   interface{} `json:"error_pct,omitempty"`
+	Latency    interface{} `json:"latency,omitempty"`
+	StatusCode interface{} `json:"status_code,omitempty"`
 }
 }
 
 
 type promParsedSingletonQuery struct {
 type promParsedSingletonQuery struct {
@@ -313,6 +314,8 @@ func parseQuery(rawQuery []byte, metric string) ([]*promParsedSingletonQuery, er
 				singletonResult.Bytes = values[1]
 				singletonResult.Bytes = values[1]
 			} else if metric == "nginx:errors" {
 			} else if metric == "nginx:errors" {
 				singletonResult.ErrorPct = values[1]
 				singletonResult.ErrorPct = values[1]
+			} else if metric == "nginx:status" {
+				singletonResult.StatusCode = values[1]
 			} else if metric == "cpu_hpa_threshold" {
 			} else if metric == "cpu_hpa_threshold" {
 				singletonResult.CPU = values[1]
 				singletonResult.CPU = values[1]
 			} else if metric == "memory_hpa_threshold" {
 			} else if metric == "memory_hpa_threshold" {