Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[receiver/receivercreator] Support for probing K8s services #29021

Closed
a-thaler opened this issue Nov 8, 2023 · 7 comments
Closed

[receiver/receivercreator] Support for probing K8s services #29021

a-thaler opened this issue Nov 8, 2023 · 7 comments
Assignees
Labels
enhancement New feature or request needs triage New item requiring triage receiver/receivercreator

Comments

@a-thaler
Copy link
Contributor

a-thaler commented Nov 8, 2023

Component(s)

receiver/receivercreator
extension/observer

Is your feature request related to a problem? Please describe.

I used the typical setup of blackbox-exporter and prometheus to probe the availability of k8s services and make the results available as metrics. Hereby, the discovery of services by prometheus annotations is an elegant approach.

With the availability of the httpcheck receiver the setup can be turned into an otel-collector based setup. However, the configuration is static and does not support any discovery capabilities.

The receivercreator reciever seems the perfect match for that scenario by configuring the httpcheck dynamically dependent on the discovered service endpoints.

Describe the solution you'd like

Add support to the k8s_observer to watch k8s services, so that a new rule type k8s.service is available in the receivercreator reciever which allows the dynamic configuration of the httpcheck receiver.

An example configuration might look like this:

  extensions:
    k8s_observer:
      observe_nodes: false
      observe_pods: false
      observe_services: true

  receivers:
    receiver_creator:
      watch_observers: [k8s_observer]
      receivers:
        httpcheck:
          rule: type == "k8s.service" && annotations["prometheus.io/probe"] == "true"
          config:
            targets:
              - endpoint: 'http://`endpoint`:9090/health'
                method: 'GET'
            collection_interval: 10s

  exporters:
    debug:
      verbosity: detailed

  service:
    extensions:
      - k8s_observer
    pipelines:
      metrics:
        receivers:
        - receiver_creator
        exporters:
        - debug

A more advanced config could look like this:

  receivers:
    receiver_creator:
      watch_observers: [k8s_observer]
      receivers:
        httpcheck:
          rule: type == "k8s.service" && annotations["prometheus.io/probe"] == "true"
          config:
            targets:
              - endpoint: '`"prometheus.io/scheme" in annotations ? annotations["prometheus.io/scheme"] : http`://`endpoint`:`"prometheus.io/port" in annotations ? annotations["prometheus.io/port"] : 9090``"prometheus.io/path" in annotations ? annotations["prometheus.io/path"] : "/health"`'
                method: '`"prometheus.io/method" in annotations ? annotations["prometheus.io/method"] : GET`'
            collection_interval: '`pod.annotations["collection_interval"]`'

Describe alternatives you've considered

As the httpcheck receiver does not support any discovery, the only alternative is to stick to the blackbox-exporter and use the prometheusreceiver with a target_allocator instead which is way more complex and requires the blackbox-exporter.

Additional context

No response

@a-thaler a-thaler added enhancement New feature or request needs triage New item requiring triage labels Nov 8, 2023
Copy link
Contributor

github-actions bot commented Nov 8, 2023

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

@a-thaler
Copy link
Contributor Author

a-thaler commented Nov 8, 2023

I created a first PR for it: #29022
Additional points I see which could be addressed:

Service Port Discovery
Analogue to the pod discovery, also the service ports could be transformed into individual endpoints. Here I'm in doubt if the existing port type should be re-used and just extended with optional service metadata or if a new port type needs to be introduced. Extending the existing type will require to check in the config if a port belongs to a pod or a service. So probably a new type like k8s.service.port should be introduced for that to clearly distinguish the two kind of ports.

Resource Attributes
The PR proposes to add the namespace by default as resource attribute. Unfortunately there is nothing available in the semantic conventions to reflect a k8s service as the source of the data.

Service attributes
In the PR I used the internal DNS name of a service as endpoint. If the user prefers to use the IP, it is available via the cluster_ip attribute. Additional I could extend the PR to also list the external host name in case of a LoadBalancer service, so that an external probing could be done as well. I currently don't se other attributes of interest.

