Skip to content

Add support for hints' based autodiscovery in kubernetes provider #662

@ChrsMark

Description

@ChrsMark

As discussed at #613 (comment), kubernetes provider can be enhanced in order to support hint's based autodiscovery.

This can be achieved using the already supported dynamic variable resolution mechanism by constructing and emitting hint's specific mappings similar to elastic-agent/internal/pkg/composable/providers/kubernetes/pod.go.

Find below a full example of how we can reach from k8s annotations to an Agent input.

Hint's as annotations

annotations:
  co.elastic.hints/package: redis
  co.elastic.hints/data_streams: info, key
  co.elastic.hints/host: '${kubernetes.pod.ip}:6379'
  co.elastic.hints/info.period: 1m
  co.elastic.hints/key.period: 10m

Emitted mapping by k8s provider

{
  "kubernetes": {
    "hints": {
      "redis": {
        "info": {
          "enabled": true,
          "period": "1m",
          "host": "152.10.67.976:6379"
        },
        "key": {
          "enabled": true,
          "period": "10m",
          "host": "152.10.67.976:6379"
        }
      }
    }
  }
}

Defined template constructed by Fleet UI

providers:
  kubernetes:
    kube_config: /Users/chrismark/.kube/config
    node: "kind-control-plane"
    hints.enabled: true

inputs:
  - name: templates.d/redis/0.3.6
    type: redis/metrics
    data_stream.namespace: default
    use_output: default
    streams:
      - data_stream:
          dataset: redis.info
          type: metrics
        metricsets:
         - info
        hosts:
          - "${kubernetes.hints.redis.info.host|kubernetes.hints.redis.host|'127.0.0.1:6379'}"
        idle_timeout: 20s
        maxconn: 10
        network: tcp
        period: "${kubernetes.hints.redis.info.period|kubernetes.hints.redis.period|'10s'}"
        condition: ${kubernetes.hints.redis.info.enabled} == true or ${kubernetes.hints.redis.enabled} == true //enabled even if only the integration is enabled, AKA enabled by default
      - data_stream:
          dataset: redis.key
          type: metrics
        metricsets:
          - key
        hosts:
          - "${kubernetes.hints.redis.key.host|kubernetes.hints.redis.host|'127.0.0.1'}:${kubernetes.hints.redis.info.port|'6379'}"
        idle_timeout: 20s
        key.patterns:
          - limit: 20
            pattern: '*'
        maxconn: 10
        network: tcp
        period: "${kubernetes.hints.redis.key.period|kubernetes.hints.redis.period|'10s'}"
        condition: ${kubernetes.hints.redis.key.enabled} == true and ${kubernetes.hints.redis.enabled} == true //enabled only if explicitely enabled, AKA disabled by default

The above will be provided as a ConfigMap mounted into the Agent Pod:

apiVersion: v1
kind: ConfigMap
metadata:
  name: elastic-agent-standalone-inputs
data:
  redis.yml: |-
    inputs:
     - name: templates.d/redis/0.3.6
       type: redis/metrics
       data_stream.namespace: default
       use_output: default
       streams:
         - data_stream:
             dataset: redis.info
             type: metrics
           metricsets:
             ...

The scope of this issue is summarised into 2 parts and can be implemented already regardless of Fleet's UI implementation part:

Known issues/dependencies:

Closes #274

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions