lianneli commented on code in PR #2673:
URL: https://github.com/apache/celeborn/pull/2673#discussion_r1730037430


##########
charts/celeborn/templates/_helpers.tpl:
##########
@@ -155,3 +155,78 @@ Create the name of the worker podmonitor to use
 {{- define "celeborn.workerPodMonitorName" -}}
 {{ include "celeborn.fullname" . }}-worker-podmonitor
 {{- end }}
+
+{{/*
+Create master annotations if metrics enables
+*/}}
+{{- define "celeborn.masterMetricsAnnotation" -}}
+{{- $metricsEnabled := true -}}
+{{- $metricsPath := "/metrics/prometheus" -}}
+{{- $masterPort := 9098 -}}
+{{- range $key, $val := .Values.celeborn }}
+{{- if eq $key "celeborn.metrics.enabled" }}
+{{- $metricsEnabled = $val -}}
+{{- end }}
+{{- if eq $key "celeborn.metrics.prometheus.path" }}
+{{- $metricsPath = $val -}}
+{{- end }}
+{{- if eq $key "celeborn.master.http.port" }}
+{{- $masterPort = $val -}}
+{{- end }}
+{{- end }}
+{{- if eq (toString $metricsEnabled) "true" -}}
+prometheus.io/path: {{ $metricsPath }}
+prometheus.io/port: '{{ $masterPort }}'
+prometheus.io/scheme: 'http'
+prometheus.io/scrape: 'true'
+{{- end }}
+{{- end }}
+
+{{/*
+Create worker annotations if metrics enables
+*/}}
+{{- define "celeborn.workerMetricsAnnotation" -}}
+{{- $metricsEnabled := true -}}
+{{- $metricsPath := "/metrics/prometheus" -}}
+{{- $workerPort := 9096 -}}
+{{- range $key, $val := .Values.celeborn }}
+{{- if eq $key "celeborn.metrics.enabled" }}
+{{- $metricsEnabled = $val -}}
+{{- end }}
+{{- if eq $key "celeborn.metrics.prometheus.path" }}
+{{- $metricsPath = $val -}}
+{{- end }}
+{{- if eq $key "celeborn.worker.http.port" }}
+{{- $workerPort = $val -}}
+{{- end }}
+{{- end }}
+{{- if eq (toString $metricsEnabled) "true" -}}
+prometheus.io/path: {{ $metricsPath }}
+prometheus.io/port: '{{ $workerPort }}'
+prometheus.io/scheme: 'http'
+prometheus.io/scrape: 'true'
+{{- end }}
+{{- end }}
+
+{{/*

Review Comment:
   > > Of Course, we can add the prometheus http port in master service for 
understanding more easily. Should I do that?
   > 
   > No, but I'm still very interested in why Prometheus can still scrape 
metrics successfully.
   
   @RexXiong 
   Good question, and I made a test.
   
   In k8s, the core role of Service is translating **Pod's ip** to domain name 
like "xxx.namespace.svc.cluster.local", whether the port set in Service is a 
real one. However, Service will not work if there is none port set. 
   
   Prometheus would search all the "on working" service, fetch annotations to 
get real port, then get **Pod's ip** though K8s Api to finish the metrics 
scratching.  
   
   That's why we need not set another port in Master Service.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to