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

add EntityState entity event as log record for host #33927

Open
povilasv opened this issue Jul 5, 2024 · 5 comments
Open

add EntityState entity event as log record for host #33927

povilasv opened this issue Jul 5, 2024 · 5 comments
Labels
enhancement New feature or request needs triage New item requiring triage receiver/hostmetrics

Comments

@povilasv
Copy link
Contributor

povilasv commented Jul 5, 2024

Component(s)

receiver/hostmetrics

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

I would like to add EntityState Entity event, similar to what we have in k8s_cluster receiver, when is configured as log consumer. We would send a event on startup and also periodically if metadata_collection_interval is configured.

This event would be empty, so that resourcedetection processor would fill in the details. Initially transform processor would be also needed to fit the Entity model.

Example pipeline:

    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

Example event we would produce:

{
  "logRecord": {
    "attributes": {
      "otel.entity.attributes": {
        "host.name": "kind-control-plane",
        "otel.entity.id": {
          "host.id": "bf57b58e587d4115a373ba1199bf4b70"
        }
      },
      "otel.entity.event.type": "entity_state",
      "otel.entity.type": "host"
    },
    "timeUnixNano": 1720168109538054222
  },
  "resource": {
    "attributes": {}
  },
  "resourceSchemaUrl": "https://opentelemetry.io/schemas/1.6.1",
  "scope": {
    "attributes": {
      "otel.entity.event_as_log": true
    }
  }
}

Example k8s_cluster_receiver entity event:

{
   "logRecord":{
      "attributes":{
         "otel.entity.attributes":{
            "app.kubernetes.io/instance":"otel-coralogix-integration",
            "app.kubernetes.io/managed-by":"Helm",
            "app.kubernetes.io/name":"opentelemetry-agent",
            "app.kubernetes.io/version":"0.104.0",
            "daemonset.creation_timestamp":"2024-07-05T07:43:47Z",
            "helm.sh/chart":"opentelemetry-agent-0.87.0",
            "k8s.workload.kind":"DaemonSet",
            "k8s.workload.name":"coralogix-opentelemetry-agent"
         },
         "otel.entity.event.type":"entity_state",
         "otel.entity.id":{
            "k8s.daemonset.uid":"9280b46e-8e45-4f5b-80dd-f078c4ca3d57"
         },
         "otel.entity.type":"k8s.daemonset"
      },
      "timeUnixNano":1720167199952089629
   },
   "scope":{
      "attributes":{
         "otel.entity.event_as_log":true
      }
   }
}

Describe the solution you'd like

Describe alternatives you've considered

No response

Additional context

No response

@povilasv povilasv added enhancement New feature or request needs triage New item requiring triage labels Jul 5, 2024
@povilasv povilasv changed the title add EntityState entity event as log for host add EntityState entity event as log record for host Jul 5, 2024
Copy link
Contributor

github-actions bot commented Jul 5, 2024

Pinging code owners:

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

@povilasv
Copy link
Contributor Author

povilasv commented Jul 5, 2024

Would appreciate @tigrannajaryan review, given you did all the work around Entity events.

@tigrannajaryan
Copy link
Member

+1 for producing EntityState for the Host. This is our (Entity SIG) intent in the future, Host will be one of the entities we would like to report. As long as this is marked "alpha" since we are not yet certain about what Id and Attributes the host should include.

The event's shape looks slightly wrong to me. The "otel.entity.id" should not be contained in "otel.entity.attributes". I think this is what would be expected:

{
  "logRecord": {
    "attributes": {
      "otel.entity.attributes": {
        "host.name": "kind-control-plane",
      },
      "otel.entity.id": {
        "host.id": "bf57b58e587d4115a373ba1199bf4b70"
      }
      "otel.entity.event.type": "entity_state",
      "otel.entity.type": "host"
    },
    "timeUnixNano": 1720168109538054222
  },
  ...
}

To make this work nicely the resourcedetection processor likely needs to be reworked to gain understanding of entities so that it can put the right attributes in the "otel.entity.id".

I have a draft of what it can possibly look like in this prototype: tigrannajaryan#1

@povilasv
Copy link
Contributor Author

povilasv commented Jul 8, 2024

Thanks for the info @tigrannajaryan, so basically for now something like this can be used:

      transform/entity-event:
        log_statements:
          - context: log
            statements:
              - set(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, [""])

I put the logs in "development" stability in this #33928, would apprecaite if you could take a look / comment 🙇

I would like to do it in stages, first add capability in hostmetrics receiver, next understand and add the needed changes in resourcedetection processor.

What do you think?

@tigrannajaryan
Copy link
Member

I would like to do it in stages, first add capability in hostmetrics receiver, next understand and add the needed changes in resourcedetection processor.

Sounds good to me. Thanks for working on this.

I just want to emphasize one more time: we are in the very early stages of designing the entities, so we should expect significant changes as we gain better understanding over time. I think it would be also great for you to attend Entities SIG meetings to both be aware of developments and also help us with any feedback you may have as you work on this.

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/hostmetrics
Projects
None yet
Development

No branches or pull requests

2 participants