2
0
Эх сурвалжийг харах

Merge pull request #448 from porter-dev/beta.3.nginx-custom-metrics

use correct namespace for nginx ingress
abelanger5 5 жил өмнө
parent
commit
c12ae81f0b

+ 7 - 5
dashboard/src/main/home/cluster-dashboard/expanded-chart/metrics/MetricsSection.tsx

@@ -131,8 +131,8 @@ export default class MetricsSection extends Component<PropsType, StateType> {
           });
 
           let ingressOptions = [] as any[];
-          res.data.map((ingress: string) => {
-            ingressOptions.push({ value: ingress, label: ingress });
+          res.data.map((ingress: any) => {
+            ingressOptions.push({ value: ingress, label: ingress.name });
           });
 
           // iterate through the controllers to get the list of pods
@@ -205,7 +205,7 @@ export default class MetricsSection extends Component<PropsType, StateType> {
       this.getMetrics();
     }
 
-    if (this.state.selectedIngress != prevState.selectedIngress) {
+    if (this.state.selectedIngress?.name != prevState.selectedIngress?.name) {
       this.getMetrics();
     }
   }
@@ -219,6 +219,7 @@ export default class MetricsSection extends Component<PropsType, StateType> {
     let { currentCluster, currentProject, setCurrentError } = this.context;
     let kind = this.state.selectedMetric;
     let shouldsum = true;
+    let namespace = currentChart.namespace;
 
     // calculate start and end range
     var d = new Date();
@@ -234,7 +235,8 @@ export default class MetricsSection extends Component<PropsType, StateType> {
     }
 
     if (this.state.selectedMetric == "nginx:errors") {
-      pods = [this.state.selectedIngress];
+      pods = [this.state.selectedIngress?.name];
+      namespace = this.state.selectedIngress?.namespace || "default"
       shouldsum = false;
     }
 
@@ -246,7 +248,7 @@ export default class MetricsSection extends Component<PropsType, StateType> {
           metric: kind,
           shouldsum: shouldsum,
           pods,
-          namespace: currentChart.namespace,
+          namespace: namespace,
           startrange: start,
           endrange: end,
           resolution: resolutions[this.state.selectedRange]

+ 11 - 3
internal/kubernetes/prometheus/metrics.go

@@ -29,21 +29,29 @@ func GetPrometheusService(clientset kubernetes.Interface) (*v1.Service, bool, er
 	return &services.Items[0], true, nil
 }
 
+type SimpleIngress struct {
+	Name      string `json:"name"`
+	Namespace string `json:"namespace"`
+}
+
 // GetIngressesWithNGINXAnnotation gets an array of names for all ingresses controlled by
 // NGINX
-func GetIngressesWithNGINXAnnotation(clientset kubernetes.Interface) ([]string, error) {
+func GetIngressesWithNGINXAnnotation(clientset kubernetes.Interface) ([]SimpleIngress, error) {
 	ingressList, err := clientset.NetworkingV1beta1().Ingresses("").List(context.TODO(), metav1.ListOptions{})
 
 	if err != nil {
 		return nil, err
 	}
 
-	res := make([]string, 0)
+	res := make([]SimpleIngress, 0)
 
 	for _, ingress := range ingressList.Items {
 		if ingressAnn, found := ingress.ObjectMeta.Annotations["kubernetes.io/ingress.class"]; found {
 			if ingressAnn == "nginx" {
-				res = append(res, ingress.ObjectMeta.Name)
+				res = append(res, SimpleIngress{
+					Name:      ingress.ObjectMeta.Name,
+					Namespace: ingress.ObjectMeta.Namespace,
+				})
 			}
 		}
 	}