{{- if .Values.printNotes }}
{{- if .Values.server.enabled }}
{{- $ctx := dict "helm" . "appKey" "server" "style" "plain" }}
{{- $fullname := include "vm.plain.fullname" $ctx }}
{{- $ns := include "vm.namespace" $ctx }}
The VictoriaMetrics write api can be accessed via port {{ .Values.server.service.servicePort }} on the following DNS name from within your cluster:
    {{ include "vm.fqdn" $ctx }}

Metrics Ingestion:
  Get the Victoria Metrics service URL by running these commands in the same shell:

{{- if contains "NodePort" .Values.server.service.type }}
    export NODE_PORT=$(kubectl get --namespace {{ $ns }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ $fullname }})
    export NODE_IP=$(kubectl get nodes --namespace {{ $ns }} -o jsonpath="{.items[0].status.addresses[0].address}")
    echo http://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.server.service.type }}
    NOTE: It may take a few minutes for the LoadBalancer IP to be available.
      You can watch the status of by running 'kubectl get svc --namespace {{ $ns }} -w {{ $fullname }}'

    export SERVICE_IP=$(kubectl get svc --namespace {{ $ns }} {{ $fullname }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
    echo http://$SERVICE_IP:{{ .Values.server.service.servicePort }}
{{- else if contains "ClusterIP"  .Values.server.service.type }}
    export POD_NAME=$(kubectl get pods --namespace {{ $ns }} -l "app={{ include "vm.app.name" $ctx }}" -l "app.kubernetes.io/instance={{ include "vm.release" $ctx }}" -o jsonpath="{.items[0].metadata.name}")
    kubectl --namespace {{ $ns }} port-forward $POD_NAME {{ .Values.server.service.servicePort }}
{{- end }}

  Write URL inside the kubernetes cluster:
    {{ include "vm.url" $ctx }}/<protocol-specific-write-endpoint>

  All supported write endpoints can be found at https://docs.victoriametrics.com/victoriametrics/single-server-victoriametrics/#how-to-import-time-series-data

  E.g: for Prometheus:
    {{ include "vm.url" $ctx }}/api/v1/write

{{- if .Values.server.scrape.enabled }}

Metrics Scrape:
  Pull-based scrapes are enabled
  Scrape config can be displayed by running this command::
    {{- if eq .Values.server.scrape.configMap "" }}
    kubectl get cm {{ $fullname }}-scrapeconfig -n {{ $ns }}
    {{- else }}
    kubectl get cm .Values.server.scrape.configMap -n {{ $ns }}
    {{- end }}

  The target’s information is accessible via api:
    Inside cluster:
      {{ include "vm.url" $ctx }}/targets
    Outside cluster:
      You need to port-forward service (see instructions above) and call
      http://<service-host-port>/targets
{{- end }}

Read Data:
  The following URL can be used as the datasource URL in Grafana::
    {{ include "vm.url" $ctx }}
{{- end }}
{{- end }}
