canonical / grafana-cloud-integrator

https://charmhub.io/grafana-cloud-integrator
Apache License 2.0
1 stars 1 forks source link

Requirer (e.g. grafana-agent) does not see the loki url forwarded from the provider #18

Open sed-i opened 1 day ago

sed-i commented 1 day ago

Bug Description

The grafana-agent.yaml file that grafana agent renders, with the help of the grafana_cloud_integrator lib, ends up with an empty "loki" section, even though loki_url was set as a config option in the integrator charm.

To Reproduce

Deploy the following bundle. The loki section in juju ssh --container agent ga/0 cat /etc/grafana-agent.yaml is empty.

bundle: kubernetes
applications:
  flog:
    charm: flog-k8s
    channel: latest/edge
    revision: 8
    base: ubuntu@20.04/stable
    resources:
      workload-image: 2
    scale: 1
    constraints: arch=amd64
  ga:
    charm: grafana-agent-k8s
    channel: latest/edge
    revision: 95
    resources:
      agent-image: 45
    scale: 1
    constraints: arch=amd64
    storage:
      data: kubernetes,1,1024M
  gci:
    charm: grafana-cloud-integrator
    channel: latest/edge
    revision: 21
    scale: 1
    options:
      loki-url: http://exmaple.com
      password: passwd
      username: admin
    constraints: arch=amd64
relations:
- - flog:log-proxy
  - ga:logging-provider
- - gci:grafana-cloud-config
  - ga:grafana-cloud-config

Environment

Model  Controller  Cloud/Region        Version  SLA          Timestamp
graf   microk8s    microk8s/localhost  3.5.3    unsupported  13:57:47-05:00

App   Version  Status   Scale  Charm                     Channel      Rev  Address         Exposed  Message
flog           blocked      1  flog-k8s                  latest/edge    8  10.152.183.67   no       No promtail client endpoints available!
ga    0.40.4   active       1  grafana-agent-k8s         latest/edge   95  10.152.183.166  no       
gci            active       1  grafana-cloud-integrator  latest/edge   21  10.152.183.217  no       Metrics disabled

Relevant log output

~> juju ssh --container agent ga/0 cat /etc/grafana-agent.yaml
integrations:
  agent:
    enabled: true
    relabel_configs:
    - regex: (.*)
      replacement: juju_graf_599f66b6-ee4d-4be1-8f64-bb1a84da123b_ga_self-monitoring
      target_label: job
    - regex: (.*)
      replacement: graf_599f66b6-ee4d-4be1-8f64-bb1a84da123b_ga_ga/0
      target_label: instance
    - replacement: grafana-agent-k8s
      source_labels:
      - __address__
      target_label: juju_charm
    - replacement: graf
      source_labels:
      - __address__
      target_label: juju_model
    - replacement: 599f66b6-ee4d-4be1-8f64-bb1a84da123b
      source_labels:
      - __address__
      target_label: juju_model_uuid
    - replacement: ga
      source_labels:
      - __address__
      target_label: juju_application
    - replacement: ga/0
      source_labels:
      - __address__
      target_label: juju_unit
  prometheus_remote_write: []
logs: {}
metrics:
  configs:
  - name: agent_scraper
    remote_write: []
    scrape_configs: []
  wal_directory: /tmp/agent/data
server:
  log_level: info
traces: {}

Additional context

No response

lucabello commented 20 hours ago

This is a Grafana Agent issue. When we build the Loki config, we currently do:

...
if self._loki_consumer.loki_endpoints:
    configs.append(
        {
            "name": "push_api_server",
            "clients": self._loki_endpoints_with_tls(),
            "scrape_configs": [
                ...

The endpoints from Grafana Cloud integrator are coming from self._loki_endpoints_with_tls(), meaning we won't add them to the configuration if there are no endpoints coming from _loki_consumer (which is the case if you don't relate Grafana Agent to Loki).