-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Live Metrics Filtering Part 5: Validator #43506
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 all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
4aa78d3
adding projection functionality, rethink automic double
harsimar bf15276
atomic double and some other changes
harsimar 4ace19d
merge from master to get p3 changes
harsimar 75718c7
pr comments and some build stuff
harsimar 27d4979
changing guava version
harsimar 619bb47
spotbug fix
harsimar 915d579
starting to add tests
harsimar 9c8fa37
added unit tests for derived metric projection
harsimar e3377d7
fix conflict from main
harsimar c599211
reorganize tests
harsimar a6ab936
fixing inconsistency with main re okio
harsimar 494a1b9
pr comments & small refactorings
harsimar 1351d2b
remove logging, spotless
harsimar a77adfe
validator
harsimar 68b9c83
minor
harsimar d80053e
changes to concurrency handling
harsimar f83c116
moving synchronization to derivedMetricAggregation
harsimar d8b618f
moving derivedMetricAggregation to its own file
harsimar 77f176a
merge projection into here
harsimar 96e705f
validator round 1 - need to refactor for validator to store errors
harsimar 6e81b55
finish implementation and starting to add tests
harsimar 568f059
merge from main
harsimar de6bd93
spotless
harsimar f492237
remove unused classes
harsimar 191783d
pr comments
harsimar c3c3c49
fix ci errors
harsimar 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
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 |
|---|---|---|
|
|
@@ -50,7 +50,6 @@ void update(double incrementBy) { | |
| return aggregation / count; | ||
| } | ||
| return aggregation; | ||
|
|
||
| } | ||
| } | ||
| } | ||
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
170 changes: 170 additions & 0 deletions
170
...re/monitor/opentelemetry/autoconfigure/implementation/quickpulse/filtering/Validator.java
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,170 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
| package com.azure.monitor.opentelemetry.autoconfigure.implementation.quickpulse.filtering; | ||
|
|
||
| import com.azure.monitor.opentelemetry.autoconfigure.implementation.quickpulse.swagger.models.PredicateType; | ||
| import com.azure.monitor.opentelemetry.autoconfigure.implementation.quickpulse.swagger.models.TelemetryType; | ||
| import com.azure.monitor.opentelemetry.autoconfigure.implementation.quickpulse.swagger.models.DerivedMetricInfo; | ||
| import com.azure.monitor.opentelemetry.autoconfigure.implementation.quickpulse.swagger.models.FilterConjunctionGroupInfo; | ||
| import com.azure.monitor.opentelemetry.autoconfigure.implementation.quickpulse.swagger.models.DocumentFilterConjunctionGroupInfo; | ||
| import com.azure.monitor.opentelemetry.autoconfigure.implementation.quickpulse.swagger.models.FilterInfo; | ||
| import com.azure.monitor.opentelemetry.autoconfigure.implementation.quickpulse.swagger.models.CollectionConfigurationError; | ||
| import com.azure.monitor.opentelemetry.autoconfigure.implementation.quickpulse.swagger.models.CollectionConfigurationErrorType; | ||
| import com.azure.monitor.opentelemetry.autoconfigure.implementation.quickpulse.swagger.models.KeyValuePairString; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.HashSet; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
|
|
||
| import static java.util.Arrays.asList; | ||
|
|
||
| public class Validator { | ||
| private final Set<String> knownStringColumns | ||
| = new HashSet<String>(asList(KnownRequestColumns.URL, KnownRequestColumns.NAME, KnownDependencyColumns.DATA, | ||
| KnownDependencyColumns.TARGET, KnownDependencyColumns.TYPE, KnownTraceColumns.MESSAGE, | ||
| KnownExceptionColumns.MESSAGE, KnownExceptionColumns.STACK)); | ||
|
|
||
| private final Set<String> knownNumericColumns = new HashSet<>( | ||
| asList(KnownRequestColumns.RESPONSE_CODE, KnownRequestColumns.DURATION, KnownDependencyColumns.RESULT_CODE)); | ||
|
|
||
| private final Set<PredicateType> validStringPredicates = new HashSet<>( | ||
| asList(PredicateType.CONTAINS, PredicateType.DOES_NOT_CONTAIN, PredicateType.EQUAL, PredicateType.NOT_EQUAL)); | ||
|
|
||
| // TODO (harskaur): In ErrorTracker PR, track a list of configuration validation errors here | ||
harsimar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| private final List<CollectionConfigurationError> errors = new ArrayList<>(); | ||
|
|
||
| public boolean isValidDerivedMetricInfo(DerivedMetricInfo derivedMetricInfo) { | ||
| TelemetryType telemetryType = TelemetryType.fromString(derivedMetricInfo.getTelemetryType()); | ||
| if (!isValidTelemetryType(telemetryType)) { | ||
| return false; | ||
| } | ||
|
|
||
| if (!isNotCustomMetricProjection(derivedMetricInfo.getProjection())) { | ||
| return false; | ||
| } | ||
|
|
||
| for (FilterConjunctionGroupInfo conjunctionGroupInfo : derivedMetricInfo.getFilterGroups()) { | ||
| for (FilterInfo filter : conjunctionGroupInfo.getFilters()) { | ||
| if (!isValidFieldName(filter.getFieldName(), telemetryType)) { | ||
| return false; | ||
| } | ||
| if (!isValidPredicateAndComparand(filter)) { | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| public boolean | ||
| isValidDocConjunctionGroupInfo(DocumentFilterConjunctionGroupInfo documentFilterConjunctionGroupInfo) { | ||
| TelemetryType telemetryType = documentFilterConjunctionGroupInfo.getTelemetryType(); | ||
| if (!isValidTelemetryType(telemetryType)) { | ||
| return false; | ||
| } | ||
|
|
||
| FilterConjunctionGroupInfo conjunctionGroupInfo = documentFilterConjunctionGroupInfo.getFilters(); | ||
| for (FilterInfo filter : conjunctionGroupInfo.getFilters()) { | ||
| if (!isValidFieldName(filter.getFieldName(), telemetryType)) { | ||
| return false; | ||
| } | ||
| if (!isValidPredicateAndComparand(filter)) { | ||
| return false; | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| public void constructAndTrackCollectionConfigurationError(CollectionConfigurationErrorType errorType, | ||
harsimar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| String message, String eTag, String id, boolean isDerivedMetricId) { | ||
| CollectionConfigurationError error = new CollectionConfigurationError(); | ||
| error.setMessage(message); | ||
| error.setCollectionConfigurationErrorType(errorType); | ||
|
|
||
| KeyValuePairString keyValuePair1 = new KeyValuePairString(); | ||
| keyValuePair1.setKey("ETag"); | ||
| keyValuePair1.setValue(eTag); | ||
|
|
||
| KeyValuePairString keyValuePair2 = new KeyValuePairString(); | ||
| keyValuePair2.setKey(isDerivedMetricId ? "DerivedMetricInfoId" : "DocumentStreamInfoId"); | ||
| keyValuePair2.setValue(id); | ||
|
|
||
| List<KeyValuePairString> data = new ArrayList<>(); | ||
| data.add(keyValuePair1); | ||
| data.add(keyValuePair2); | ||
|
|
||
| error.setData(data); | ||
|
|
||
| // TODO (harskaur): For ErrorTracker PR, add this error to list of tracked errors | ||
| errors.add(error); | ||
| } | ||
|
|
||
| private boolean isValidTelemetryType(TelemetryType telemetryType) { | ||
| // TODO (harskaur): In ErrorTracker PR, create an error message & track an error for each false case | ||
| if (telemetryType.equals(TelemetryType.PERFORMANCE_COUNTER)) { | ||
| return false; | ||
| } else if (telemetryType.equals(TelemetryType.EVENT)) { | ||
| return false; | ||
| } else if (telemetryType.equals(TelemetryType.METRIC)) { | ||
| return false; | ||
| } | ||
| return true; | ||
|
|
||
| } | ||
|
|
||
| private boolean isNotCustomMetricProjection(String projection) { | ||
| if (projection.startsWith("CustomMetrics.")) { | ||
| // TODO (harskaur): In ErrorTracker PR, create an error message & track an error for this case | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| private boolean isValidFieldName(String fieldName, TelemetryType telemetryType) { | ||
| // TODO (harskaur): In ErrorTracker PR, create an error message & track an error for each false case | ||
| if (fieldName.isEmpty()) { | ||
| return false; | ||
| } | ||
| if (fieldName.startsWith("CustomMetrics.")) { | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| private boolean isValidPredicateAndComparand(FilterInfo filter) { | ||
| // TODO (harskaur): In ErrorTracker PR, create an error message & track an error for each false case | ||
| if (filter.getComparand().isEmpty()) { | ||
| // It is possible to not type in a comparand and the service side to send us empty string. | ||
| return false; | ||
| } else if (Filter.ANY_FIELD.equals(filter.getFieldName()) | ||
| && !(filter.getPredicate().equals(PredicateType.CONTAINS) | ||
| || filter.getPredicate().equals(PredicateType.DOES_NOT_CONTAIN))) { | ||
| // While the UI allows != and == for the ANY_FIELD fieldName, .net classic code only allows contains/not contains & the spec follows | ||
| // .net classic behavior for this particular condition. | ||
| return false; | ||
| } else if (knownNumericColumns.contains(filter.getFieldName())) { | ||
| // Just in case a strange timestamp value is passed from the service side. The service side should send a duration with a specific | ||
| // format ([days].[hours]:[minutes]:[seconds] - the seconds may be a whole number or something like 7.89). | ||
| if (KnownDependencyColumns.DURATION.equals(filter.getFieldName())) { | ||
| if (Filter.getMicroSecondsFromFilterTimestampString(filter.getComparand()) == Long.MIN_VALUE) { | ||
| return false; | ||
| } | ||
| } else { // The service side not does not validate if resultcode or responsecode is a numeric value | ||
| try { | ||
| Long.parseLong(filter.getComparand()); | ||
| } catch (NumberFormatException e) { | ||
| return false; | ||
| } | ||
| } | ||
| } else if (knownStringColumns.contains(filter.getFieldName()) | ||
| || filter.getFieldName().startsWith(Filter.CUSTOM_DIM_FIELDNAME_PREFIX)) { | ||
| // While the UI allows a user to select any predicate for a custom dimension filter, .net classic treats all custom dimensions like | ||
| // String values. therefore we validate for predicates applicable to String. This is called out in the spec as well. | ||
| if (!validStringPredicates.contains(filter.getPredicate())) { | ||
| return false; | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
| } | ||
Oops, something went wrong.
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.