Uploaded image for project: 'ZABBIX FEATURE REQUESTS'
  1. ZABBIX FEATURE REQUESTS
  2. ZBXNEXT-8497

Simplify LLD preprocessing in kubernates templates

XMLWordPrintable

    • Sprint 101 (Jun 2023)
    • 1

      In kubernetes tempaltes the LLD data is generated using the following preprocessing steps

      1. prometheus to json (to convert the required metrics to JSON format)
      2. javascript (so simplify converted JSON and embed LLD macros)
      3. throttle

      The second step (javascript) could be dropped by defining LLD macros in LLD rule configuration.
      For example the following data can be extracted with prometheus to json:

      [
        {
          "name": "kube_replicaset_status_replicas",
          "value": "2",
          "line_raw": "kube_replicaset_status_replicas{namespace=\"kube-system\",replicaset=\"coredns-787d4945fb\"} 2",
          "labels": {
            "namespace": "kube-system",
            "replicaset": "coredns-787d4945fb"
          },
          "type": "gauge",
          "help": "The number of replicas per ReplicaSet."
        },
        {
          "name": "kube_replicaset_status_replicas",
          "value": "1",
          "line_raw": "kube_replicaset_status_replicas{namespace=\"monitoring\",replicaset=\"zabbix-kube-state-metrics-56b6f796bc\"} 1",
          "labels": {
            "namespace": "monitoring",
            "replicaset": "zabbix-kube-state-metrics-56b6f796bc"
          },
          "type": "gauge",
          "help": "The number of replicas per ReplicaSet."
        },
        {
          "name": "kube_replicaset_status_replicas",
          "value": "1",
          "line_raw": "kube_replicaset_status_replicas{namespace=\"monitoring\",replicaset=\"zabbix-proxy-858c66755c\"} 1",
          "labels": {
            "namespace": "monitoring",
            "replicaset": "zabbix-proxy-858c66755c"
          },
          "type": "gauge",
          "help": "The number of replicas per ReplicaSet."
        },
        {
          "name": "kube_replicaset_status_replicas",
          "value": "6",
          "line_raw": "kube_replicaset_status_replicas{namespace=\"default\",replicaset=\"nginx-deployment-57b4bdfdf7\"} 6",
          "labels": {
            "namespace": "default",
            "replicaset": "nginx-deployment-57b4bdfdf7"
          },
          "type": "gauge",
          "help": "The number of replicas per ReplicaSet."
        },
        {
          "name": "kube_replicaset_status_replicas",
          "value": "1",
          "line_raw": "kube_replicaset_status_replicas{namespace=\"kube-system\",replicaset=\"calico-kube-controllers-56dd5794f\"} 1",
          "labels": {
            "namespace": "kube-system",
            "replicaset": "calico-kube-controllers-56dd5794f"
          },
          "type": "gauge",
          "help": "The number of replicas per ReplicaSet."
        }
      ]
      

      Then with javascript it's converted to:

      [
        {
          "{#NAME}": "coredns-787d4945fb",
          "{#NAMESPACE}": "kube-system"
        },
        {
          "{#NAME}": "zabbix-kube-state-metrics-56b6f796bc",
          "{#NAMESPACE}": "monitoring"
        },
        {
          "{#NAME}": "zabbix-proxy-858c66755c",
          "{#NAMESPACE}": "monitoring"
        },
        {
          "{#NAME}": "nginx-deployment-57b4bdfdf7",
          "{#NAMESPACE}": "default"
        },
        {
          "{#NAME}": "calico-kube-controllers-56dd5794f",
          "{#NAMESPACE}": "kube-system"
        }
      ]
      

      This could be simplified by dropping the conversion and defining the following LLD macros

      | {#NAME} | $.labels.replicaset |
      | {#NAMESPACE} | $.labels.namespace |
      

      It will result in slightly more memory usage to keep old values for throttling, however it will be partially offset by not having to cache javascript and its bytecode.

            drasikhov Denis Rasikhov
            wiper Andris Zeila
            Team INT
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: