diff --git a/sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/main/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/quickpulse/QuickPulseDataCollector.java b/sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/main/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/quickpulse/QuickPulseDataCollector.java index 3b25ddbf5f927..c11f574997dde 100644 --- a/sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/main/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/quickpulse/QuickPulseDataCollector.java +++ b/sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/main/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/quickpulse/QuickPulseDataCollector.java @@ -19,8 +19,17 @@ import com.azure.monitor.opentelemetry.autoconfigure.implementation.quickpulse.filtering.Filter; import com.azure.monitor.opentelemetry.autoconfigure.implementation.quickpulse.filtering.TraceDataColumns; import com.azure.monitor.opentelemetry.autoconfigure.implementation.quickpulse.filtering.DerivedMetricProjections; -import com.azure.monitor.opentelemetry.autoconfigure.implementation.quickpulse.swagger.models.*; +import com.azure.monitor.opentelemetry.autoconfigure.implementation.quickpulse.swagger.models.RemoteDependency; +import com.azure.monitor.opentelemetry.autoconfigure.implementation.quickpulse.swagger.models.Request; +import com.azure.monitor.opentelemetry.autoconfigure.implementation.quickpulse.swagger.models.KeyValuePairString; +import com.azure.monitor.opentelemetry.autoconfigure.implementation.quickpulse.swagger.models.DocumentIngress; import com.azure.monitor.opentelemetry.autoconfigure.implementation.quickpulse.swagger.models.Exception; +import com.azure.monitor.opentelemetry.autoconfigure.implementation.quickpulse.swagger.models.FilterConjunctionGroupInfo; +import com.azure.monitor.opentelemetry.autoconfigure.implementation.quickpulse.swagger.models.DerivedMetricInfo; +import com.azure.monitor.opentelemetry.autoconfigure.implementation.quickpulse.swagger.models.Trace; +import com.azure.monitor.opentelemetry.autoconfigure.implementation.quickpulse.swagger.models.TelemetryType; +import com.azure.monitor.opentelemetry.autoconfigure.implementation.quickpulse.swagger.models.AggregationType; +import com.azure.monitor.opentelemetry.autoconfigure.implementation.quickpulse.swagger.models.CollectionConfigurationError; import com.azure.monitor.opentelemetry.autoconfigure.implementation.utils.CpuPerformanceCounterCalculator; import reactor.util.annotation.Nullable; @@ -84,7 +93,8 @@ synchronized QuickPulseStatus getQuickPulseStatus() { @Nullable synchronized FinalCounters getAndRestart() { FilteringConfiguration config = configuration.get(); - Counters currentCounters = counters.getAndSet(new Counters(config.getValidProjectionInitInfo(), config.getErrors())); + Counters currentCounters + = counters.getAndSet(new Counters(config.getValidProjectionInitInfo(), config.getErrors())); if (currentCounters != null) { return new FinalCounters(currentCounters); } diff --git a/sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/main/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/quickpulse/QuickPulseDataSender.java b/sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/main/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/quickpulse/QuickPulseDataSender.java index a778c797afe24..886dd1be134b2 100644 --- a/sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/main/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/quickpulse/QuickPulseDataSender.java +++ b/sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/main/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/quickpulse/QuickPulseDataSender.java @@ -81,14 +81,13 @@ public void run() { long transmissionTimeInTicks = currentDate.getTime() * 10000 + TICKS_AT_EPOCH; String etag = configuration.get().getETag(); - logger.verbose("Attempting to send data points to quickpulse with etag {}: {}", - etag, + logger.verbose("Attempting to send data points to quickpulse with etag {}: {}", etag, printListOfMonitoringPoints(dataPointList)); try { Response responseMono = liveMetricsRestAPIsForClientSDKs - .publishNoCustomHeadersWithResponseAsync(endpointPrefix, instrumentationKey.get(), - etag, transmissionTimeInTicks, dataPointList) + .publishNoCustomHeadersWithResponseAsync(endpointPrefix, instrumentationKey.get(), etag, + transmissionTimeInTicks, dataPointList) .block(); if (responseMono == null) { // this shouldn't happen, the mono should complete with a response or a failure @@ -111,7 +110,8 @@ public void run() { if (body != null && !etag.equals(body.getETag())) { configuration.set(new FilteringConfiguration(body)); try { - logger.verbose("Received a new live metrics filtering configuration from post response: {}", body.toJsonString()); + logger.verbose("Received a new live metrics filtering configuration from post response: {}", + body.toJsonString()); } catch (IOException e) { logger.verbose(e.getMessage()); } @@ -140,11 +140,11 @@ private void onPostError(long sendTime) { private String printListOfMonitoringPoints(List points) { StringBuilder dataPointsPrint = new StringBuilder("["); - for (MonitoringDataPoint p: points) { + for (MonitoringDataPoint p : points) { try { dataPointsPrint.append(p.toJsonString()); dataPointsPrint.append("\n"); - } catch (IOException e){ + } catch (IOException e) { logger.verbose(e.getMessage()); } } diff --git a/sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/main/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/quickpulse/QuickPulsePingSender.java b/sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/main/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/quickpulse/QuickPulsePingSender.java index 6d11179e0e7a2..92c4afe5ff4be 100644 --- a/sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/main/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/quickpulse/QuickPulsePingSender.java +++ b/sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/main/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/quickpulse/QuickPulsePingSender.java @@ -106,8 +106,9 @@ IsSubscribedHeaders ping(String redirectedEndpoint) { CollectionConfigurationInfo body = responseMono.getValue(); if (body != null && !configuration.get().getETag().equals(body.getETag())) { try { - logger.verbose("Received a new live metrics filtering configuration from ping response: {}", body.toJsonString()); - } catch (IOException e){ + logger.verbose("Received a new live metrics filtering configuration from ping response: {}", + body.toJsonString()); + } catch (IOException e) { logger.verbose(e.getMessage()); } configuration.set(new FilteringConfiguration(body)); diff --git a/sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/main/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/quickpulse/filtering/CustomDimensions.java b/sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/main/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/quickpulse/filtering/CustomDimensions.java index 6d90d17f1baaa..3efec24ce7358 100644 --- a/sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/main/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/quickpulse/filtering/CustomDimensions.java +++ b/sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/main/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/quickpulse/filtering/CustomDimensions.java @@ -2,6 +2,7 @@ // Licensed under the MIT License. package com.azure.monitor.opentelemetry.autoconfigure.implementation.quickpulse.filtering; +import com.azure.core.util.logging.ClientLogger; import com.azure.monitor.opentelemetry.autoconfigure.implementation.quickpulse.swagger.models.FilterInfo; import java.util.HashMap; @@ -9,6 +10,7 @@ public class CustomDimensions { private final Map customDimensions; + private static ClientLogger logger = new ClientLogger(CustomDimensions.class); public CustomDimensions(Map customDimensions, Map customMeasurements) { Map resultMap = new HashMap<>(); @@ -47,9 +49,13 @@ public double getCustomDimValueForProjection(String key) { try { return Double.parseDouble(value); } catch (NumberFormatException e) { - + logger.verbose( + "The value for the custom dimension could not be converted to a numeric value for a derived metric projection"); } + return Double.NaN; } + logger.verbose( + "The custom dimension could not be found in this telemetry item when calculating a derived metric."); return Double.NaN; } diff --git a/sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/main/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/quickpulse/filtering/DependencyDataColumns.java b/sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/main/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/quickpulse/filtering/DependencyDataColumns.java index 40ebf92143843..f5227b93f236a 100644 --- a/sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/main/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/quickpulse/filtering/DependencyDataColumns.java +++ b/sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/main/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/quickpulse/filtering/DependencyDataColumns.java @@ -21,12 +21,12 @@ public class DependencyDataColumns implements TelemetryColumns { public DependencyDataColumns(RemoteDependencyData rdData) { customDims = new CustomDimensions(rdData.getProperties(), rdData.getMeasurements()); mapping.put(KnownDependencyColumns.TARGET, rdData.getTarget()); - mapping.put(KnownDependencyColumns.DURATION, - FormattedDuration.getDurationFromTelemetryItemDurationString(rdData.getDuration())); - if (mapping.get(KnownDependencyColumns.DURATION).equals(-1)) { - logger.verbose("The timestamp from the RemoteDependencyData could not be converted to microseconds: {}", rdData.getDuration()); + long durationMicroSec = FormattedDuration.getDurationFromTelemetryItemDurationString(rdData.getDuration()); + if (durationMicroSec == -1) { + logger.verbose("The provided timestamp could not be converted to microseconds: {}", rdData.getDuration()); } + mapping.put(KnownDependencyColumns.DURATION, durationMicroSec); mapping.put(KnownDependencyColumns.SUCCESS, rdData.isSuccess()); mapping.put(KnownDependencyColumns.NAME, rdData.getName()); @@ -34,7 +34,8 @@ public DependencyDataColumns(RemoteDependencyData rdData) { try { resultCode = Integer.parseInt(rdData.getResultCode()); } catch (NumberFormatException e) { - logger.verbose("The result code in the RemoteDependencyData object could not be converted to a numeric value so setting the value to -1: {}", rdData.getResultCode()); + logger.verbose("The provided result code could not be converted to a numeric value: {}", + rdData.getResultCode()); resultCode = -1; } mapping.put(KnownDependencyColumns.RESULT_CODE, resultCode); diff --git a/sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/main/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/quickpulse/filtering/DerivedMetricProjections.java b/sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/main/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/quickpulse/filtering/DerivedMetricProjections.java index b57dfa4e2df66..9c341ce12a6b4 100644 --- a/sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/main/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/quickpulse/filtering/DerivedMetricProjections.java +++ b/sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/main/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/quickpulse/filtering/DerivedMetricProjections.java @@ -15,7 +15,7 @@ public class DerivedMetricProjections { public static final String COUNT = "Count()"; private final Map derivedMetricValues = new HashMap<>(); - private static final ClientLogger logger = new ClientLogger(DerivedMetricProjections.class); + private static final ClientLogger LOGGER = new ClientLogger(DerivedMetricProjections.class); public DerivedMetricProjections(Map projectionInfo) { for (Map.Entry entry : projectionInfo.entrySet()) { @@ -65,10 +65,8 @@ public void calculateProjection(DerivedMetricInfo derivedMetricInfo, TelemetryCo } if (Double.isNaN(incrementBy)) { - logger.verbose("The {} column in the incoming telemetry item was either not present or could not be parsed to a numeric value. " + - "This telemetry item will not be counted in derived metric projections.", - derivedMetricInfo.getProjection().equals(KnownRequestColumns.DURATION) ? - "Duration" : derivedMetricInfo.getProjection().substring(Filter.CUSTOM_DIM_FIELDNAME_PREFIX.length())); + LOGGER.verbose( + "This telemetry item will not be counted in derived metric projections because the Duration or a CustomDimension column could not be interpreted as a numeric value."); } else { calculateAggregation(derivedMetricInfo.getId(), incrementBy); } diff --git a/sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/main/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/quickpulse/filtering/FilteringConfiguration.java b/sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/main/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/quickpulse/filtering/FilteringConfiguration.java index 08f17ed816216..5a21fd332902b 100644 --- a/sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/main/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/quickpulse/filtering/FilteringConfiguration.java +++ b/sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/main/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/quickpulse/filtering/FilteringConfiguration.java @@ -42,11 +42,13 @@ public FilteringConfiguration() { validDocumentFilterConjunctionGroupInfos = new HashMap<>(); etag = ""; validProjectionInfo = new HashMap<>(); - logger.verbose("Initializing an empty live metrics filtering configuration - did not yet receive a configuration from ping or post."); + logger.verbose( + "Initializing an empty live metrics filtering configuration - did not yet receive a configuration from ping or post."); } public FilteringConfiguration(CollectionConfigurationInfo configuration) { - logger.verbose("About to parse and validate a new live metrics filtering configuration with etag {}", configuration.getETag()); + logger.verbose("About to parse and validate a new live metrics filtering configuration with etag {}", + configuration.getETag()); validDerivedMetricInfos = parseMetricFilterConfiguration(configuration); validDocumentFilterConjunctionGroupInfos = parseDocumentFilterConfiguration(configuration); etag = configuration.getETag(); @@ -92,7 +94,8 @@ public List getErrors() { .getDocumentFilterGroups()) { TelemetryType telemetryType = documentFilterGroupInfo.getTelemetryType(); FilterConjunctionGroupInfo filterGroup = documentFilterGroupInfo.getFilters(); - if (validator.isValidDocConjunctionGroupInfo(documentFilterGroupInfo, configuration.getETag(), documentStreamId)) { + if (validator.isValidDocConjunctionGroupInfo(documentFilterGroupInfo, configuration.getETag(), + documentStreamId)) { if (!result.containsKey(telemetryType)) { result.put(telemetryType, new HashMap<>()); } diff --git a/sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/main/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/quickpulse/filtering/RequestDataColumns.java b/sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/main/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/quickpulse/filtering/RequestDataColumns.java index d575d945c1ac1..62c84484c255b 100644 --- a/sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/main/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/quickpulse/filtering/RequestDataColumns.java +++ b/sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/main/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/quickpulse/filtering/RequestDataColumns.java @@ -3,6 +3,7 @@ package com.azure.monitor.opentelemetry.autoconfigure.implementation.quickpulse.filtering; +import com.azure.core.util.logging.ClientLogger; import com.azure.monitor.opentelemetry.autoconfigure.implementation.models.RequestData; import com.azure.monitor.opentelemetry.autoconfigure.implementation.quickpulse.swagger.models.FilterInfo; import com.azure.monitor.opentelemetry.autoconfigure.implementation.utils.FormattedDuration; @@ -16,18 +17,28 @@ public class RequestDataColumns implements TelemetryColumns { private final Map mapping = new HashMap<>(); private final CustomDimensions customDims; + private static ClientLogger logger = new ClientLogger(RequestDataColumns.class); + public RequestDataColumns(RequestData requestData) { customDims = new CustomDimensions(requestData.getProperties(), requestData.getMeasurements()); mapping.put(KnownRequestColumns.URL, requestData.getUrl()); mapping.put(KnownRequestColumns.SUCCESS, requestData.isSuccess()); - mapping.put(KnownRequestColumns.DURATION, - FormattedDuration.getDurationFromTelemetryItemDurationString(requestData.getDuration())); + + long durationMicroSec = FormattedDuration.getDurationFromTelemetryItemDurationString(requestData.getDuration()); + if (durationMicroSec == -1) { + logger.verbose("The provided timestamp could not be converted to microseconds: {}", + requestData.getDuration()); + } + + mapping.put(KnownRequestColumns.DURATION, durationMicroSec); mapping.put(KnownRequestColumns.NAME, requestData.getName()); int responseCode; try { responseCode = Integer.parseInt(requestData.getResponseCode()); } catch (NumberFormatException e) { responseCode = -1; + logger.verbose("The provided response code could not be converted to a numeric value: {}", + requestData.getResponseCode()); } mapping.put(KnownRequestColumns.RESPONSE_CODE, responseCode); } diff --git a/sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/main/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/quickpulse/filtering/Validator.java b/sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/main/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/quickpulse/filtering/Validator.java index 84adf44749621..c35090cf28fb6 100644 --- a/sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/main/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/quickpulse/filtering/Validator.java +++ b/sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/main/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/quickpulse/filtering/Validator.java @@ -34,28 +34,24 @@ public class Validator { private final List errors = new ArrayList<>(); - private static final ClientLogger logger = new ClientLogger(Validator.class); + private static final ClientLogger LOGGER = new ClientLogger(Validator.class); public boolean isValidDerivedMetricInfo(DerivedMetricInfo derivedMetricInfo, String etag) { TelemetryType telemetryType = TelemetryType.fromString(derivedMetricInfo.getTelemetryType()); if (!isValidTelemetryType(telemetryType)) { constructAndTrackCollectionConfigurationError( CollectionConfigurationErrorType.METRIC_TELEMETRY_TYPE_UNSUPPORTED, - "The user selected a telemetry type that the SDK does not support for Live Metrics Filtering. " + - "Telemetry type: " + telemetryType, - etag, - derivedMetricInfo.getId(), - true); + "The user selected a telemetry type that the SDK does not support for Live Metrics Filtering. " + + "Telemetry type: " + telemetryType, + etag, derivedMetricInfo.getId(), true); return false; } if (!isNotCustomMetricProjection(derivedMetricInfo.getProjection())) { constructAndTrackCollectionConfigurationError( CollectionConfigurationErrorType.FILTER_FAILURE_TO_CREATE_UNEXPECTED, - "The user selected a projection of Custom Metric, which this SDK does not support.", - etag, - derivedMetricInfo.getId(), - true); + "The user selected a projection of Custom Metric, which this SDK does not support.", etag, + derivedMetricInfo.getId(), true); return false; } @@ -72,10 +68,15 @@ public boolean isValidDerivedMetricInfo(DerivedMetricInfo derivedMetricInfo, Str return true; } - public boolean - isValidDocConjunctionGroupInfo(DocumentFilterConjunctionGroupInfo documentFilterConjunctionGroupInfo, String etag, String id) { + public boolean isValidDocConjunctionGroupInfo(DocumentFilterConjunctionGroupInfo documentFilterConjunctionGroupInfo, + String etag, String id) { TelemetryType telemetryType = documentFilterConjunctionGroupInfo.getTelemetryType(); if (!isValidTelemetryType(telemetryType)) { + constructAndTrackCollectionConfigurationError( + CollectionConfigurationErrorType.METRIC_TELEMETRY_TYPE_UNSUPPORTED, + "The user selected a telemetry type that the SDK does not support for Live Metrics Filtering. " + + "Telemetry type: " + telemetryType, + etag, id, false); return false; } @@ -114,8 +115,8 @@ public void constructAndTrackCollectionConfigurationError(CollectionConfiguratio errors.add(error); // This message gets logged once for every error we see on config validation. Config validation // only happens once per config change. - logger.verbose("{}. Due to this misconfiguration the {} rule will be ignored by the SDK.", - message, isDerivedMetricId ? "derived metric" : "document filter conjunction"); + LOGGER.verbose("{}. Due to this misconfiguration the {} rule will be ignored by the SDK.", message, + isDerivedMetricId ? "derived metric" : "document filter conjunction"); } private boolean isValidTelemetryType(TelemetryType telemetryType) { @@ -141,19 +142,14 @@ private boolean isValidFieldName(String fieldName, String etag, String id, boole if (fieldName.isEmpty()) { constructAndTrackCollectionConfigurationError( CollectionConfigurationErrorType.FILTER_FAILURE_TO_CREATE_UNEXPECTED, - "The user specified an empty field name for a filter.", - etag, - id, - isDerivedMetricId); + "The user specified an empty field name for a filter.", etag, id, isDerivedMetricId); return false; } if (fieldName.startsWith("CustomMetrics.")) { constructAndTrackCollectionConfigurationError( CollectionConfigurationErrorType.FILTER_FAILURE_TO_CREATE_UNEXPECTED, "The user selected a custom metric field name, but this SDK does not support filtering of custom metrics. ", - etag, - id, - isDerivedMetricId); + etag, id, isDerivedMetricId); return false; } return true; @@ -164,10 +160,7 @@ private boolean isValidPredicateAndComparand(FilterInfo filter, String etag, Str // It is possible to not type in a comparand and the service side to send us empty string. constructAndTrackCollectionConfigurationError( CollectionConfigurationErrorType.FILTER_FAILURE_TO_CREATE_UNEXPECTED, - "The user specified an empty comparand value for a filter.", - etag, - id, - isDerivedMetricId); + "The user specified an empty comparand value for a filter.", etag, id, isDerivedMetricId); return false; } else if (Filter.ANY_FIELD.equals(filter.getFieldName()) && !(filter.getPredicate().equals(PredicateType.CONTAINS) @@ -176,10 +169,9 @@ private boolean isValidPredicateAndComparand(FilterInfo filter, String etag, Str // .net classic behavior for this particular condition. constructAndTrackCollectionConfigurationError( CollectionConfigurationErrorType.FILTER_FAILURE_TO_CREATE_UNEXPECTED, - "The specified predicate is not supported for the fieldName * (Any field): " + filter.getPredicate().getValue(), - etag, - id, - isDerivedMetricId); + "The specified predicate is not supported for the fieldName * (Any field): " + + filter.getPredicate().getValue(), + etag, id, isDerivedMetricId); 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 @@ -188,10 +180,9 @@ private boolean isValidPredicateAndComparand(FilterInfo filter, String etag, Str if (Filter.getMicroSecondsFromFilterTimestampString(filter.getComparand()) == Long.MIN_VALUE) { constructAndTrackCollectionConfigurationError( CollectionConfigurationErrorType.FILTER_FAILURE_TO_CREATE_UNEXPECTED, - "The duration string provided by the user could not be parsed to a numeric value: " + filter.getComparand(), - etag, - id, - isDerivedMetricId); + "The duration string provided by the user could not be parsed to a numeric value: " + + filter.getComparand(), + etag, id, isDerivedMetricId); return false; } } else { // The service side not does not validate if resultcode or responsecode is a numeric value @@ -200,10 +191,9 @@ private boolean isValidPredicateAndComparand(FilterInfo filter, String etag, Str } catch (NumberFormatException e) { constructAndTrackCollectionConfigurationError( CollectionConfigurationErrorType.FILTER_FAILURE_TO_CREATE_UNEXPECTED, - "The result/response code specified by the user did not parse to a numeric value: " + filter.getComparand(), - etag, - id, - isDerivedMetricId); + "The result/response code specified by the user did not parse to a numeric value: " + + filter.getComparand(), + etag, id, isDerivedMetricId); return false; } } @@ -214,10 +204,9 @@ private boolean isValidPredicateAndComparand(FilterInfo filter, String etag, Str if (!validStringPredicates.contains(filter.getPredicate())) { constructAndTrackCollectionConfigurationError( CollectionConfigurationErrorType.FILTER_FAILURE_TO_CREATE_UNEXPECTED, - "The user selected a predicate (" + filter.getPredicate().getValue() + ") that is not supported for the field name " + filter.getFieldName(), - etag, - id, - isDerivedMetricId); + "The user selected a predicate (" + filter.getPredicate().getValue() + + ") that is not supported for the field name " + filter.getFieldName(), + etag, id, isDerivedMetricId); return false; } } diff --git a/sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/test/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/quickpulse/QuickPulseDataCollectorTests.java b/sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/test/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/quickpulse/QuickPulseDataCollectorTests.java index 886156a04869c..aa28c718bdb9d 100644 --- a/sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/test/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/quickpulse/QuickPulseDataCollectorTests.java +++ b/sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/test/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/quickpulse/QuickPulseDataCollectorTests.java @@ -256,9 +256,10 @@ void honorDefaultConfig() { // The default documents config asks to collect documents of the "Event" telemetry type // As the SDK does not collect the Event telemetry type for live metrics, we consider that part of the config invalid - List errors = counters.configErrors; + List errors = counters.configErrors; assertThat(errors.size()).isEqualTo(1); - assertThat(errors.get(0).getCollectionConfigurationErrorType()).isEqualTo(CollectionConfigurationErrorType.METRIC_TELEMETRY_TYPE_UNSUPPORTED); + assertThat(errors.get(0).getCollectionConfigurationErrorType()) + .isEqualTo(CollectionConfigurationErrorType.METRIC_TELEMETRY_TYPE_UNSUPPORTED); List documents = counters.documentList; diff --git a/sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/test/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/quickpulse/filteringTest/ValidatorTests.java b/sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/test/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/quickpulse/filteringTest/ValidatorTests.java index 4aafe77cc3d0b..3bdd6f7646ce6 100644 --- a/sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/test/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/quickpulse/filteringTest/ValidatorTests.java +++ b/sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/test/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/quickpulse/filteringTest/ValidatorTests.java @@ -15,6 +15,7 @@ import java.util.Arrays; import java.util.List; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -28,6 +29,7 @@ void rejectInvalidTelemetryTypesForDmi(TelemetryType telemetryType) { DerivedMetricInfo dmi = createDerivedMetricInfo("random-id", telemetryType.getValue(), AggregationType.SUM, AggregationType.SUM, DerivedMetricProjections.COUNT, filterGroups); assertFalse(validator.isValidDerivedMetricInfo(dmi, "random-etag")); + assertThat(validator.getErrors().size()).isEqualTo(1); } @ParameterizedTest @@ -36,6 +38,7 @@ void rejectInvalidTelemetryTypesForDocs(TelemetryType telemetryType) { Validator validator = new Validator(); DocumentFilterConjunctionGroupInfo docGroup = createDocGroupWithNoFilters(telemetryType); assertFalse(validator.isValidDocConjunctionGroupInfo(docGroup, "random-etag", "random-id")); + assertThat(validator.getErrors().size()).isEqualTo(1); } @ParameterizedTest @@ -46,6 +49,7 @@ void acceptValidTelemetryTypeForDmi(TelemetryType telemetryType) { DerivedMetricInfo dmi = createDerivedMetricInfo("random-id", telemetryType.getValue(), AggregationType.SUM, AggregationType.SUM, DerivedMetricProjections.COUNT, filterGroups); assertTrue(validator.isValidDerivedMetricInfo(dmi, "random-etag")); + assertThat(validator.getErrors().size()).isEqualTo(0); } @ParameterizedTest @@ -54,6 +58,7 @@ void acceptValidTelemetryTypeForDocs(TelemetryType telemetryType) { Validator validator = new Validator(); DocumentFilterConjunctionGroupInfo docGroup = createDocGroupWithNoFilters(telemetryType); assertTrue(validator.isValidDocConjunctionGroupInfo(docGroup, "random-etag", "random-id")); + assertThat(validator.getErrors().size()).isEqualTo(0); } @Test @@ -63,6 +68,7 @@ void rejectCustomMetricProjection() { DerivedMetricInfo dmi = createDerivedMetricInfo("random-id", TelemetryType.TRACE.getValue(), AggregationType.SUM, AggregationType.SUM, "CustomMetrics.property", filterGroups); assertFalse(validator.isValidDerivedMetricInfo(dmi, "random-etag")); + assertThat(validator.getErrors().size()).isEqualTo(1); } @Test @@ -73,6 +79,7 @@ void rejectCustomMetricFieldName() { DerivedMetricInfo dmi = createDerivedMetricInfo("random-id", TelemetryType.TRACE.getValue(), AggregationType.SUM, AggregationType.SUM, DerivedMetricProjections.COUNT, filterGroups); assertFalse(validator.isValidDerivedMetricInfo(dmi, "random-etag")); + assertThat(validator.getErrors().size()).isEqualTo(1); } @ParameterizedTest @@ -83,6 +90,7 @@ void rejectInvalidFiltersForDmi(FilterInfo filter) { AggregationType.SUM, AggregationType.SUM, DerivedMetricProjections.COUNT, filterGroups); Validator validator = new Validator(); assertFalse(validator.isValidDerivedMetricInfo(dmi, "random-etag")); + assertThat(validator.getErrors().size()).isEqualTo(1); } @ParameterizedTest @@ -91,6 +99,7 @@ void rejectInvalidFiltersForDocs(FilterInfo filter) { Validator validator = new Validator(); DocumentFilterConjunctionGroupInfo docGroup = createDocGroupWithOneFilter(TelemetryType.REQUEST, filter); assertFalse(validator.isValidDocConjunctionGroupInfo(docGroup, "random-etag", "random-id")); + assertThat(validator.getErrors().size()).isEqualTo(1); } @Test @@ -113,6 +122,8 @@ void rejectInvalidGroupWithMultipleFilters() { docGroup.setFilters(filterGroup); docGroup.setTelemetryType(TelemetryType.REQUEST); assertFalse(validator.isValidDocConjunctionGroupInfo(docGroup, "random-etag", "random-id")); + + assertThat(validator.getErrors().size()).isEqualTo(2); } @ParameterizedTest @@ -123,6 +134,7 @@ void acceptValidFiltersForDmi(FilterInfo filter) { AggregationType.SUM, AggregationType.SUM, DerivedMetricProjections.COUNT, filterGroups); Validator validator = new Validator(); assertTrue(validator.isValidDerivedMetricInfo(dmi, "random-etag")); + assertThat(validator.getErrors().size()).isEqualTo(0); } @ParameterizedTest @@ -131,6 +143,7 @@ void acceptValidFiltersForDocs(FilterInfo filter) { Validator validator = new Validator(); DocumentFilterConjunctionGroupInfo docGroup = createDocGroupWithOneFilter(TelemetryType.REQUEST, filter); assertTrue(validator.isValidDocConjunctionGroupInfo(docGroup, "random-etag", "random-id")); + assertThat(validator.getErrors().size()).isEqualTo(0); } private static List invalidTelemetryTypes() {