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/hostmetrics] add EntityState entity event as log record for host #33928

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

povilasv
Copy link
Contributor

@povilasv povilasv commented Jul 5, 2024

Description:

Add EntityState event for host, implementation is similiar to k8sclusterreceiver. This change sends empty event, which can be used together with resourcedetection processor to add required attributes:

    receivers:
      hostmetrics:
        enabled: true
        metadata_collection_interval: "5m"

    processors:
      resourcedetection/env:
        detectors: ["system", "env"]
        timeout: 2s
        override: false
        system:
          resource_attributes:
            host.id:
              enabled: true
      resourcedetection/region:
        detectors: ["gcp", "ec2", "azure"]
        timeout: 2s
        override: true
      transform/entity-event:
        log_statements:
          - context: log
            statements:
              - set(attributes["otel.entity.attributes"]["otel.entity.id"]["host.id"], resource.attributes["host.id"])
              - set(attributes["otel.entity.attributes"]["host.name"], resource.attributes["host.name"])
              - set(attributes["otel.entity.attributes"]["host.type"], resource.attributes["host.type"])
              - set(attributes["otel.entity.attributes"]["host.image.id"], resource.attributes["host.image.id"])
              - set(attributes["otel.entity.attributes"]["host.image.name"], resource.attributes["host.image.name"])
          - context: resource
            statements:
              - keep_keys(attributes, [""])
    service:
      pipelines:
        logs/entity:
          exporters:
            - otlp
          processors:
            - k8sattributes
            - resourcedetection/env
            - resourcedetection/region
            - transform/entity-event
          receivers:
            - hostmetrics

Link to tracking Issue:

#33927

Testing:

  • kind cluster
  • unit tests

Documentation:

  • added docs

receiver/hostmetricsreceiver/config.go Outdated Show resolved Hide resolved
receiver/hostmetricsreceiver/config.go Show resolved Hide resolved
func (hmr *hostMetricsReceiver) sendEntityEvent(ctx context.Context) {
timestamp := pcommon.NewTimestampFromTime(time.Now())

out := metadataPkg.NewEntityEventsSlice()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a follow up PR we should add "Interval" as a field to the Entity events and use MetadataCollectionInterval as the value. The "Interval" was proposed after the initial design and is now in the OTEP.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree :)

@povilasv povilasv force-pushed the entity-event branch 3 times, most recently from 9e6bcfd to ccd0e9a Compare July 9, 2024 15:00
@povilasv
Copy link
Contributor Author

povilasv commented Jul 9, 2024

FYI: unit test failures seem unrelated:

=== FAIL: . TestConnectorConsume/test_fix_failed_label_not_work (re-run 1) (0.01s)
    logger.go:146: 2024-07-09T19:49:27.049Z	INFO	Started servicegraphconnector
    logger.go:146: 2024-07-09T19:49:27.050Z	INFO	Shutting down servicegraphconnector
    logger.go:146: 2024-07-09T19:49:27.052Z	DEBUG	edge completed	{"client_service": "foo", "server_service": "bar", "connection_type": "", "trace_id": "b3a53e9c2ac533afc48b511c2f368dc1"}
    logger.go:146: 2024-07-09T19:49:27.052Z	DEBUG	edge completed	{"client_service": "foo", "server_service": "bar", "connection_type": "", "trace_id": "c6aafb2dcf4d71c81ae52e50e8f805ee"}
    logger.go:146: 2024-07-09T19:49:27.053Z	DEBUG	edge completed	{"client_service": "foo", "server_service": "bar", "connection_type": "", "trace_id": "7af657de319d6a57967bc241882ea94f"}
    connector_test.go:129: 
        	Error Trace:	/home/runner/work/opentelemetry-collector-contrib/opentelemetry-collector-contrib/connector/servicegraphconnector/connector_test.go:129
        	Error:      	Received unexpected error:
        	            	the following errors occurred:
        	            	 -  resource "map[]": scope "traces_service_graph": metric "traces_service_graph_request_total": missing expected datapoint: map[client:foo connection_type: failed:false server:bar]
        	            	 -  resource "map[]": scope "traces_service_graph": metric "traces_service_graph_request_total": unexpected datapoint: map[client:foo connection_type: failed:true server:bar]
        	            	 -  resource "map[]": scope "traces_service_graph": metric "traces_service_graph_request_total": missing expected datapoint: map[client:foo connection_type: failed:true server:bar]
        	            	 -  resource "map[]": scope "traces_service_graph": metric "traces_service_graph_request_total": unexpected datapoint: map[client:foo connection_type: failed:false server:bar]
        	Test:       	TestConnectorConsume/test_fix_failed_label_not_work

=== FAIL: . TestConnectorConsume (re-run 1) (0.01s)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants