Skip to content

Commit

Permalink
logging and testing
Browse files Browse the repository at this point in the history
  • Loading branch information
harsimar committed Jan 9, 2025
1 parent 73f4cc7 commit 0c5aae9
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<CollectionConfigurationInfo> 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
Expand All @@ -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());
}
Expand Down Expand Up @@ -140,11 +140,11 @@ private void onPostError(long sendTime) {

private String printListOfMonitoringPoints(List<MonitoringDataPoint> 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());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
// 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;
import java.util.Map;

public class CustomDimensions {
private final Map<String, String> customDimensions;
private static ClientLogger logger = new ClientLogger(CustomDimensions.class);

public CustomDimensions(Map<String, String> customDimensions, Map<String, Double> customMeasurements) {
Map<String, String> resultMap = new HashMap<>();
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,21 @@ 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());
int resultCode;
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class DerivedMetricProjections {
public static final String COUNT = "Count()";
private final Map<String, DerivedMetricAggregation> derivedMetricValues = new HashMap<>();

private static final ClientLogger logger = new ClientLogger(DerivedMetricProjections.class);
private static final ClientLogger LOGGER = new ClientLogger(DerivedMetricProjections.class);

public DerivedMetricProjections(Map<String, AggregationType> projectionInfo) {
for (Map.Entry<String, AggregationType> entry : projectionInfo.entrySet()) {
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -92,7 +94,8 @@ public List<CollectionConfigurationError> 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<>());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -16,18 +17,28 @@ public class RequestDataColumns implements TelemetryColumns {
private final Map<String, Object> 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);
}
Expand Down
Loading

0 comments on commit 0c5aae9

Please sign in to comment.