grafana / helm-charts

Apache License 2.0
1.63k stars 2.26k forks source link

Helm release of loki-stack using CDK #2394

Open saritatewari4 opened 1 year ago

saritatewari4 commented 1 year ago

Hi,

I am trying to deploy loki stack on cdk using helm release.

from aws_cdk import aws_eks as eks
from aws_cdk import aws_iam as iam
from aws_cdk.core import Construct, Stack

class ObservabilityStack:
    def __init__(self, cluster: eks.ICluster, context: Stack):
        self.cluster = cluster
        self.context = context
        self.name = "observability"

    def run(self) -> Construct:
        namespace = self.cluster.add_manifest(f"{self.name}-namespace", {
            "apiVersion": "v1",
            "kind": "Namespace",
            "metadata": {
                "name": self.name
            }
        })
        chart_specs = [
            {
                "name": "grafana",
                "chart": {
                    "git": "https://github.com/grafana/helm-charts",
                    "path": "charts/grafana",
                    "ref": "bd62f15e63f3e78aa9514d420bc028db9b5f47f0"
                },
                "values": {
                    "persistence": {
                        "enabled": False
                    }
                }
            },
            {
                "name": "loki",
                "chart": {
                    "git": "https://github.com/grafana/helm-charts",
                    "path": "charts/loki-stack",
                    "ref": "811015b64af55017df32c73b35dadcf1b8c5a6b5"
                },
                "values": {
                    "promtail": {
                        "enabled": False
                    },
                    "loki": {   
                        "datasource": {    
                            "jsonData": {
                                "datasourceUid": "Tempo",
                                "matcherRegex": "\"traceId\":\"(\\w+)\"",
                                "name": "TraceID",
                                "url": "$${__value.raw}"
                            },
                        }
                    }
                    # "loki":{
                    #     "url": "http://loki:3300",
                    #     "datasource": [
                    #         {
                    #             "jsonData": {
                    #                 "datasourceUid": "Tempo",
                    #                 "matcherRegex": "\"traceId\":\"(\\w+)\"",
                    #                 "name": "TraceID",
                    #                 "url": "$${__value.raw}"
                    #             }
                    #         }
                    #     ]
                    # }
                }
            },
            {
                "name": "tempo",
                "chart": {
                    "git": "https://github.com/grafana/helm-charts",
                    "path": "charts/tempo",
                    "ref": "a25c8e970a5e5f95d5f8b4a9fb8c662a294d8205"
                },
                "values":{}
            }
        ]

        charts = []
        for spec in chart_specs:
            chart = self.cluster.add_manifest(f"observability-{spec['name']}", {
                "apiVersion": "helm.fluxcd.io/v1",
                "kind": "HelmRelease",
                "metadata": {
                    "name": spec['name'],
                    "namespace": self.name
                },
                "spec": {
                    "chart": spec['chart'],
                    "releaseName": spec['name'],
                    "targetNamespace": self.name,
                    "values": spec['values'],
                }
            })
            charts.append(chart)

        for chart in charts:
            chart.node.add_dependency(namespace)

I wanted to modify the config map of Loki to update the derived field. Above configuration is not working. I can't see modified derived fields, which I am passing from this CDK file. I am not getting any error msg also in eks.

Please help me on this.

MayurDuduka commented 6 months ago

https://grafana.com/docs/grafana/latest/datasources/loki/#provision-the-loki-data-source



datasources:
  - name: Loki
    type: loki
    access: proxy
    url: http://localhost:3100
    basicAuth: true
    basicAuthUser: my_user
    jsonData:
      maxLines: 1000
      derivedFields:
        # Field with internal link pointing to data source in Grafana.
        # datasourceUid value can be anything, but it should be unique across all defined data source uids.
        - datasourceUid: my_jaeger_uid
          matcherRegex: "traceID=(\\w+)"
          name: TraceID
          # url will be interpreted as query for the datasource
          url: '$${__value.raw}'
          # optional for URL Label to set a custom display label for the link.
          urlDisplayLabel: 'View Trace'

        # Field with external link.
        - matcherRegex: "traceID=(\\w+)"
          name: TraceID
          url: 'http://localhost:16686/trace/$${__value.raw}'
    secureJsonData:
      basicAuthPassword: test_password```