grafana / alloy

OpenTelemetry Collector distribution with programmable pipelines
https://grafana.com/oss/alloy
Apache License 2.0
1.25k stars 157 forks source link

should be capsule, got array #1370

Closed condaatje closed 1 month ago

condaatje commented 1 month ago

What's wrong?

when importing a list of namespaces via configmap, alloy config throws an error

Steps to reproduce

create a configmap like so:

---
kind: ConfigMap
metadata:
  name: grafana-cloud
apiVersion: v1
data:
  loki-target-namespaces: |-
    ["argocd", "tailscale"]

then try to import the list of namespaces in the alloy config like so:

    discovery.kubernetes "pod" {
      role = "pod"
      namespaces {
        own_namespace = true
        // https://grafana.com/docs/alloy/latest/get-started/configuration-syntax/expressions/function_calls/
        names = nonsensitive(json_decode(remote.kubernetes.configmap.grafana_cloud.data["loki-target-namespaces"]))
      }
    }

config reloader spits out the following error:

alloy Error: /etc/alloy/config.alloy:90:26: json_decode(remote.kubernetes.configmap.grafana_cloud.data["loki-target-namespaces"]) should be capsule, got array
alloy 
alloy 89 |     // https://grafana.com/docs/alloy/latest/get-started/configuration-syntax/expressions/function_calls/
alloy 90 |     names = nonsensitive(json_decode(remote.kubernetes.configmap.grafana_cloud.data["loki-target-namespaces"]))
alloy    |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
alloy 91 |   }
alloy interrupt received
alloy Error: could not perform the initial load successfully
Stream closed EOF for alloy/alloy-xnqcl (alloy)

System information

kubernetes

Software version

latest version of alloy

Configuration

discovery.kubernetes "pod" {
      role = "pod"
      namespaces {
        own_namespace = true
        // https://grafana.com/docs/alloy/latest/get-started/configuration-syntax/expressions/function_calls/
        names = nonsensitive(json_decode(remote.kubernetes.configmap.grafana_cloud.data["loki-target-namespaces"]))
      }
    }

Logs

alloy Error: /etc/alloy/config.alloy:90:26: json_decode(remote.kubernetes.configmap.grafana_cloud.data["loki-target-namespaces"]) should be capsule, got array
alloy 
alloy 89 |     // https://grafana.com/docs/alloy/latest/get-started/configuration-syntax/expressions/function_calls/
alloy 90 |     names = nonsensitive(json_decode(remote.kubernetes.configmap.grafana_cloud.data["loki-target-namespaces"]))
alloy    |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
alloy 91 |   }
alloy interrupt received
alloy Error: could not perform the initial load successfully
Stream closed EOF for alloy/alloy-xnqcl (alloy)
condaatje commented 1 month ago

it's possible I'm doing something wrong here

rfratto commented 1 month ago

Hi, the main issue seems to be that nonsensitive expects a string or a secret, but you're passing in an array (["argocd", "tailscale"]). It looks like things should be OK if you remove that call to nonsensitive:

discovery.kubernetes "pod" {
      role = "pod"
      namespaces {
        own_namespace = true
        // https://grafana.com/docs/alloy/latest/get-started/configuration-syntax/expressions/function_calls/
        names = json_decode(remote.kubernetes.configmap.grafana_cloud.data["loki-target-namespaces"])
      }
    }
condaatje commented 1 month ago

awesome, that worked nicely. thanks!