Skip to content

Traefik 2.x access-log support #9131

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

Merged
merged 22 commits into from
Jun 11, 2024

Conversation

ltflb-bgdi
Copy link
Contributor

@ltflb-bgdi ltflb-bgdi commented Feb 12, 2024

Proposed commit message

Traefik-access-log integration was done with traefik v1.6 which went EOL 2018. Since traefik 2.x the (json) log format changed.
Thus using the existing traefik integration is not working properly. As well, only few fields are parsed and some important ones are missing.

For this reason I have done the following improvements:

  • Refactored field structure according to traefik 2.x format (json)
  • Parsed more fields
  • Improved ecs compatibility

Checklist

  • I have reviewed tips for building integrations and this pull request is aligned with them.
  • I have verified that all data streams collect metrics or logs.
  • I have added an entry to my package's changelog.yml file.
  • I have verified that Kibana version constraints are current according to guidelines.

Author's Checklist

  • Json log tests are failing due to http headers. These headers are mapped as objects as already done in apm integration. Expected logs correct but elastic-package test fails with missing header field mapping comment. This seems to me like a limitation/bug of the elastic-package tool and should be fixed separately.

How to test this PR locally

elastic-package stack up
cd /packages/traefik
elastic-package test

Related issues

Screenshots

@ltflb-bgdi ltflb-bgdi requested a review from a team as a code owner February 12, 2024 20:35
@ltflb-bgdi ltflb-bgdi marked this pull request as draft February 12, 2024 20:35
@ltflb-bgdi ltflb-bgdi force-pushed the feat-BGDIINF_SB-3114-traefik branch 9 times, most recently from 7d4fd2f to 9da289e Compare February 15, 2024 10:19
@ltflb-bgdi ltflb-bgdi marked this pull request as ready for review February 16, 2024 16:30
@LaZyDK
Copy link
Contributor

LaZyDK commented Feb 22, 2024

I'm looking forward to this one.

@jamiehynds jamiehynds added Integration:traefik Traefik Team:Obs-InfraObs Observability Infrastructure Monitoring team [elastic/obs-infraobs-integrations] labels Feb 28, 2024
@jamiehynds
Copy link

@SubhrataK can someone from your team please review?

@muthu-mps
Copy link
Contributor

@SubhrataK can someone from your team please review?

Thanks @jamiehynds - We will look into it.

@@ -11,7 +11,7 @@
],
"created": "2020-04-28T11:07:58.223Z",
"duration": 2000000,
"ingested": "2023-10-15T20:29:57.434126924Z",
"ingested": "2024-02-14T16:03:17.172004634Z",
"kind": "event",
"original": "192.168.33.1 - - [02/Oct/2017:20:22:07 +0000] \"GET /ui/favicons/favicon-16x16.png HTTP/1.1\" 304 0 \"http://example.com/login\" \"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36\" 262 \"Host-host-1\" \"http://172.19.0.3:5601\" 2ms",
Copy link
Contributor

Choose a reason for hiding this comment

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

Please mask the sensitive information such like IPs, domain name etc. These sensitive information shouldn't be shipped in package. please check the same for other places as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -1,3 +1,8 @@
- version: "2.0.0"
changes:
- description: Support traefik v2.x access-logs
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor nit: Please end the description with "." (fullstop)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done for all descriptions

@@ -3,4 +3,6 @@ variants:
SERVICE_VERSION: 1.6
"v1.7":
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: If we are keeping 1.7 version in variants then can we also update the Compatibility section by saying that "The Traefik datasets were tested with Traefik 1.6, 1.7 and 2.9" after testing?

},
"service": {
"url": {
"original": "http://172.19.0.3:5601"
Copy link
Contributor

Choose a reason for hiding this comment

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

Based on the description of the field and logs pattern it seems it should be mapped with ECS field called service.address.

- set:
field: observer.type
value: proxy

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 add the null remover script? As null value shouldn't be ingested. For reference : https://github.com/elastic/integrations/blob/main/packages/apache/data_stream/access/elasticsearch/ingest_pipeline/default.yml#L171-L194

@@ -1,7 +1,7 @@
{
"expected": [
{
"@timestamp": "2021-03-16T18:56:54Z",
"@timestamp": "2021-03-16T18:56:54.735539596Z",
"ecs": {
Copy link
Contributor

Choose a reason for hiding this comment

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

We have updated the ECS version from 8.5.1 to 8.11.0 in dependancy hence please update this to 8.11.0 as well by setting up the processor in pipeline. For reference: https://github.com/elastic/integrations/blob/main/packages/apache/data_stream/access/elasticsearch/ingest_pipeline/default.yml#L10C2-L12C21

@muthu-mps
Copy link
Contributor

/test

@muthu-mps
Copy link
Contributor

@ltflb-bgdi,

  • The docs/README.md file should be generated. Perform the changes to README file in the _dev/build/docs folder and run the elastic-package build command to update the docs/README.md file.
  • Build fails for this reason
    Error: checking package failed: checking readme files are up-to-date failed: files do not match

@ltflb-bgdi
Copy link
Contributor Author

@ltflb-bgdi,

  • The docs/README.md file should be generated. Perform the changes to README file in the _dev/build/docs folder and run the elastic-package build command to update the docs/README.md file.
  • Build fails for this reason
    Error: checking package failed: checking readme files are up-to-date failed: files do not match

Done

@muthu-mps
Copy link
Contributor

/test

@muthu-mps
Copy link
Contributor

We need to look into the changes required in the metrics for the new version. Primarily we need to look at how to collect the metrics with the newer version with multiple options provided. Let me comeback to you on this.

As a passive observer on this that is interested in using the logging data stream, perhaps there is an option to merge the logging change separately from health/metric changes.

@andrewkroh - My only concern is what happens if the log is pulled from the newer version and the metrics rely on the older version. Let is evaluate this scenario if nothing breaks then we should be good to merge this PR. Please add your thoughts around this.

@milan-elastic - Can we validate this PR changes by updating the integrations from the Traefik 1.x version to the 2.x version.

@andrewkroh
Copy link
Member

My only concern is what happens if the log is pulled from the newer version and the metrics rely on the older version

That's true. The /health data stream won't work. I imaging there isn't anyone using Traefik 1.x anymore. It entered end-of-support1 close to 2.5 years ago (with no security updates) and now 3.x is out. I would take the stance that this integration should no longer try to support 1.x and it drops support for it by removing the heath data stream and incrementing the packages major version.

Traefik has several ways of getting rich metrics from it like prometheus, otel, and statd. (Personally I pull from the prometheus endpoint). You could plan a new metrics data stream that pulls from prometheus/statds or perhaps could document that metrics can be sent to the APM server's OTLP listener2.

Footnotes

  1. https://doc.traefik.io/traefik/deprecation/releases/

  2. https://www.elastic.co/guide/en/observability/current/apm-open-telemetry.html

@muthu-mps
Copy link
Contributor

My only concern is what happens if the log is pulled from the newer version and the metrics rely on the older version

That's true. The /health data stream won't work. I imaging there isn't anyone using Traefik 1.x anymore. It entered end-of-support1 close to 2.5 years ago (with no security updates) and now 3.x is out. I would take the stance that this integration should no longer try to support 1.x and it drops support for it by removing the heath data stream and incrementing the packages major version.

Traefik has several ways of getting rich metrics from it like prometheus, otel, and statd. (Personally I pull from the prometheus endpoint). You could plan a new metrics data stream that pulls from prometheus/statds or perhaps could document that metrics can be sent to the APM server's OTLP listener2.

Footnotes

  1. https://doc.traefik.io/traefik/deprecation/releases/
  2. https://www.elastic.co/guide/en/observability/current/apm-open-telemetry.html

Thanks Andrew! Valid point. Since the native support for processing metrics is already unavailable we can deprecate the current data stream and add a new data stream for processing the metrics. Let me create an issue.

@milan-elastic
Copy link
Contributor

@milan-elastic - Can we validate this PR changes by updating the integrations from the Traefik 1.x version to the 2.x version.

Findings

As per @muthu-mps comment I have tested out Traefik upgrade scenario from 1.x to 2.x. Here are the scenarios tested

  • Verified that the Traefix 1.x format logs are still parsed by the pipeline in the Traefik integration version 2.0.0
  • Verified that the Traefix 2.x format logs are still parsed by the pipeline in the Traefik integration version 2.0.0
    • I did find some fields that are no longer supported in Traefik integration version 2.0.0 like traefik.access.backend_url and traefik.access.frontend_name . These fields are now renamed to traefik.access.service.address and traefik.access.router.name respectively.
  • Verified that there are no errors or conflicts while the integration is upgraded to 2.0.0 version
  • Verified by loading the dashboards and visualizations after upgrading the integration to the 2.x major release and checked that there are no errors in it.

Major issue

I understand that we are saying the user to upgrade to the newer versions of Traefik but this would lead to breaking the health data stream as the /health endpoint is no longer accessible just as Andrew said. Tried accessing the endpoint on Traefik 1.7 initially and there it was accessible and we are able to fetch the metrics but in Traefik 2.5 this is not working. You can find the setup links here for both the versions

Minor nits

Need to update the sample_event.json as I can see some of the empty fields in it. We have already included the null script, so we should once generate the sample_event to check if it is working

@muthu-mps
Copy link
Contributor

As we plan to release the log stream in this iteration and the metrics stream in the next iteration. We need to update the integration with the below mentioned changes.

Steps

  1. Remove the metrics data stream from the policy template. Ensures that we are not adding unsupported data stream.
  2. Update the documentation to have a mention that the integrations supports log collection with the Traefik supported versions and the support for metrics collection will be added.
  3. Documentation should remove the metric data stream references.
  4. The current dashboard supports only the logs. Verify the data is loading properly for logs after making the above changes.

@ltflb-bgdi - Please let us know, If you need any help in making the above changes. If you are okay, we can perform the changes to the PR.

@ltflb-bgdi
Copy link
Contributor Author

  • Update the documentation to have a mention that the integrations supports log collection with the Traefik supported versions and the support for metrics collection will be added.
  • Documentation should remove the metric data stream references.

@muthu-mps Feel free to implement your proposed changes. If you want me to do it, let me know.

@muthu-mps
Copy link
Contributor

  • Update the documentation to have a mention that the integrations supports log collection with the Traefik supported versions and the support for metrics collection will be added.
  • Documentation should remove the metric data stream references.

@muthu-mps Feel free to implement your proposed changes. If you want me to do it, let me know.

Thanks @ltflb-bgdi!

@milan-elastic - Please make the above suggested changes to this PR. Let me know if you have any questions.

@milan-elastic
Copy link
Contributor

@ltflb-bgdi can you please provide me an access to your project so I can write into your branch?
cc: @muthu-mps

@ltflb-bgdi
Copy link
Contributor Author

@ltflb-bgdi can you please provide me an access to your project so I can write into your branch? cc: @muthu-mps

Done

@muthu-mps
Copy link
Contributor

/test

@muthu-mps
Copy link
Contributor

/test

@muthu-mps
Copy link
Contributor

/test

@elasticmachine
Copy link

💚 Build Succeeded

History

Copy link

Copy link
Contributor

@milan-elastic milan-elastic left a comment

Choose a reason for hiding this comment

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

LGTM!

@muthu-mps
Copy link
Contributor

@andrewkroh - We have updated the policy template to drop support for metrics input and the support for metrics will get revamped and added in the next iterations. The documentation is also updated.
Do you have any final thoughts before merging the PR?

Copy link
Member

@andrewkroh andrewkroh left a comment

Choose a reason for hiding this comment

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

🚢

@ltflb-bgdi
Copy link
Contributor Author

Please let me know by when we can expect the last approval and merge. Thanks.

Copy link
Contributor

@muthu-mps muthu-mps left a comment

Choose a reason for hiding this comment

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

LGTM!

@muthu-mps muthu-mps merged commit 7a68798 into elastic:main Jun 11, 2024
@muthu-mps muthu-mps deleted the feat-BGDIINF_SB-3114-traefik branch June 11, 2024 10:51
@elasticmachine
Copy link

Package traefik - 2.0.0 containing this change is available at https://epr.elastic.co/search?package=traefik

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Integration:traefik Traefik Team:Obs-InfraObs Observability Infrastructure Monitoring team [elastic/obs-infraobs-integrations]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants