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

added translation logic in tcp and udp emf log receivers to attach network attributes for emf logs #1491

Open
wants to merge 3 commits into
base: main-emf-entity
Choose a base branch
from

Conversation

nathalapooja
Copy link
Contributor

Description of the issue

Describe the problem or feature in addition to a link to the issues.
We want the ability to send entities for customers forwarding EMF logs using the EMF forwarding plugin: https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Embedded_Metric_Format_Generation_CloudWatch_Agent.html

To build entity, we should be able to retrieve the EMF log sender IP address.

Description of changes

How does this change address the problem?
TCP and UDP logs receiver has an already built config option add_attributes which adds net.* attributes according to [semantic convention][https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/span-general.md#general-network-connection-attributes]

https://github.com/amazon-contributing/opentelemetry-collector-contrib/tree/aws-cwa-dev/receiver/tcplogreceiver
https://github.com/amazon-contributing/opentelemetry-collector-contrib/tree/aws-cwa-dev/receiver/udplogreceiver

Added translation logic to enable this additional config in TCP and UDP logs receiver translator.

License

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Tests

Describe what tests you have done.
Unit Testing and Manual Testing

Testing details

  1. Agent config
    {
      "logs": {
        "metrics_collected": {
          "emf": { }
        }
      }
    }
  1. Translated yaml config
exporters:
    awscloudwatchlogs/emf_logs:
        certificate_file_path: ""
        emf_only: true
        endpoint: ""
        imds_retries: 1
        local_mode: false
        log_group_name: emf/logs/default
        log_retention: 0
        log_stream_name: cloudwatch-agent-6kzfw
        max_retries: 2
        middleware: agenthealth/logs
        no_verify_ssl: false
        num_workers: 8
        profile: ""
        proxy_address: ""
        raw_log: true
        region: us-east-1
        request_timeout_seconds: 30
        resource_arn: ""
        retry_on_failure:
            enabled: true
            initial_interval: 5s
            max_elapsed_time: 5m0s
            max_interval: 30s
            multiplier: 1.5
            randomization_factor: 0.5
        role_arn: ""
        sending_queue:
            enabled: true
            num_consumers: 1
            queue_size: 1000
extensions:
    agenthealth/logs:
        is_usage_data_enabled: true
        stats:
            operations:
                - PutLogEvents
            usage_flags:
                mode: EKS
                region_type: EC2M
    agenthealth/statuscode:
        is_status_code_enabled: true
        is_usage_data_enabled: true
        stats:
            usage_flags:
                mode: EKS
                region_type: EC2M
    entitystore:
        kubernetes_mode: EKS
        mode: ec2
        region: us-east-1
    server:
        listen_addr: :4311
        tls_ca_path: /etc/amazon-cloudwatch-observability-agent-client-cert/tls-ca.crt
        tls_cert_path: /etc/amazon-cloudwatch-observability-agent-server-cert/server.crt
        tls_key_path: /etc/amazon-cloudwatch-observability-agent-server-cert/server.key
processors:
    awsentity/service/emf:
        cluster_name: compass-ga2
        entity_type: Service
        kubernetes_mode: EKS
        platform: ec2
    batch/emf_logs:
        metadata_cardinality_limit: 1000
        send_batch_max_size: 0
        send_batch_size: 8192
        timeout: 5s
receivers:
    tcplog/emf_logs:
        add_attributes: true
        encoding: utf-8
        id: tcp_input
        listen_address: 0.0.0.0:25888
        operators: []
        retry_on_failure:
            enabled: false
            initial_interval: 0s
            max_elapsed_time: 0s
            max_interval: 0s
        type: tcp_input
    udplog/emf_logs:
        add_attributes: true
        encoding: utf-8
        id: udp_input
        listen_address: 0.0.0.0:25888
        multiline:
            line_end_pattern: .^
            line_start_pattern: ""
            omit_pattern: false
        operators: []
        retry_on_failure:
            enabled: false
            initial_interval: 0s
            max_elapsed_time: 0s
            max_interval: 0s
        type: udp_input
service:
    extensions:
        - agenthealth/logs
        - agenthealth/statuscode
        - entitystore
        - server
    pipelines:
        logs/emf_logs:
            exporters:
                - awscloudwatchlogs/emf_logs
            processors:
                - batch/emf_logs
                - awsentity/service/emf
            receivers:
                - tcplog/emf_logs
                - udplog/emf_logs
    telemetry:
        logs:
            development: false
            disable_caller: false
            disable_stacktrace: false
            encoding: console
            level: info
            sampling:
                enabled: true
                initial: 2
                thereafter: 500
                tick: 10s
        metrics:
            address: ""
            level: None
        traces: {}
  1. Sample EMF log sent to agent port from petclinic pod
echo '{"_aws":{"Timestamp":1736186361000,"LogGroupName":"emf_group_2","LogStreamName":"emf_stream","CloudWatchMetrics":[{"Namespace":"MyApp","Dimensions":[["Operation"]],"Metrics":[{"Name":"ProcessingLatency","Unit":"Milliseconds","StorageResolution":60}]}]},"Operation":"Aggregator","ProcessingLatency":100}' | nc cloudwatch-agent.amazon-cloudwatch 25888
  1. Pet-clinic Pod details
│ Name:  petclinic-pod-k48dh │
│ Namespace:   default │
│ Priority:  0 │
│ Service Account:  default │
│ Node:  ip-192-168-59-192.ec2.internal/192.168.59.192 │
│ Start Time:  Fri, 20 Dec 2024 15:35:13 -0500 │
│ Labels:  app=petclinic-pod │
│  controller-revision-hash=59dd5fb  │
│  pod-template-generation=6 │
│ Annotations:   [instrumentation.opentelemetry.io/inject-java](http://instrumentation.opentelemetry.io/inject-java): true  │
│  [instrumentation.opentelemetry.io/inject-python](http://instrumentation.opentelemetry.io/inject-python): true  │
│  [kubectl.kubernetes.io/restartedAt](http://kubectl.kubernetes.io/restartedAt): 2024-12-20T15:35:07-05:00  │
│ Status:  Running │
│ IP:  192.168.63.234  │
│ IPs:  │
│  IP:  192.168.63.234  
  1. net work logs on agent with ip
2025-01-06T21:49:49Z I! {"caller":"awsentity/processor.go:130","msg":"process scope logs","kind":"processor","name":"awsentity/service/emf","pipeline":"logs/emf_logs","l":{"net.host.ip":"192.168.59.192","net.host.name":"192-168-59-192.cloudwatch-agent.amazon-cloudwatc │
│ h.svc.cluster.local","net.host.port":"25888","net.peer.ip":"192.168.63.234","net.peer.name":"ip-192-168-63-234.ec2.internal","net.peer.port":"35757","net.transport":"IP.TCP"}} 
  1. EMF published to cloudwatch
    Screenshot 2025-01-06 at 4 54 36 PM
    Screenshot 2025-01-06 at 4 54 19 PM

Requirements

Before commit the code, please do the following steps.

  1. Run make fmt and make fmt-sh
  2. Run make lint

@nathalapooja nathalapooja requested a review from a team as a code owner January 8, 2025 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant