affo commented on code in PR #2711:
URL: https://github.com/apache/fluss/pull/2711#discussion_r2931488532


##########
helm/templates/_metrics.tpl:
##########
@@ -0,0 +1,88 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+{{/*
+Returns list of provided reporter names.
+*/}}
+{{- define "fluss.metrics.reporterNames" -}}
+{{- $metrics := .Values.metrics | default dict -}}
+{{- $reportersValue := $metrics.reporters | default "" | toString | trim -}}
+{{- if eq $reportersValue "" -}}
+[]
+{{- else -}}
+{{- $selected := list -}}
+{{- range $raw := regexSplit "\\s*,\\s*" $reportersValue -1 -}}
+{{- $name := trim $raw -}}
+{{- if ne $name "" -}}
+{{- $selected = append $selected $name -}}
+{{- end -}}
+{{- end -}}
+{{- $selected | toYaml -}}
+{{- end -}}
+{{- end -}}
+
+{{/*
+Checks if prometheus reporter is enabled.
+*/}}
+{{- define "fluss.metrics.prometheusEnabled" -}}
+{{- $reporterNames := include "fluss.metrics.reporterNames" . | fromYamlArray 
-}}
+{{- if has "prometheus" $reporterNames -}}
+true
+{{- end -}}
+{{- end -}}
+
+{{/*
+Renders metrics reporter configuration entries.
+Expects the root context as argument.
+
+From values:
+  metrics:
+    reporters: prometheus
+    prometheus:
+      port: 9249
+
+Renders:
+  metrics.reporters: prometheus
+  metrics.reporter.prometheus.port: 9249
+
+Only the port is rendered from values. All other reporter options
+should be specified via configurationOverrides.
+The port must be set via metrics.<name>.port, not via configurationOverrides.
+*/}}
+{{- define "fluss.metrics.config" -}}

Review Comment:
   What do you think?
   
   ```yaml
   {{/*
   Get a value preferring configurationOverrides over a specific key.
   Usage:
   {{ include "fluss.getWithOverride" (dict
       "key" "some.config.key"
       "default" .Values.some.value
       "ctx" .) }}
   */}}
   {{- define "fluss.getWithOverride" -}}
   {{- $overrides := .ctx.Values.configurationOverrides | default dict -}}
   {{- if hasKey $overrides .key -}}
     {{- index $overrides .key -}}
   {{- else -}}
     {{- .default -}}
   {{- end -}}
   {{- end -}}
   ```
   
   This should to to `_helpers.tpl` as it would come in handy for any clash in 
the future (e.g.: lake tiering?).
   
   



##########
helm/templates/_metrics.tpl:
##########
@@ -0,0 +1,88 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+

Review Comment:
   Add 
   
   ```
   {{- define "fluss.metrics.enabled" -}}
   {{- $reporters := include "fluss.metrics.reporterNames" . | fromYaml -}}
   {{- if gt (len $reporters) 0 -}}
   true
   {{- end -}}
   {{- end -}}
   ```



##########
helm/templates/_metrics.tpl:
##########
@@ -0,0 +1,88 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+{{/*
+Returns list of provided reporter names.
+*/}}
+{{- define "fluss.metrics.reporterNames" -}}
+{{- $metrics := .Values.metrics | default dict -}}
+{{- $reportersValue := $metrics.reporters | default "" | toString | trim -}}

Review Comment:
   ```suggestion
   {{- $reportersValue := (include "fluss.getWithOverride" (dict
       "key" "metrics.reporters"
       "default" (index .Values.metrics "reporters" | default "")
       "ctx" .)) -}}
   ```



##########
helm/templates/_metrics.tpl:
##########
@@ -0,0 +1,88 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+{{/*
+Returns list of provided reporter names.
+*/}}
+{{- define "fluss.metrics.reporterNames" -}}
+{{- $metrics := .Values.metrics | default dict -}}
+{{- $reportersValue := $metrics.reporters | default "" | toString | trim -}}
+{{- if eq $reportersValue "" -}}
+[]
+{{- else -}}
+{{- $selected := list -}}
+{{- range $raw := regexSplit "\\s*,\\s*" $reportersValue -1 -}}
+{{- $name := trim $raw -}}
+{{- if ne $name "" -}}
+{{- $selected = append $selected $name -}}
+{{- end -}}
+{{- end -}}
+{{- $selected | toYaml -}}
+{{- end -}}
+{{- end -}}
+
+{{/*
+Checks if prometheus reporter is enabled.
+*/}}
+{{- define "fluss.metrics.prometheusEnabled" -}}

Review Comment:
   you may also create 1 function that returns if a reporter is enabled
   
   ```yaml
   {{/*
   Usage:
     {{ include "fluss.metrics.reporter.enabled" (dict "reporter" "jmx"        
"ctx" .) }}
     {{ include "fluss.metrics.reporter.enabled" (dict "reporter" "prometheus" 
"ctx" .) }}
   */}}
   {{- define "fluss.metrics.reporter.enabled" -}}
   {{- $reporterNames := include "fluss.metrics.reporterNames" .ctx | 
fromYamlArray -}}
   {{- if has .reporter $reporterNames -}}
   true
   {{- end -}}
   {{- end -}}
   ```



##########
helm/templates/_metrics.tpl:
##########
@@ -0,0 +1,88 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+{{/*
+Returns list of provided reporter names.
+*/}}
+{{- define "fluss.metrics.reporterNames" -}}
+{{- $metrics := .Values.metrics | default dict -}}
+{{- $reportersValue := $metrics.reporters | default "" | toString | trim -}}
+{{- if eq $reportersValue "" -}}
+[]
+{{- else -}}
+{{- $selected := list -}}
+{{- range $raw := regexSplit "\\s*,\\s*" $reportersValue -1 -}}
+{{- $name := trim $raw -}}
+{{- if ne $name "" -}}
+{{- $selected = append $selected $name -}}
+{{- end -}}
+{{- end -}}
+{{- $selected | toYaml -}}
+{{- end -}}
+{{- end -}}
+
+{{/*
+Checks if prometheus reporter is enabled.
+*/}}
+{{- define "fluss.metrics.prometheusEnabled" -}}

Review Comment:
   I would also add:
   
   ```yaml
   {{- define "fluss.metrics.reporter.jmx.enabled" -}}
   {{- $reporterNames := include "fluss.metrics.reporterNames" . | 
fromYamlArray -}}
   {{- if has "jmx" $reporterNames -}}
   true
   {{- end -}}
   {{- end -}}
   ```



##########
helm/templates/configmap.yaml:
##########
@@ -26,4 +26,5 @@ data:
   server.yaml: |
     {{- range $key, $val := .Values.configurationOverrides }}
     {{ $key }}: {{ tpl (printf "%v" $val) $ }}
-    {{- end }}
\ No newline at end of file
+    {{- end }}
+    {{- include "fluss.metrics.config" . | nindent 4 }}

Review Comment:
   ```suggestion
       {{- end }}
       
       {{- if include "fluss.metrics.enabled" -}}
       ### Metrics
       
       {{- if not (hasKey .Values.configurationOverrides "metrics.reporters") 
-}}
       metrics.reporters: {{ .Values.metrics.reporters }}
       {{- end -}}
       
       
       ... and so on...
   ```



-- 
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