@JaredTan95
Copy link
Member

JaredTan95 commented Nov 8, 2023

@a-thaler Hi, As I kown, blackbox-exporter not only do http probe, but also do tcp, ssh,imap etc. so, you cared about just http probe?

@JaredTan95
Copy link
Member

@a-thaler Hi, As I kown, blackbox-exporter not only do http probe, but also do tcp, ssh,imap etc. so, you cared about just http probe?

refs #29009

@a-thaler
Copy link
Contributor Author

a-thaler commented Nov 8, 2023

Hi @JaredTan95, I currently care about HTTP and like to leverage the httpcheck receiver, but the approach outlined here is agnostic to the protocol as it determines the endpoint only and provides you the service context. It then depends on the actual nested receiver config. So a potential receiver resulting out of the linked feature request should be usable as well.

@JaredTan95
Copy link
Member

but the approach outlined here is agnostic to the protocol as it determines the endpoint only and provides you the service context. It then depends on the actual nested receiver config. So a potential receiver resulting out of the linked feature request should be usable as well.

make sense

djaglowski pushed a commit that referenced this issue Nov 16, 2023
)

**Description:**
- Added a new watch to the k8s_observer extension for k8s services,
which can be enabled using a new flag "observe_services".
- Discovered entities are transformed into a new endpoint type
`k8s.service`.
- Adjusted the receivercreator to support the new type `k8s.service`


**Link to tracking Issue:**
[#29021](#29021)

**Testing:** Added unit tests analogue to the available tests

**Documentation:** Adjusted readme's of k8s_observer and
receivercreator. Added description of new flags and typers.

**Note:**
Current implementation is working as described in the linked ticket.
Please check the potential discussion points mentioned in the ticket:
#29021 (comment)

---------

Co-authored-by: Antoine Toulme <antoine@toulme.name>
@a-thaler
Copy link
Contributor Author

Feature got merged as proposed with #29022. Further improvements will be handled in individual issues.

graphaelli pushed a commit to graphaelli/opentelemetry-collector-contrib that referenced this issue Nov 17, 2023
…n-telemetry#29022)

**Description:**
- Added a new watch to the k8s_observer extension for k8s services,
which can be enabled using a new flag "observe_services".
- Discovered entities are transformed into a new endpoint type
`k8s.service`.
- Adjusted the receivercreator to support the new type `k8s.service`


**Link to tracking Issue:**
[open-telemetry#29021](open-telemetry#29021)

**Testing:** Added unit tests analogue to the available tests

**Documentation:** Adjusted readme's of k8s_observer and
receivercreator. Added description of new flags and typers.

**Note:**
Current implementation is working as described in the linked ticket.
Please check the potential discussion points mentioned in the ticket:
open-telemetry#29021 (comment)

---------

Co-authored-by: Antoine Toulme <antoine@toulme.name>
RoryCrispin pushed a commit to ClickHouse/opentelemetry-collector-contrib that referenced this issue Nov 24, 2023
…n-telemetry#29022)

**Description:**
- Added a new watch to the k8s_observer extension for k8s services,
which can be enabled using a new flag "observe_services".
- Discovered entities are transformed into a new endpoint type
`k8s.service`.
- Adjusted the receivercreator to support the new type `k8s.service`


**Link to tracking Issue:**
[open-telemetry#29021](open-telemetry#29021)

**Testing:** Added unit tests analogue to the available tests

**Documentation:** Adjusted readme's of k8s_observer and
receivercreator. Added description of new flags and typers.

**Note:**
Current implementation is working as described in the linked ticket.
Please check the potential discussion points mentioned in the ticket:
open-telemetry#29021 (comment)

---------

Co-authored-by: Antoine Toulme <antoine@toulme.name>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request needs triage New item requiring triage receiver/receivercreator
Projects
None yet
Development

No branches or pull requests

2 participants