elastic / elastic-agent

Elastic Agent - single, unified way to add monitoring for logs, metrics, and other types of data to a host.
Other
112 stars 126 forks source link

Testing Elastic Agent Service autodiscovery with Synthetics #3075

Open gizas opened 11 months ago

gizas commented 11 months ago

Elastic Agent support autodiscovery of kubernetes services through kubernetes provider as decribed in https://www.elastic.co/guide/en/fleet/current/kubernetes-provider.html#_provider_for_service_resources

This case will try to investigate the configuration needed to support Kubernetes Service autodiscovery and demonstrate the information in Synthetics or any other alternative kibana page.

gizas commented 11 months ago

Prerequisities:

Create infratructure:

kind create cluster --image kindest/node:v1.26.3
docker network connect elastic-package-stack_default kind-control-plane                                                                                                                                                                                                                                                                                                
elastic-package stack up -d -vvv --version=8.8.1

Install sample services like kube-state-metrics and following service frontend copy.yaml.txt


1st scenario: Testing with Synthetics

Install following standalone-elastic-agent:

elastic-agent-standalone-kubernetes_hints.yml.txt

This is the interesting part for input configuration:

inputs:
      - id: >-
          synthetics/http-synthetics-e241e337-ac4b-4d49-b152-3b94a80d0047-elastic-agent-managed-ep-default
        name: frontend-Kind-default
        revision: 2
        type: synthetics/http
        use_output: default
        meta:
          package:
            name: synthetics
            version: 1.0.1
        data_stream:
          namespace: default
        streams:
          - id: e241e337-ac4b-4d49-b152-3b94a80d0047
            name: frontend
            type: http
            enabled: true
            data_stream:
              dataset: http
              type: synthetics
              elasticsearch:
                privileges:
                  indices:
                    - auto_configure
                    - create_doc
                    - read
            response.include_body: on_error
            origin: ui
            processors:
              - add_fields:
                  fields:
                    config_id: e241e337-ac4b-4d49-b152-3b94a80d0047
                    monitor.fleet_managed: true
                  target: ''
            max_redirects: 0
            response.include_body_max_bytes: 1024
            timeout: 16s
            mode: any
            schedule: '@every 3m'
            urls: 10.96.145.79
            ipv4: true
            ipv6: true
            __ui:
              is_tls_enabled: false
            run_from.id: elastic-agent-managed-ep
            response.include_headers: true
            run_from.geo.name: Kind
            check.request.method: GET

Below services are found under/uptime:

Screenshot 2023-07-13 at 5 16 01 PM


2nd scenario: Testing with Synthetics and autodiscovery We will enable the kubernetes service discovery in kubernetes provider.

Install following standalone manifest: elastic-agent-standalone-kubernetes_hints_service.yml.txt

Then for following cluster:

k get services -A
NAMESPACE     NAME                 TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)                  AGE
default       kubernetes           ClusterIP      10.96.0.1       <none>        443/TCP                  7h22m
frontend      frontend             ClusterIP      10.96.145.79    <none>        80/TCP                   101m
frontend      frontend-external    LoadBalancer   10.96.252.237   <pending>     80:31728/TCP             101m
kube-system   kube-dns             ClusterIP      10.96.0.10      <none>        53/UDP,53/TCP,9153/TCP   7h22m
kube-system   kube-state-metrics   ClusterIP      None            <none>        8080/TCP,8081/TCP        4h46m

You can see that annotations, service.name and service.uid work successfully Screenshot 2023-07-13 at 6 17 45 PM

So missing information is to see how we can pass are:

ChrsMark commented 11 months ago

Hey @gizas ! service.url and service.port would need to be populated by the Metadata Generator at https://github.com/elastic/elastic-agent-autodiscover/blob/main/kubernetes/metadata/service.go.

Please have a look at https://github.com/elastic/elastic-agent-autodiscover/blob/main/kubernetes/metadata/service_test.go#L69-L82 to check that we don't emit this information.