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

Simplify unmarshal logic by adding more supported hooks #4237

Merged
merged 3 commits into from Oct 22, 2021

Conversation

bogdandrutu
Copy link
Member

@bogdandrutu bogdandrutu commented Oct 20, 2021

  • Add hook that supports "String -> encoding.TextUnmarshaler", e.g. zapcore.Level no longer need special unmarshaling
  • Add a special hook for map[string]interface{} -> map[ComponentID]interface{} to determine duplicates after space trimming, not sure if this error needs this special treatment.

Signed-off-by: Bogdan Drutu bogdandrutu@gmail.com

@bogdandrutu bogdandrutu requested a review from a team as a code owner October 20, 2021 23:21
@codecov
Copy link

codecov bot commented Oct 20, 2021

Codecov Report

Merging #4237 (92e2c29) into main (b927925) will increase coverage by 0.13%.
The diff coverage is 96.20%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4237      +/-   ##
==========================================
+ Coverage   87.92%   88.05%   +0.13%     
==========================================
  Files         173      173              
  Lines       10263    10200      -63     
==========================================
- Hits         9024     8982      -42     
+ Misses        993      977      -16     
+ Partials      246      241       -5     
Impacted Files Coverage Δ
config/config.go 100.00% <ø> (ø)
config/configmap.go 81.98% <92.68%> (+10.24%) ⬆️
config/configunmarshaler/defaultunmarshaler.go 100.00% <100.00%> (+4.45%) ⬆️
config/identifiable.go 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b927925...92e2c29. Read the comment docs.

* Add hook that supports "String -> encoding.TextUnmarshaler", e.g. zapcore.Level no longer need special unmarshaling
* Add hook that supports "String -> ComponentID"
* Add a special hook for map[string]interface{} -> map[ComponentID]interface{} to determine duplicates after space trimming, not sure if this error needs this special treatment.

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
bogdandrutu added a commit to bogdandrutu/opentelemetry-collector that referenced this pull request Oct 20, 2021
Depends on open-telemetry#4237

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
Copy link
Member

@jpkrohling jpkrohling left a comment

Choose a reason for hiding this comment

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

Not sure this is part of this PR, but here's how the error messages are presented to the users after this PR:

$ go run ./cmd/otelcol --config config/configunmarshaler/testdata/invalid-exporter-name-after-slash.yaml 
Error: cannot load configuration: error reading top level configuration sections: 1 error(s) decoding:

* error decoding 'exporters': name part must be specified after / in type/name key
2021/10/21 14:16:58 collector server run finished with error: cannot load configuration: error reading top level configuration sections: 1 error(s) decoding:

* error decoding 'exporters': name part must be specified after / in type/name key
exit status 1

Can we do better? The error is that "exporter/" doesn't contain a name and it requires the user to parse the output (which seems duplicate) to figure that out. The closest to helping the user is "name part must be specified after / in type/name key" but that's also a bit cryptic, IMO.

Also, and now more specific to this PR: there seems to be a missing test coverage for the new functions.

config/configmap.go Outdated Show resolved Hide resolved
// This is needed in combination with stringToComponentIDHookFunc since the NewComponentIDFromString may produce
// equal IDs for different strings, and an error needs to be returned in that case, otherwise the last equivalent ID
// overwrites the previous one.
func mapStringToMapComponentIDHookFunc() mapstructure.DecodeHookFunc {
Copy link
Member

Choose a reason for hiding this comment

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

Why don't you just define the func as var, instead of having a new func per invocation of mapStringToMapComponentIDHookFunc()?

Copy link
Member

Choose a reason for hiding this comment

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

Also, there seems to be no coverage for this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done the var part for all funcs, even though not that important since this happens during initialization, but I like to follow best practices :)

Copy link
Member Author

Choose a reason for hiding this comment

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

In terms of testing, the "duplicate" ComponentID is tested in the defaultunmarshaler/duplicate_foo tests.

config/configmap.go Outdated Show resolved Hide resolved
@bogdandrutu
Copy link
Member Author

/easycla

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
@@ -1,8 +1,8 @@
receivers:
examplereceiver:
exporters:
exampleexporter/exp:
exampleexporter/ exp :
exampleexporter /exp :
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the changes in the duplicate yaml test files?

Copy link
Member Author

Choose a reason for hiding this comment

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

Adding spaces in more parts of the name to ensure we do the right thing.

config/identifiable.go Show resolved Hide resolved
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
@bogdandrutu
Copy link
Member Author

@codeboten PTAL

@bogdandrutu bogdandrutu merged commit bd13c61 into open-telemetry:main Oct 22, 2021
@bogdandrutu bogdandrutu deleted the usemorehooks branch October 22, 2021 00:08
bogdandrutu added a commit to bogdandrutu/opentelemetry-collector that referenced this pull request Oct 22, 2021
Depends on open-telemetry#4237

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
bogdandrutu added a commit that referenced this pull request Oct 22, 2021
Depends on #4237

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
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.

None yet

3 participants