generated from amazon-archives/__template_Custom
-
Notifications
You must be signed in to change notification settings - Fork 237
[Bugfix] Fix merging logic to append multiple jvm/otlp configurations #1870
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
Changes from 9 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
5d02efa
[Bugfix] Fix JVM merging logic to append multiple jvm configurations
lisguo 285c1dd
make fmt
lisguo 3ba4a1d
Refactor mergeJmxList to use the existing mergeList func
lisguo aebe056
Refactor to merge keys that can be either a map or an array
lisguo 0037256
Add test that shows measurements will not be merged
lisguo 6e950cc
make fmt. fix syntax error
lisguo 9878d98
ignore linter for test code for legacy package
lisguo ea1e12b
Merge branch 'main' into lisaguo-jvm-merge
lisguo 3776a5c
Add otlp to map
lisguo a76c8d1
make fmt. add unit test to include otlp
lisguo af1c4b1
make fmt again
lisguo 5b01d0d
Use switch statement in mergeMap, use assert in test
lisguo 555e668
Merge branch 'main' into lisaguo-jvm-merge
lisguo 0d3e0a7
Update translator/jsonconfig/mergeJsonUtil/util.go
lisguo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,295 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package mergeJsonUtil // nolint:revive | ||
|
|
||
| import ( | ||
| "reflect" | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestMergeArrayOrObjectConfiguration(t *testing.T) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Missing coverage for merging an array into an object. |
||
| tests := []struct { | ||
| name string | ||
| sourceMap map[string]interface{} | ||
| resultMap map[string]interface{} | ||
| expected map[string]interface{} | ||
| }{ | ||
| { | ||
| name: "1. Merge two identical JVM objects -> single configuration", | ||
| sourceMap: map[string]interface{}{ | ||
| "jmx": map[string]interface{}{ | ||
| "endpoint": "localhost:9999", | ||
| "jvm": map[string]interface{}{ | ||
| "measurement": []interface{}{"jvm.memory.heap.used", "jvm.gc.collections.count"}, | ||
| }, | ||
| }, | ||
| }, | ||
| resultMap: map[string]interface{}{ | ||
| "jmx": map[string]interface{}{ | ||
| "endpoint": "localhost:9999", | ||
| "jvm": map[string]interface{}{ | ||
| "measurement": []interface{}{"jvm.memory.heap.used", "jvm.gc.collections.count"}, | ||
| }, | ||
| }, | ||
| }, | ||
| expected: map[string]interface{}{ | ||
| "jmx": map[string]interface{}{ | ||
| "endpoint": "localhost:9999", | ||
| "jvm": map[string]interface{}{ | ||
| "measurement": []interface{}{"jvm.memory.heap.used", "jvm.gc.collections.count"}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| { | ||
| name: "2. Merge two different JVM objects -> array with two objects", | ||
| sourceMap: map[string]interface{}{ | ||
| "jmx": map[string]interface{}{ | ||
| "endpoint": "localhost:9999", | ||
| "jvm": map[string]interface{}{ | ||
| "measurement": []interface{}{"jvm.memory.heap.used", "jvm.gc.collections.count"}, | ||
| }, | ||
| }, | ||
| }, | ||
| resultMap: map[string]interface{}{ | ||
| "jmx": map[string]interface{}{ | ||
| "endpoint": "localhost:1234", | ||
| "jvm": map[string]interface{}{ | ||
| "measurement": []interface{}{"jvm.classes.loaded", "jvm.memory.heap.committed"}, | ||
| }, | ||
| }, | ||
| }, | ||
| expected: map[string]interface{}{ | ||
| "jmx": []interface{}{ | ||
| map[string]interface{}{ | ||
| "endpoint": "localhost:1234", | ||
| "jvm": map[string]interface{}{ | ||
| "measurement": []interface{}{"jvm.classes.loaded", "jvm.memory.heap.committed"}, | ||
| }, | ||
| }, | ||
| map[string]interface{}{ | ||
| "endpoint": "localhost:9999", | ||
| "jvm": map[string]interface{}{ | ||
| "measurement": []interface{}{"jvm.memory.heap.used", "jvm.gc.collections.count"}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| { | ||
| name: "3. Merge JVM array with different object -> array with two objects", | ||
| sourceMap: map[string]interface{}{ | ||
| "jmx": []interface{}{ | ||
| map[string]interface{}{ | ||
| "endpoint": "localhost:9999", | ||
| "jvm": map[string]interface{}{ | ||
| "measurement": []interface{}{"jvm.memory.heap.used", "jvm.gc.collections.count"}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| resultMap: map[string]interface{}{ | ||
| "jmx": map[string]interface{}{ | ||
| "endpoint": "localhost:1234", | ||
| "jvm": map[string]interface{}{ | ||
| "measurement": []interface{}{"jvm.classes.loaded", "jvm.memory.heap.committed"}, | ||
| }, | ||
| }, | ||
| }, | ||
| expected: map[string]interface{}{ | ||
| "jmx": []interface{}{ | ||
| map[string]interface{}{ | ||
| "endpoint": "localhost:1234", | ||
| "jvm": map[string]interface{}{ | ||
| "measurement": []interface{}{"jvm.classes.loaded", "jvm.memory.heap.committed"}, | ||
| }, | ||
| }, | ||
| map[string]interface{}{ | ||
| "endpoint": "localhost:9999", | ||
| "jvm": map[string]interface{}{ | ||
| "measurement": []interface{}{"jvm.memory.heap.used", "jvm.gc.collections.count"}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| { | ||
| name: "4. Merge two different JVM arrays -> array with two objects", | ||
| sourceMap: map[string]interface{}{ | ||
| "jmx": []interface{}{ | ||
| map[string]interface{}{ | ||
| "endpoint": "localhost:9999", | ||
| "jvm": map[string]interface{}{ | ||
| "measurement": []interface{}{"jvm.memory.heap.used", "jvm.gc.collections.count"}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| resultMap: map[string]interface{}{ | ||
| "jmx": []interface{}{ | ||
| map[string]interface{}{ | ||
| "endpoint": "localhost:1234", | ||
| "jvm": map[string]interface{}{ | ||
| "measurement": []interface{}{"jvm.classes.loaded", "jvm.memory.heap.committed"}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| expected: map[string]interface{}{ | ||
| "jmx": []interface{}{ | ||
| map[string]interface{}{ | ||
| "endpoint": "localhost:1234", | ||
| "jvm": map[string]interface{}{ | ||
| "measurement": []interface{}{"jvm.classes.loaded", "jvm.memory.heap.committed"}, | ||
| }, | ||
| }, | ||
| map[string]interface{}{ | ||
| "endpoint": "localhost:9999", | ||
| "jvm": map[string]interface{}{ | ||
| "measurement": []interface{}{"jvm.memory.heap.used", "jvm.gc.collections.count"}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| { | ||
| name: "5. Merge two identical JVM arrays -> array with single object", | ||
| sourceMap: map[string]interface{}{ | ||
| "jmx": []interface{}{ | ||
| map[string]interface{}{ | ||
| "endpoint": "localhost:9999", | ||
| "jvm": map[string]interface{}{ | ||
| "measurement": []interface{}{"jvm.memory.heap.used", "jvm.gc.collections.count"}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| resultMap: map[string]interface{}{ | ||
| "jmx": []interface{}{ | ||
| map[string]interface{}{ | ||
| "endpoint": "localhost:9999", | ||
| "jvm": map[string]interface{}{ | ||
| "measurement": []interface{}{"jvm.memory.heap.used", "jvm.gc.collections.count"}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| expected: map[string]interface{}{ | ||
| "jmx": []interface{}{ | ||
| map[string]interface{}{ | ||
| "endpoint": "localhost:9999", | ||
| "jvm": map[string]interface{}{ | ||
| "measurement": []interface{}{"jvm.memory.heap.used", "jvm.gc.collections.count"}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| { | ||
| name: "merge with empty result map", | ||
| sourceMap: map[string]interface{}{ | ||
| "jmx": map[string]interface{}{ | ||
| "endpoint": "localhost:9999", | ||
| "jvm": map[string]interface{}{ | ||
| "measurement": []interface{}{"jvm.memory.heap.used"}, | ||
| }, | ||
| }, | ||
| }, | ||
| resultMap: map[string]interface{}{}, | ||
| expected: map[string]interface{}{ | ||
| "jmx": map[string]interface{}{ | ||
| "endpoint": "localhost:9999", | ||
| "jvm": map[string]interface{}{ | ||
| "measurement": []interface{}{"jvm.memory.heap.used"}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| { | ||
| name: "merge mixed Kafka and Tomcat configurations", | ||
| sourceMap: map[string]interface{}{ | ||
| "jmx": []interface{}{ | ||
| map[string]interface{}{ | ||
| "endpoint": "localhost:9999", | ||
| "tomcat": map[string]interface{}{ | ||
| "measurement": []interface{}{"tomcat.sessions", "tomcat.errors"}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| resultMap: map[string]interface{}{ | ||
| "jmx": map[string]interface{}{ | ||
| "endpoint": "localhost:1234", | ||
| "kafka": map[string]interface{}{ | ||
| "measurement": []interface{}{"kafka.request.time.avg", "kafka.request.failed"}, | ||
| }, | ||
| }, | ||
| }, | ||
| expected: map[string]interface{}{ | ||
| "jmx": []interface{}{ | ||
| map[string]interface{}{ | ||
| "endpoint": "localhost:1234", | ||
| "kafka": map[string]interface{}{ | ||
| "measurement": []interface{}{"kafka.request.time.avg", "kafka.request.failed"}, | ||
| }, | ||
| }, | ||
| map[string]interface{}{ | ||
| "endpoint": "localhost:9999", | ||
| "tomcat": map[string]interface{}{ | ||
| "measurement": []interface{}{"tomcat.sessions", "tomcat.errors"}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| { | ||
| name: "merge JVM arrays with same endpoint but different measurements -> separate objects", | ||
| sourceMap: map[string]interface{}{ | ||
| "jmx": []interface{}{ | ||
| map[string]interface{}{ | ||
| "endpoint": "localhost:9999", | ||
| "jvm": map[string]interface{}{ | ||
| "measurement": []interface{}{"jvm.gc.collections.count"}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| resultMap: map[string]interface{}{ | ||
| "jmx": []interface{}{ | ||
| map[string]interface{}{ | ||
| "endpoint": "localhost:9999", | ||
| "jvm": map[string]interface{}{ | ||
| "measurement": []interface{}{"jvm.classes.loaded"}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| expected: map[string]interface{}{ | ||
| "jmx": []interface{}{ | ||
| map[string]interface{}{ | ||
| "endpoint": "localhost:9999", | ||
| "jvm": map[string]interface{}{ | ||
| "measurement": []interface{}{"jvm.classes.loaded"}, | ||
| }, | ||
| }, | ||
| map[string]interface{}{ | ||
| "endpoint": "localhost:9999", | ||
| "jvm": map[string]interface{}{ | ||
| "measurement": []interface{}{"jvm.gc.collections.count"}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| mergeArrayOrObjectConfiguration(tt.sourceMap, tt.resultMap, "jmx", "/test/path/") | ||
| if !reflect.DeepEqual(tt.resultMap, tt.expected) { | ||
| t.Errorf("mergeArrayOrObjectConfiguration() = %v, want %v", tt.resultMap, tt.expected) | ||
| } | ||
lisguo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }) | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.