-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Live Metrics Filtering: Part 1 of 5 - port filtering functionality (#…
…43040) * swagger * experimenting with ping api, not done yet * experimental code, post not done, not tested * initial draft and test changes * changes to build point * fix some bugs, fix some tests * cleanup & test fixes * minor changes I forgot to push * a slight restructuring and adding yaml/licence headers * Migrate changes to the new autoconfigure module (#42864) * move * markdown * check * delete unused files and remove version from yaml * starting to port stuff, incomplete * more code, not done * updating some comments according to pr review * starting to add test, test is failing * PR comment * trying to fix build error * minor * hopefully this should fix build analyze step errors * added custom dim test, need to debug * adding more tests * final changes * pr comment & fixing CI build errors * pr comments * code refactor; did not use TimeUnit as that led to some expected behavior --------- Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
- Loading branch information
Showing
16 changed files
with
1,059 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 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
31 changes: 31 additions & 0 deletions
31
...tor/opentelemetry/autoconfigure/implementation/quickpulse/filtering/CustomDimensions.java
This file contains 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,31 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
package com.azure.monitor.opentelemetry.autoconfigure.implementation.quickpulse.filtering; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class CustomDimensions { | ||
private Map<String, String> customDimensions; | ||
|
||
public CustomDimensions() { | ||
this.customDimensions = new HashMap<String, String>(); | ||
} | ||
|
||
public void setCustomDimensions(Map<String, String> customDimensions, Map<String, Double> customMeasurements) { | ||
Map<String, String> resultMap = new HashMap<>(); | ||
if (customDimensions != null) { | ||
resultMap.putAll(customDimensions); | ||
} | ||
if (customMeasurements != null) { | ||
for (Map.Entry<String, Double> cmEntry : customMeasurements.entrySet()) { | ||
resultMap.put(cmEntry.getKey(), cmEntry.getValue().toString()); | ||
} | ||
} | ||
this.customDimensions = resultMap; | ||
} | ||
|
||
public Map<String, String> getCustomDimensions() { | ||
return this.customDimensions; | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
...pentelemetry/autoconfigure/implementation/quickpulse/filtering/DependencyDataColumns.java
This file contains 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,76 @@ | ||
// 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.models.RemoteDependencyData; | ||
import com.azure.monitor.opentelemetry.autoconfigure.implementation.utils.FormattedDuration; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
// Casing of private fields is to match the names of fields passed down via filtering configuration | ||
public class DependencyDataColumns implements TelemetryColumns { | ||
private final CustomDimensions customDims; | ||
private final Map<String, Object> mapping = new HashMap<>(); | ||
|
||
public DependencyDataColumns(RemoteDependencyData rdData) { | ||
customDims = new CustomDimensions(); | ||
customDims.setCustomDimensions(rdData.getProperties(), rdData.getMeasurements()); | ||
mapping.put(KnownDependencyColumns.TARGET, rdData.getTarget()); | ||
mapping.put(KnownDependencyColumns.DURATION, | ||
FormattedDuration.getDurationFromTelemetryItemDurationString(rdData.getDuration())); | ||
mapping.put(KnownDependencyColumns.SUCCESS, rdData.isSuccess()); | ||
mapping.put(KnownDependencyColumns.NAME, rdData.getName()); | ||
int resultCode; | ||
try { | ||
resultCode = Integer.parseInt(rdData.getResultCode()); | ||
} catch (NumberFormatException e) { | ||
resultCode = -1; | ||
} | ||
mapping.put(KnownDependencyColumns.RESULT_CODE, resultCode); | ||
mapping.put(KnownDependencyColumns.TYPE, rdData.getType()); | ||
mapping.put(KnownDependencyColumns.DATA, rdData.getData()); | ||
} | ||
|
||
// To be used for tests only | ||
public DependencyDataColumns(String target, long duration, boolean success, String name, int resultCode, | ||
String type, String data, Map<String, String> dims, Map<String, Double> measurements) { | ||
customDims = new CustomDimensions(); | ||
customDims.setCustomDimensions(dims, measurements); | ||
mapping.put(KnownDependencyColumns.TARGET, target); | ||
mapping.put(KnownDependencyColumns.DURATION, duration); | ||
mapping.put(KnownDependencyColumns.SUCCESS, success); | ||
mapping.put(KnownDependencyColumns.NAME, name); | ||
mapping.put(KnownDependencyColumns.RESULT_CODE, resultCode); | ||
mapping.put(KnownDependencyColumns.TYPE, type); | ||
mapping.put(KnownDependencyColumns.DATA, data); | ||
} | ||
|
||
public <T> T getFieldValue(String fieldName, Class<T> type) { | ||
return type.cast(mapping.get(fieldName)); | ||
} | ||
|
||
public Map<String, String> getCustomDimensions() { | ||
return this.customDims.getCustomDimensions(); | ||
} | ||
|
||
public List<String> getAllFieldValuesAsString() { | ||
List<String> result = new ArrayList<>(); | ||
for (Object value : mapping.values()) { | ||
if (value instanceof String) { | ||
result.add((String) value); | ||
} else if (value instanceof Integer) { | ||
result.add(((Integer) value).toString()); | ||
} else if (value instanceof Long) { | ||
result.add(((Long) value).toString()); | ||
} else { // boolean | ||
result.add(((Boolean) value).toString()); | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
} |
55 changes: 55 additions & 0 deletions
55
...opentelemetry/autoconfigure/implementation/quickpulse/filtering/ExceptionDataColumns.java
This file contains 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,55 @@ | ||
// 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.models.TelemetryExceptionData; | ||
import com.azure.monitor.opentelemetry.autoconfigure.implementation.models.TelemetryExceptionDetails; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
// Casing of private fields is to match the names of fields passed down via filtering configuration | ||
public class ExceptionDataColumns implements TelemetryColumns { | ||
|
||
private final CustomDimensions customDims; | ||
|
||
private final Map<String, Object> mapping = new HashMap<>(); | ||
|
||
public ExceptionDataColumns(TelemetryExceptionData exceptionData) { | ||
customDims = new CustomDimensions(); | ||
customDims.setCustomDimensions(exceptionData.getProperties(), exceptionData.getMeasurements()); | ||
List<TelemetryExceptionDetails> details = exceptionData.getExceptions(); | ||
mapping.put(KnownExceptionColumns.MESSAGE, | ||
details != null && !details.isEmpty() ? details.get(0).getMessage() : ""); | ||
mapping.put(KnownExceptionColumns.STACK, | ||
details != null && !details.isEmpty() ? details.get(0).getStack() : ""); | ||
} | ||
|
||
// To be used in tests only | ||
public ExceptionDataColumns(String message, String stackTrace, Map<String, String> dims, | ||
Map<String, Double> measurements) { | ||
customDims = new CustomDimensions(); | ||
customDims.setCustomDimensions(dims, measurements); | ||
mapping.put(KnownExceptionColumns.MESSAGE, message); | ||
mapping.put(KnownExceptionColumns.STACK, stackTrace); | ||
} | ||
|
||
public Map<String, String> getCustomDimensions() { | ||
return this.customDims.getCustomDimensions(); | ||
} | ||
|
||
public <T> T getFieldValue(String fieldName, Class<T> type) { | ||
return type.cast(mapping.get(fieldName)); | ||
} | ||
|
||
public List<String> getAllFieldValuesAsString() { | ||
List<String> result = new ArrayList<>(); | ||
for (Object value : mapping.values()) { | ||
result.add((String) value); | ||
} | ||
return result; | ||
} | ||
} |
Oops, something went wrong.