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

Merge branch '0.7.0-hpa-metrics' of github.com:porter-dev/porter into 0.7.0-hpa-metrics

jnfrati 4 лет назад
Родитель
Сommit
3e779fe21f

+ 8 - 0
dashboard/src/main/home/cluster-dashboard/expanded-chart/metrics/MetricsSection.tsx

@@ -267,7 +267,14 @@ const MetricsSection: React.FunctionComponent<PropsType> = ({
     const end = Math.round(d.getTime() / 1000);
     const start = end - secondsBeforeNow[selectedRange];
 
+    let podNames = [] as string[];
+
+    if (!shouldsum) {
+      podNames = [selectedPod];
+    }
+
     if (selectedMetric == "nginx:errors") {
+      podNames = [selectedIngress?.name];
       namespace = selectedIngress?.namespace || "default";
       shouldsum = false;
     }
@@ -287,6 +294,7 @@ const MetricsSection: React.FunctionComponent<PropsType> = ({
           startrange: start,
           endrange: end,
           resolution: resolutions[selectedRange],
+          pods: podNames,
         },
         {
           id: currentProject.id,

+ 1 - 0
dashboard/src/shared/api.tsx

@@ -558,6 +558,7 @@ const getMetrics = baseApi<
     cluster_id: number;
     metric: string;
     shouldsum: boolean;
+    pods: string[];
     kind: string, // the controller kind
     name: string;
     namespace: string;

+ 17 - 9
internal/kubernetes/prometheus/metrics.go

@@ -60,14 +60,15 @@ func GetIngressesWithNGINXAnnotation(clientset kubernetes.Interface) ([]SimpleIn
 }
 
 type QueryOpts struct {
-	Metric     string `schema:"metric"`
-	ShouldSum  bool   `schema:"shouldsum"`
-	Kind       string `schema:"kind"`
-	Name       string `schema:"name"`
-	Namespace  string `schema:"namespace"`
-	StartRange uint   `schema:"startrange"`
-	EndRange   uint   `schema:"endrange"`
-	Resolution string `schema:"resolution"`
+	Metric     string   `schema:"metric"`
+	ShouldSum  bool     `schema:"shouldsum"`
+	Kind       string   `schema:"kind"`
+	PodList    []string `schema:"pods"`
+	Name       string   `schema:"name"`
+	Namespace  string   `schema:"namespace"`
+	StartRange uint     `schema:"startrange"`
+	EndRange   uint     `schema:"endrange"`
+	Resolution string   `schema:"resolution"`
 }
 
 func QueryPrometheus(
@@ -85,7 +86,14 @@ func QueryPrometheus(
 		return nil, err
 	}
 
-	podSelector := fmt.Sprintf(`namespace="%s",pod=~"%s",container!="POD",container!=""`, opts.Namespace, podSelectionRegex)
+	var podSelector string
+
+	if len(opts.PodList) > 0 {
+		podSelector = fmt.Sprintf(`namespace="%s",pod=~"%s",container!="POD",container!=""`, opts.Namespace, strings.Join(opts.PodList, "|"))
+	} else {
+		podSelector = fmt.Sprintf(`namespace="%s",pod=~"%s",container!="POD",container!=""`, opts.Namespace, podSelectionRegex)
+	}
+
 	query := ""
 
 	if opts.Metric == "cpu" {