菜单
企业版 开源版

配置 GEM federation-frontend

你可以使用 Helm 在 Kubernetes 集群中部署 Grafana Enterprise Metrics (GEM) federation-frontend。federation-frontend 允许你使用单个端点查询多个 GEM 集群的数据。有关集群查询联邦的更多信息,请参阅 federation-frontend 文档

注意

本指南专门介绍如何将 federation-frontend 组件作为独立部署,不包含任何额外的 GEM 或 Mimir 组件。

开始之前

  1. 设置 GEM 集群:有关设置和配置 GEM 部署的信息,请参阅 使用 Helm Chart 部署 Grafana Enterprise Metrics
  2. 为你要查询的每个集群提供具有 metrics:read 范围的访问令牌。有关更多信息,请参阅 设置 GEM 租户

部署 GEM federation-frontend

  1. 创建一个名为 gem-tokens 的 Kubernetes Secret,其中包含每个远程 GEM 集群的 GEM 访问令牌。Helm values 文件后续会使用这个 Secret。请将 TOKEN1TOKEN2 替换为远程 GEM 集群的访问令牌。

    yaml
    apiVersion: v1
    kind: Secret
    metadata:
      name: gem-tokens
    data:
      CLUSTER_1_GEM_TOKEN: TOKEN1
      CLUSTER_2_GEM_TOKEN: TOKEN2
  2. 使用 kubectl 命令将 secret 应用到 federation-frontend-demo 命名空间中的集群

    bash
    kubectl -n federation-frontend-demo apply -f mysecret.yaml
  3. 创建一个名为 federation-frontend.yaml 的 values 文件,内容如下。

    http://gem-query-frontend.monitoring.svc.cluster.local:8080/prometheushttps://gem.monitoring.acme.local/prometheus 替换为你要查询的 GEM 集群的 URL。将 tenant-1tenant-2 替换为远程 GEM 集群的租户 ID。

    请注意,这些资源设置仅为示例,对于小型部署已足够。请根据你的具体需求和负载调整这些值

    yaml
    # Enable enterprise features
    enterprise:
      enabled: true
    
    # Enable and configure federation-frontend
    federation_frontend:
      enabled: true
      # Since this is a standalone deployment, configure the chart to not render any of the other GEM components.
      disableOtherComponents: true
      replicas: 2
      resources:
        requests:
          cpu: 100m
          memory: 128Mi
        limits:
          cpu: 1
          memory: 256Mi
      extraEnvFrom:
        - secretRef:
            name: gem-tokens
    
    # Configure the remote GEM clusters to query.
    mimir:
      structuredConfig:
        auth:
          type: trust
        # The federation-frontend doesn't handle authentication or authorization. Disabling multitenancy means the federation-frontend doesn't require the X-Scope-OrgID header.
        # With disabled multitenancy, the federation-frontend uses the authn/z material from the proxy_targets configuration.
        # For a complete list of configuration options, refer to the configuration reference at https://grafana.org.cn/docs/enterprise-metrics/<GEM_VERSION>/config/reference/#federation.
        multitenancy_enabled: false
        federation:
          proxy_targets:
            - name: "cluster-1"
              url: "http://gem-query-frontend.monitoring.svc.cluster.local:8080/prometheus"
              basic_auth:
                username: tenant-1
                password: "${CLUSTER_1_GEM_TOKEN}"
    
            - name: "cluster-2"
              url: "https://gem.monitoring.acme.local/prometheus"
              basic_auth:
                username: tenant-2
                password: "${CLUSTER_2_GEM_TOKEN}"
    
    # Disable MinIO
    minio:
      enabled: false
    
    # The federation-frontend doesn't need the rollout-operator for rollouts, so it can be disabled.
    rollout_operator:
      enabled: false
  4. 使用 helm 部署 federation-frontend

    bash
    helm install federation-frontend grafana/mimir-distributed -f federation-frontend.yaml -n federation-frontend-demo

    这仅部署 federation-frontend 组件。federation-frontend 配置为将查询代理到你在 proxy_targets 配置中指定的 GEM 集群。

  5. 验证 federation-frontend 是否正在运行。最简单的方法是针对 federation-frontend 服务发出一个标签名称查询。

    此示例尝试从集群中访问 Kubernetes 服务,并请求过去 12 小时的标签名称。

    bash
    curl -XPOST 'https://mimir-federation-frontend:8080/prometheus/api/v1/labels' \
      -d "start=$(date -u +%Y-%m-%dT%H:%M:%S.0Z -d '12 hours ago' 2>/dev/null || date -u -v -12H +%Y-%m-%dT%H:%M:%S.0Z)" \
      -d "end=$(date -u +%Y-%m-%dT%H:%M:%S.0Z)"

    你应该会收到一个包含远程 GEM 集群标签名称的响应,类似于此

    json
    {
      "status": "success",
      "data": ["__cluster__", "__name__", "hash_extra", "series_id"]
    }