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

[fbreceivier] inject log level #42798

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

Conversation

VihasMakwana
Copy link
Contributor

@VihasMakwana VihasMakwana commented Feb 20, 2025

This PR maps logging.level from beats to service::telemetry::logs::level, so that the log level is respected across config translation

Screenshots:

  1. logging with warning level
config.yaml
filebeat.inputs:
  - type: filestream
    id: filestream-input-id
    enabled: true
    paths:
      - /Users/vihasmakwana/Desktop/Vihas/elastic/beats/x-pack/filebeat/logs/*.log

output:
  elasticsearch:
    hosts: ["https://localhost:9200"]
    username: elastic
    password: changeme

logging.level: warning
Screenshot 2025-03-04 at 12 26 07 PM 2. logging with debug level
config.yaml
filebeat.inputs:
  - type: filestream
    id: filestream-input-id
    enabled: true
    paths:
      - /Users/vihasmakwana/Desktop/Vihas/elastic/beats/x-pack/filebeat/logs/*.log

output:
  elasticsearch:
    hosts: ["https://localhost:9200"]
    username: elastic
    password: changeme

logging.level: debug
Screenshot 2025-03-04 at 12 26 29 PM

Closes https://github.com/elastic/ingest-dev/issues/5030

@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Feb 20, 2025
Copy link
Contributor

mergify bot commented Feb 20, 2025

This pull request does not have a backport label.
If this is a bug or security fix, could you label this PR @VihasMakwana? 🙏.
For such, you'll need to label your PR with:

  • The upcoming major version of the Elastic Stack
  • The upcoming minor version of the Elastic Stack (if you're not pushing a breaking change)

To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-8./d is the label to automatically backport to the 8./d branch. /d is the digit
  • backport-active-all is the label that automatically backports to all active branches.
  • backport-active-8 is the label that automatically backports to all active minor branches for the 8 major.
  • backport-active-9 is the label that automatically backports to all active minor branches for the 9 major.

@VihasMakwana VihasMakwana changed the title inject log level [fbreceivier] inject log level Mar 3, 2025
@VihasMakwana VihasMakwana marked this pull request as ready for review March 3, 2025 14:12
@VihasMakwana VihasMakwana requested a review from a team as a code owner March 3, 2025 14:12
@VihasMakwana VihasMakwana added the Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team label Mar 3, 2025
@elasticmachine
Copy link
Collaborator

Pinging @elastic/elastic-agent-data-plane (Team:Elastic-Agent-Data-Plane)

@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Mar 3, 2025
@@ -72,7 +72,11 @@ func (fmp *provider) Retrieve(_ context.Context, uri string, _ confmap.WatcherFu
},
},
}

// inject log level
Copy link
Contributor

Choose a reason for hiding this comment

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

can you move this to beatconverter.go? Since this is common for all beats

// inject log level
level, _ := cfg.String("logs.level", -1)
if level != "" {
cfgMap["service::telemetry::logs::level"] = level
Copy link
Contributor

Choose a reason for hiding this comment

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

you may want to map beats' logging level to otel level first.

For example. logging.level supports values such as warning which should translate to WARN level on otel.

For ref:
https://www.elastic.co/guide/en/beats/filebeat/current/configuration-logging.html#level
https://opentelemetry.io/docs/collector/internal-telemetry/#configure-internal-logs

Copy link
Member

@AndersonQ AndersonQ left a comment

Choose a reason for hiding this comment

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

as Khushi said, please add a translation instead of just copying it to the OTel config.

@VihasMakwana
Copy link
Contributor Author

@AndersonQ can you please re-review?

@VihasMakwana
Copy link
Contributor Author

/test

Copy link
Member

@AndersonQ AndersonQ left a comment

Choose a reason for hiding this comment

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

[Blocker]
Shouldn't it reject a wrong log level just as the beats already do?
getOTeLLogLevel could return an error if the level is invalid.

If I run this code with an invalid log level, it'll error and exit, but not because it's handled here, but because it's handled somewhere else.

config:

filebeat.inputs:
  - type: filestream
    id: filestream-input-id
    enabled: true
    paths:
      - /home/ainsoph/tmp/log.log

output:
  elasticsearch:
    hosts: [ "https://localhost:9200" ]
    username: elastic
    password: changeme
    ssl.verification_mode: none

logging.level: pastel

running it:

❯ go run . otel -c filebeat-otel.yml
2025-03-04T16:24:03.466+0100	info	service@v0.114.0/service.go:166	Setting up own telemetry...
2025-03-04T16:24:03.467+0100	info	telemetry/metrics.go:70	Serving metrics	{"address": "localhost:8888", "metrics level": "Normal"}
2025-03-04T16:24:03.467+0100	warn	elasticsearchexporter@v0.114.0/config.go:378	dedot has been deprecated: in the future, dedotting will always be performed in ECS mode only	{"kind": "exporter", "data_type": "logs", "name": "elasticsearch"}
Error: failed to build pipelines: failed to create "filebeatreceiver" receiver for data type "logs": error creating filebeatreceiver: error unpacking beats logging config: invalid level 'pastel' accessing 'logging.level'
&{{{0xc00207c600} logging} <nil> 0xc00239c020}
Usage:
  filebeat otel [flags]

it fails on another place:

Error: failed to build pipelines: failed to create "filebeatreceiver" receiver for data type "logs": error creating filebeatreceiver: error unpacking beats logging config: invalid level 'pastel' accessing 'logging.level'

last but not least, could you add a test as well?

@@ -111,6 +111,12 @@ func (c converter) Convert(_ context.Context, conf *confmap.Conf) error {
beatReceiverConfigKey + "::output::otelconsumer": nil,
}

// inject log level
level, _ := config.MustNewConfigFrom(receiverCfg.ToStringMap()).String("logging.level", -1)
Copy link
Member

Choose a reason for hiding this comment

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

[Blocker]
Please, don't panic.
use the right method and handle the error gracefully

Suggested change
level, _ := config.MustNewConfigFrom(receiverCfg.ToStringMap()).String("logging.level", -1)
cfg, err := config.NewConfigFrom(receiverCfg.ToStringMap())
if err!=nil{
return fmt.Errorf("proper error message: %w", err)
}
level, err:=cfg.String("logging.level", -1)
if err!=nil{
return fmt.Errorf("proper error message: %w", err)
}```

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we should be good now.

Co-authored-by: Anderson Queiroz <me@andersonq.me>
@VihasMakwana VihasMakwana requested a review from AndersonQ March 4, 2025 15:55
@VihasMakwana
Copy link
Contributor Author

@AndersonQ @khushijain21 please take a look when you can:

  1. Test case added
  2. We don't panic anymore
  3. We return error if an unknown log level has been specified

@@ -279,6 +280,75 @@ service:

})

// t.Run("test log level",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// t.Run("test log level",

@khushijain21
Copy link
Contributor

LGTM

@VihasMakwana
Copy link
Contributor Author

/test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants