Skip to content

[confmap] **Discuss** Identify string field type and set the expanded value accordingly #12860

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dloucasfx
Copy link
Contributor

@dloucasfx dloucasfx commented Apr 15, 2025

Description

Note: This PR is for discussion as I might be missing something obvious in how the type identification works in confmap. If code owner agreed with the Issue identified and the PR is accepted, I will need to push more changes to cleanup unused code.

Issue: #12793

If you have a config that contains a slice/map of type struct and one of the fields in that struct is an env variable which is set to a numerical value, the collector will fail to start with

Error: failed to get config: cannot unmarshal the configuration: decoding failed due to the following error(s):
error decoding 'extensions': error reading configuration for "headers_setter": decoding failed due to the following error(s):
'headers[0].default_value' expected type 'string', got unconvertible type 'int', value: '12345'

The existing isStringyStructure does not handle structs which causes the first call made to useExpandValue to sanitize "ALL" data input and use the parsed value.

After looking into mapstructure code, I have noticed that the useExpandValue is called on every sub config with the associated data https://github.com/go-viper/mapstructure/blame/main/mapstructure.go#L514-L546
This made me wonder why the extra logic to check the whole structure is needed and that the first block of useExpandValue if exp, ok := data.(expandedValue); ok { should do the job.

Link to tracking issue

I have removed the extra structure type check and some and fixed the string pointer edge case.
Added an extra unit test that exposes the issue at hand.

Testing

Added a unit test and ran a bunch of manual tests

Copy link

codecov bot commented Apr 15, 2025

Codecov Report

Attention: Patch coverage is 40.00000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 91.45%. Comparing base (55f569d) to head (0b87bc4).
Report is 51 commits behind head on main.

Files with missing lines Patch % Lines
confmap/confmap.go 40.00% 2 Missing and 1 partial ⚠️

❌ Your patch check has failed because the patch coverage (40.00%) is below the target coverage (95.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #12860      +/-   ##
==========================================
- Coverage   91.46%   91.45%   -0.02%     
==========================================
  Files         493      493              
  Lines       26984    26968      -16     
==========================================
- Hits        24682    24663      -19     
- Misses       1818     1820       +2     
- Partials      484      485       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dloucasfx dloucasfx changed the title [confmap] **Discussion** Identify string field type and set the expanded value accordingly [confmap] **Discuss** Identify string field type and set the expanded value accordingly Apr 15, 2025
Copy link
Contributor

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added the Stale label Apr 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant