Metric function helm chart changes

Change-Id: I0122c765e4bc664ae4c68f796ed6cf4d6db84b4a
diff --git a/5g-control-plane/Chart.yaml b/5g-control-plane/Chart.yaml
index ed3fc86..7253c06 100644
--- a/5g-control-plane/Chart.yaml
+++ b/5g-control-plane/Chart.yaml
@@ -8,10 +8,15 @@
 name: 5g-control-plane
 icon: https://guide.opencord.org/logos/cord.svg
 
-version: 0.7.2
+version: 0.7.3
 
 dependencies:
   - name: mongodb
     version: 10.7.1
     repository: https://charts.bitnami.com/bitnami
     condition: mongodb.deploy
+  - name: kafka
+    version: 16.2.10
+    repository: https://charts.bitnami.com/bitnami
+    condition: kafka.deploy
+
diff --git a/5g-control-plane/templates/bin/_metrics-run.sh.tpl b/5g-control-plane/templates/bin/_metrics-run.sh.tpl
new file mode 100644
index 0000000..ccddaa4
--- /dev/null
+++ b/5g-control-plane/templates/bin/_metrics-run.sh.tpl
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+# Copyright 2022-present Open Networking Foundation
+#
+# SPDX-License-Identifier: Apache-2.0
+
+set -xe
+
+IMGPATH={{ .Values.config.imagePath }}
+{{- if .Values.config.coreDump.enabled }}
+cp /sdcore/metrics /tmp/coredump/
+{{- end }}
+
+cd /metricfunc
+cat config/metricscfg.conf
+
+echo $PWD
+
+GOTRACEBACK=crash /metricfunc/bin/metricfunc -metrics config/metricscfg.conf 
diff --git a/5g-control-plane/templates/configmap-metrics.yaml b/5g-control-plane/templates/configmap-metrics.yaml
new file mode 100644
index 0000000..7705174
--- /dev/null
+++ b/5g-control-plane/templates/configmap-metrics.yaml
@@ -0,0 +1,30 @@
+{{/*
+# Copyright 2022-present Open Networking Foundation
+
+# SPDX-License-Identifier: Apache-2.0
+*/}}
+
+{{- if .Values.config.metrics.deploy }}
+
+{{- if not .Values.config.useExistingConfigMap -}}
+{{- $metricscfg := index .Values.config.metrics.cfgFiles "metricscfg.conf" }}
+
+{{- end }}
+
+---
+apiVersion: v1
+kind: ConfigMap
+metadata:
+  name: metrics
+  labels:
+{{ tuple "metrics" . | include "5g-control-plane.metadata_labels" | indent 4 }}
+data:
+  metrics-run.sh: |
+{{ tuple "bin/_metrics-run.sh.tpl" . | include "5g-control-plane.template" | indent 4 }}
+{{- if not .Values.config.useExistingConfigMap -}}
+{{- range $key, $value := .Values.config.metrics.cfgFiles }}
+  {{ $key }}: |-
+{{ toYaml $value | indent 4 }}
+{{- end }}
+{{- end }}
+{{- end }}
diff --git a/5g-control-plane/templates/deployment-metrics.yaml b/5g-control-plane/templates/deployment-metrics.yaml
new file mode 100644
index 0000000..b19f9c4
--- /dev/null
+++ b/5g-control-plane/templates/deployment-metrics.yaml
@@ -0,0 +1,82 @@
+{{/*
+# Copyright 2022-present Open Networking Foundation
+
+# SPDX-License-Identifier: Apache-2.0
+*/}}
+{{- if .Values.config.metrics.deploy }}
+{{ tuple "metrics" . | include "5g-control-plane.service_account" }}
+---
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: metrics
+  labels:
+{{ tuple "metrics" . | include "5g-control-plane.metadata_labels" | indent 4 }}
+spec:
+  replicas: 1
+  #serviceName: metrics-headless
+  selector:
+    matchLabels:
+{{ tuple "metrics" . | include "5g-control-plane.metadata_labels" | indent 6 }}
+  template:
+    metadata:
+      labels:
+{{ tuple "metrics" . | include "5g-control-plane.metadata_labels" | indent 8 }}
+    {{- with .Values.config.metrics.podAnnotations }}
+      annotations:
+        {{- toYaml . | nindent 8 }}
+    {{- end }}
+    spec:
+      serviceAccountName: metrics
+    {{- if hasKey .Values.images "pullSecrets" }}
+      imagePullSecrets:
+{{ toYaml .Values.images.pullSecrets | indent 8 }}
+    {{- end }}
+      containers:
+      - name: metrics
+        image: {{ .Values.images.tags.metrics }}
+        imagePullPolicy: {{ .Values.images.pullPolicy }}
+      {{- if .Values.config.coreDump.enabled }}
+        securityContext:
+          runAsUser: 0
+      {{- end }}
+        stdin: true
+        tty: true
+        command: [ "/metricfunc/script/metrics-run.sh" ]
+        env:
+        - name: POD_IP
+          valueFrom:
+            fieldRef:
+              fieldPath: status.podIP
+      {{- if .Values.resources.enabled }}
+        resources:
+{{ toYaml .Values.resources.metrics | indent 10 }}
+      {{- end }}
+        volumeMounts:
+        - name: run-script
+          mountPath: /metricfunc/script/metrics-run.sh
+          subPath: metrics-run.sh
+        - name: metrics-config
+          mountPath: /metricfunc/config
+      {{- if .Values.config.coreDump.enabled }}
+        - name: coredump
+          mountPath: /tmp/coredump
+      {{- end }}
+      volumes:
+      - name: run-script
+        configMap:
+          name: metrics
+          defaultMode: 493
+      - name: metrics-config
+        configMap:
+          name: metrics
+          defaultMode: 493
+    {{- if .Values.config.coreDump.enabled }}
+      - name: host-rootfs
+        hostPath:
+          path: /
+      - name: coredump
+        hostPath:
+          path: {{ .Values.config.coreDump.path }}
+    {{- end }}
+{{- end }}
diff --git a/5g-control-plane/templates/service-metrics.yaml b/5g-control-plane/templates/service-metrics.yaml
new file mode 100644
index 0000000..7d8ec89
--- /dev/null
+++ b/5g-control-plane/templates/service-metrics.yaml
@@ -0,0 +1,28 @@
+{{/*
+# Copyright 2022-present Open Networking Foundation
+
+# SPDX-License-Identifier: Apache-2.0
+*/}}
+
+{{- if .Values.config.metrics.deploy }}
+---
+apiVersion: v1
+kind: Service
+metadata:
+  name: metrics
+  labels:
+{{ tuple "metrics" . | include "5g-control-plane.metadata_labels" | indent 4 }}
+spec:
+  type: {{ .Values.config.metrics.serviceType }}
+  selector:
+{{ tuple "metrics" . | include "5g-control-plane.metadata_labels" | indent 4 }}
+  ports:
+  - name: prometheus-exporter
+    port: {{ .Values.config.metrics.prometheus.port }}
+    protocol: TCP
+{{- if eq .Values.config.metrics.serviceType "NodePort" }}
+{{- if .Values.config.metrics.prometheus.nodePort }}
+    nodePort: {{ .Values.config.metrics.prometheus.nodePort }}
+{{- end }}
+{{- end }}
+{{- end }}
diff --git a/5g-control-plane/values.yaml b/5g-control-plane/values.yaml
index c3e1f0c..cda9a57 100644
--- a/5g-control-plane/values.yaml
+++ b/5g-control-plane/values.yaml
@@ -16,6 +16,7 @@
     udm: omecproject/5gc-udm:master-5992f3f
     webui: omecproject/5gc-webui:master-87adbcc
     sctplb: sctplb:0.0.1-dev-local1
+    metrics: metricfunc:0.0.1-dev-local0
   pullPolicy: IfNotPresent
 
 resources:
@@ -91,6 +92,17 @@
       cpu: 1
       memory: 1Gi
 
+  metrics:
+    requests:
+      cpu: 1
+      memory: 1Gi
+    limits:
+      cpu: 1
+      memory: 1Gi
+
+kafka:
+  deploy: false
+
 mongodb:
   deploy: true
   fullnameOverride: mongodb
@@ -631,3 +643,32 @@
             - mcc: "208"
               mnc: "93"
           groupId: ausfGroup001
+  metrics:
+    deploy: false
+    serviceType: ClusterIP
+    prometheus:
+      port: 9089
+    cfgFiles:
+      metricscfg.conf:
+        info:
+          version: 1.0.0
+          description: Metrics initial local configuration
+        logger:
+          logLevel: "debug"
+        configuration:
+          nfStream:
+            urls:
+              - "sd-core-kafka-headless:9092"
+            topic:
+              name: "sdcore-nf-data-source"
+              group:
+                analytics: "analytics"
+                mongodb: "mongodb"
+                restapi: "restapi"
+                prometheus: "prometheus"
+          analyticsStream:
+            enable: true
+            urls:
+               - "sd-core-kafka-headless:9092"
+            topic: "sdcore-analytics-feed"
+