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

fix: prevent putDimensions from storing duplicate dimensions #104

Merged
merged 3 commits into from
Aug 12, 2022

Conversation

aaronlna
Copy link
Contributor

@aaronlna aaronlna commented Nov 22, 2021

Issue

#20 (previous, related issue)

Description of changes

It appears a prior change addressing this issue may be allowing both variably-sized dimensions sets, and dimension sets with different keys, to be added, even if they are true duplicates of existing sets in the collection. Examples:

[
  ['A', 'B'],
  ['A', 'B', C'],
  ['A', 'B'], // this would be considered acceptable
]

// Output: 3 dimension sets (should be 2)
[
  ['A', 'B'],
  ['B', 'C'],
  ['A', 'B'], // this would be considered acceptable
]

// Output: 3 dimension sets (should be 2)

This change fixes that aforementioned behavior and adds an additional behavior:

  1. duplicate dimension sets replace (and are sorted after) existing dimension sets such
    that newer/latest dimension values are used by the root EMF node

Example:

putDimensions({ "keyA": "valueA1" })
putDimensions({ "keyA": "valueA2" })
putDimensions({ "keyA": "valueA3", "keyB": "valueB1" })
putDimensions({ "keyB": "valueB2", "keyA": "valueA4" })

// expected MetricsDirective dimensions:
[
  { "keyA": "valueA2" },
  { "keyB": "valueB2", "keyA": "valueA4" },
]

// expected EMF target members:
{
  "keyA": "valueA4",
  "keyB": "valueB2",
}

Description of how you validated changes

Unit tests were updated to check for these two edge-cases.


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Conditions previously checked for any dimension set which did not match
before adding the input dimension set.

This would allow different-sized dimension sets from being mistaken
as non-duplicate and being added (see unit test for example).

New conditions check for any dimension set which does match
before skipping adding the input dimension set to the collection.

[TESTING]

Unit test updated to address edge case;
multiple dimension sets of variable size are added and checked.
… duplicate

This change ensures new dimension key-values are used for the EMF root node
by removing duplicate dimension sets and adding input dimension set to the
end of the collection.

Example:

```
[
  { "keyA": "value1" },
  { "keyA": "value2" },
]

// expected EMF target member: { "keyA": "value2 }
```

[TESTING]

Updated unit tests to check for this chase wherein putDimensions
may be triggered using various dimension set lengths, values, and order.
@markkuhn markkuhn requested review from Himtanaya and removed request for Himtanaya August 11, 2022 00:07
@markkuhn markkuhn linked an issue Aug 11, 2022 that may be closed by this pull request
Copy link

@Stephen-Bao Stephen-Bao left a comment

Choose a reason for hiding this comment

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

Looks good.

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.

Disallow duplicate dimension sets.
3 participants