Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
4aa78d3
adding projection functionality, rethink automic double
harsimar Dec 10, 2024
bf15276
atomic double and some other changes
harsimar Dec 11, 2024
4ace19d
merge from master to get p3 changes
harsimar Dec 11, 2024
75718c7
pr comments and some build stuff
harsimar Dec 11, 2024
27d4979
changing guava version
harsimar Dec 11, 2024
619bb47
spotbug fix
harsimar Dec 11, 2024
915d579
starting to add tests
harsimar Dec 12, 2024
9c8fa37
added unit tests for derived metric projection
harsimar Dec 13, 2024
e3377d7
fix conflict from main
harsimar Dec 13, 2024
c599211
reorganize tests
harsimar Dec 13, 2024
a6ab936
fixing inconsistency with main re okio
harsimar Dec 13, 2024
494a1b9
pr comments & small refactorings
harsimar Dec 16, 2024
1351d2b
remove logging, spotless
harsimar Dec 16, 2024
a77adfe
validator
harsimar Dec 17, 2024
68b9c83
minor
harsimar Dec 17, 2024
d80053e
changes to concurrency handling
harsimar Dec 17, 2024
f83c116
moving synchronization to derivedMetricAggregation
harsimar Dec 17, 2024
d8b618f
moving derivedMetricAggregation to its own file
harsimar Dec 17, 2024
77f176a
merge projection into here
harsimar Dec 18, 2024
96e705f
validator round 1 - need to refactor for validator to store errors
harsimar Dec 18, 2024
6e81b55
finish implementation and starting to add tests
harsimar Dec 19, 2024
568f059
merge from main
harsimar Dec 19, 2024
de6bd93
spotless
harsimar Dec 20, 2024
f492237
remove unused classes
harsimar Dec 20, 2024
191783d
pr comments
harsimar Jan 6, 2025
c3c3c49
fix ci errors
harsimar Jan 6, 2025
0ee6032
initial implementation
harsimar Jan 7, 2025
73f4cc7
merge conflicts and starting to add some logging
harsimar Jan 8, 2025
0c5aae9
logging and testing
harsimar Jan 9, 2025
f1ba015
restructure of error tracking in validator
harsimar Jan 10, 2025
76d8577
pr comments
harsimar Jan 10, 2025
0555332
minor
harsimar Jan 10, 2025
648bc10
some pr comments
harsimar Jan 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
validator
  • Loading branch information
harsimar committed Dec 17, 2024
commit a77adfe0b1ae64467e11345c90dee860e4e84279
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.azure.monitor.opentelemetry.autoconfigure.implementation.quickpulse.filtering;

public class DuplicateMetricIdException extends Exception {
public DuplicateMetricIdException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
import com.azure.monitor.opentelemetry.autoconfigure.implementation.quickpulse.swagger.models.DocumentFilterConjunctionGroupInfo;
import com.azure.monitor.opentelemetry.autoconfigure.implementation.quickpulse.swagger.models.AggregationType;
import com.azure.monitor.opentelemetry.autoconfigure.implementation.quickpulse.swagger.models.TelemetryType;
import com.azure.monitor.opentelemetry.autoconfigure.implementation.quickpulse.swagger.models.PredicateType;
import com.azure.monitor.opentelemetry.autoconfigure.implementation.quickpulse.swagger.models.FilterInfo;

import java.util.Set;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashSet;
import java.util.HashMap;
import static java.util.Arrays.asList;

public class FilteringConfiguration {
private final Set<String> seenMetricIds = new HashSet<>();
Expand Down Expand Up @@ -134,4 +137,115 @@ private Map<String, AggregationType> initValidProjectionInfo() {
return result;
}

public static class Validator {
private static 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 static final Set<String> knownNumericColumns = new HashSet<>(asList(KnownRequestColumns.RESPONSE_CODE,
KnownRequestColumns.DURATION, KnownDependencyColumns.RESULT_CODE));

private static final Set<PredicateType> validStringPredicates = new HashSet<>(asList(PredicateType.CONTAINS,
PredicateType.DOES_NOT_CONTAIN, PredicateType.EQUAL, PredicateType.NOT_EQUAL));

public static void validateTelemetryType(TelemetryType telemetryType) throws TelemetryTypeException {
if (telemetryType.equals(TelemetryType.PERFORMANCE_COUNTER)) {
throw new TelemetryTypeException(
"The telemetry type PerformanceCounter was specified, but the distro does not send performance counters other than CPU/Mem to quickpulse");
} else if (telemetryType.equals(TelemetryType.EVENT)) {
throw new TelemetryTypeException(
"The telemetry type Event was specified, but the distro does not send events to quickpulse");
} else if (telemetryType.equals(TelemetryType.METRIC)) {
throw new TelemetryTypeException(
"The telemetry type Metric was specified, but the distro does not support sending open telemetry metrics to quickpulse");
}
}

public static void checkCustomMetricProjection(DerivedMetricInfo derivedMetricInfo)
throws UnexpectedFilterCreateException {
if (derivedMetricInfo.getProjection().startsWith("CustomMetrics.")) {
throw new UnexpectedFilterCreateException(
"The projection of a customMetric property is not supported in this distro.");
}
}

public static void validateMetricFilters(DerivedMetricInfo derivedMetricInfo)
throws UnexpectedFilterCreateException {
for (FilterConjunctionGroupInfo conjunctionGroupInfo : derivedMetricInfo.getFilterGroups()) {
for (FilterInfo filter : conjunctionGroupInfo.getFilters()) {
TelemetryType telemetryType = TelemetryType.fromString(derivedMetricInfo.getTelemetryType());
validateFieldNames(filter.getFieldName(), telemetryType);
validatePredicateAndComparand(filter);
}
}
}

public static void
validateDocumentFilters(DocumentFilterConjunctionGroupInfo documentFilterConjunctionGroupInfo)
throws UnexpectedFilterCreateException {
FilterConjunctionGroupInfo conjunctionGroupInfo = documentFilterConjunctionGroupInfo.getFilters();
for (FilterInfo filter : conjunctionGroupInfo.getFilters()) {
validateFieldNames(filter.getFieldName(), documentFilterConjunctionGroupInfo.getTelemetryType());
validatePredicateAndComparand(filter);
}
}

private static boolean isCustomDimOrAnyField(String fieldName) {
return fieldName.startsWith(Filter.CUSTOM_DIM_FIELDNAME_PREFIX) || fieldName.equals(Filter.ANY_FIELD);
}

private static void validateFieldNames(String fieldName, TelemetryType telemetryType)
throws UnexpectedFilterCreateException {
if (fieldName.isEmpty()) {
throw new UnexpectedFilterCreateException("A filter must have a non-empty field name.");
}
if (fieldName.startsWith("CustomMetrics.")) {
throw new UnexpectedFilterCreateException(
"Filtering of a customMetric property is not supported in this distro.");
}
}

private static void validatePredicateAndComparand(FilterInfo filter) throws UnexpectedFilterCreateException {
if (filter.getComparand().isEmpty()) {
// It is possible to not type in a comparand and the service side to send us empty string.
throw new UnexpectedFilterCreateException("A filter must have a non-empty comparand. FilterName: "
+ filter.getFieldName() + " Predicate: " + filter.getPredicate().getValue());
} 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.
throw new UnexpectedFilterCreateException(
"The predicate " + filter.getPredicate().getValue() + " is not supported for the field name *");
} 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) {
throw new UnexpectedFilterCreateException(
"The provided duration timestamp can't be converted to microseconds: " + filter.getComparand());
}
} else { // The service side not does not validate if resultcode or responsecode is a numeric value
try {
Long.parseLong(filter.getComparand());
} catch (NumberFormatException e) {
throw new UnexpectedFilterCreateException(
"Could not convert the provided result/response code to a numeric value: "
+ filter.getComparand());
}
}
} 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())) {
throw new UnexpectedFilterCreateException("The predicate " + filter.getPredicate().getValue()
+ " is not supported for the field " + filter.getFieldName());
}
}
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.azure.monitor.opentelemetry.autoconfigure.implementation.quickpulse.filtering;

public class MetricFailureToCreateException extends Exception {
public MetricFailureToCreateException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.azure.monitor.opentelemetry.autoconfigure.implementation.quickpulse.filtering;

public class TelemetryTypeException extends Exception {
public TelemetryTypeException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.azure.monitor.opentelemetry.autoconfigure.implementation.quickpulse.filtering;

public class UnexpectedFilterCreateException extends Exception {
public UnexpectedFilterCreateException(String message) {
super(message);
}
}