Skip to content

change elasticsearch configuration DecodeHook function to handle string to []string#11732

Merged
leehinman merged 6 commits intoelastic:mainfrom
leehinman:11352_ssl_certificate_authorities
Dec 15, 2025
Merged

change elasticsearch configuration DecodeHook function to handle string to []string#11732
leehinman merged 6 commits intoelastic:mainfrom
leehinman:11352_ssl_certificate_authorities

Conversation

@leehinman
Copy link
Contributor

@leehinman leehinman commented Dec 10, 2025

What does this PR do?

Change elasticsearch configuration DecodeHook function to convert a single string to a slice of string with one value if the destination type is a slice of string.

Why is it important?

Beats configs allow for single values when the type is an slice. For example ssl.certificate_authorities is a slice of strings, but beat configuration allows for these to be a string instead of a slice with one entry.

Checklist

  • I have read and understood the pull request guidelines of this project.
  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in ./changelog/fragments using the changelog tool
  • I have added an integration test or an E2E test

Disruptive User Impact

How to test this PR locally

cd internal/pkg/otel/translate
go test .

Related issues

Questions to ask yourself

  • How are we going to support this in production?
  • How are we going to measure its adoption?
  • How are we going to debug this?
  • What are the metrics I should take care of?
  • ...
@mergify
Copy link
Contributor

mergify bot commented Dec 10, 2025

This pull request does not have a backport label. Could you fix it @leehinman? 🙏
To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-./d./d is the label that automatically backports 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.
@leehinman leehinman added bug Something isn't working backport-8.x Automated backport to the 8.x branch with mergify backport-9.1 Automated backport to the 9.1 branch backport-9.2 Automated backport to the 9.2 branch labels Dec 10, 2025
@leehinman leehinman force-pushed the 11352_ssl_certificate_authorities branch from b0ddd05 to a84bb87 Compare December 10, 2025 20:19
@leehinman leehinman marked this pull request as ready for review December 10, 2025 20:53
@leehinman leehinman requested a review from a team as a code owner December 10, 2025 20:53
@cmacknz cmacknz requested a review from swiatekm December 10, 2025 21:34
Copy link
Contributor

@ycombinator ycombinator left a comment

Choose a reason for hiding this comment

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

While this change would work, it seems the only effect we're interested in is:

single values are converted to slices if required. Each element is weakly decoded. For example: "4" can become []int{4} if the target type is an int slice.

Since we're already defining a DecodeHook function, cfgDecodeHookFunc, would it be possible to use this function to convert T values into []T values if the target type is []T? That might be preferable/safer if we don't want or expect the rest of the implications of using WeaklyTypedInput?

@leehinman
Copy link
Contributor Author

Since we're already defining a DecodeHook function, cfgDecodeHookFunc, would it be possible to use this function to convert T values into []T values if the target type is []T? That might be preferable/safer if we don't want or expect the rest of the implications of using WeaklyTypedInput?

I was waffling on this myself. I leaned towards the WeaklyTypedInput because beats config is so permissive, but since it set off your Spidey Senses too, l'll switch to the more targeted approach. If we hit more of these we can re-evaluate.

@leehinman leehinman changed the title use WeaklyTypedInput for decoding elasticsearch config Dec 10, 2025
@leehinman leehinman force-pushed the 11352_ssl_certificate_authorities branch from 8d1a9ce to d541e9e Compare December 10, 2025 23:13
ycombinator
ycombinator previously approved these changes Dec 11, 2025
@pierrehilbert pierrehilbert added the Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team label Dec 11, 2025
@elasticmachine
Copy link
Contributor

Pinging @elastic/elastic-agent-control-plane (Team:Elastic-Agent-Control-Plane)

@pierrehilbert pierrehilbert added backport-8.19 Automated backport to the 8.19 branch and removed backport-8.x Automated backport to the 8.x branch with mergify labels Dec 11, 2025
Copy link
Contributor

@ycombinator ycombinator left a comment

Choose a reason for hiding this comment

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

LGTM once the linter failures are addressed.

@elasticmachine
Copy link
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

History

cc @leehinman

@leehinman leehinman merged commit 1967909 into elastic:main Dec 15, 2025
23 checks passed
mergify bot pushed a commit that referenced this pull request Dec 15, 2025
…ng to []string (#11732)

handle type to []type mismatch for

- string
- cipher suite
- tls version

in elasticsearch output translation

(cherry picked from commit 1967909)

# Conflicts:
#	internal/pkg/otel/translate/output_elasticsearch.go
#	internal/pkg/otel/translate/output_elasticsearch_test.go
mergify bot pushed a commit that referenced this pull request Dec 15, 2025
…ng to []string (#11732)

handle type to []type mismatch for

- string
- cipher suite
- tls version

in elasticsearch output translation

(cherry picked from commit 1967909)
mergify bot pushed a commit that referenced this pull request Dec 15, 2025
…ng to []string (#11732)

handle type to []type mismatch for

- string
- cipher suite
- tls version

in elasticsearch output translation

(cherry picked from commit 1967909)
leehinman added a commit that referenced this pull request Dec 15, 2025
…ng to []string (#11732) (#11820)

handle type to []type mismatch for

- string
- cipher suite
- tls version

in elasticsearch output translation

(cherry picked from commit 1967909)

Co-authored-by: Lee E Hinman <57081003+leehinman@users.noreply.github.com>
pierrehilbert pushed a commit that referenced this pull request Dec 16, 2025
…ng to []string (#11732) (#11819)

handle type to []type mismatch for

- string
- cipher suite
- tls version

in elasticsearch output translation

(cherry picked from commit 1967909)

Co-authored-by: Lee E Hinman <57081003+leehinman@users.noreply.github.com>
leehinman added a commit that referenced this pull request Dec 16, 2025
… function to handle string to []string (#11818)

* change elasticsearch configuration DecodeHook function to handle string to []string (#11732)

handle type to []type mismatch for

- string
- cipher suite
- tls version

in elasticsearch output translation

(cherry picked from commit 1967909)

# Conflicts:
#	internal/pkg/otel/translate/output_elasticsearch.go
#	internal/pkg/otel/translate/output_elasticsearch_test.go

* fix merge conflict

* fix unit tests

---------

Co-authored-by: Lee E Hinman <57081003+leehinman@users.noreply.github.com>
Co-authored-by: Lee E. Hinman <lee.e.hinman@elastic.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-8.19 Automated backport to the 8.19 branch backport-9.1 Automated backport to the 9.1 branch backport-9.2 Automated backport to the 9.2 branch bug Something isn't working Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team

6 participants