Skip to content
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

Fix NPE in metrics query when the metric is not exist. #10980

Merged
merged 3 commits into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions .github/workflows/skywalking.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -750,8 +750,8 @@ jobs:
matrix:
analyzer: [k8s-mesh, mx-mesh]
versions:
- istio: 1.7.1
kubernetes: 18
#- istio: 1.7.1
# kubernetes: 18
- istio: 1.8.2
kubernetes: 19
- istio: 1.9.1
Expand Down
3 changes: 2 additions & 1 deletion docs/en/changes/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
* Remove patterns from `HttpUriRecognitionService#feedRawData` and add max 10 candidates of raw URIs for each pattern.
* Add component ID for WebSphere.
* Fix AI Pipeline uri caching NullPointer and IllegalArgument Exceptions.
* Fix `NPE` in metrics query when the metric is not exist.

#### UI

* Fix metric name `browser_app_error_rate` in `Browser-Root` dashboard.

#### Documentation

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,19 +137,22 @@ public NullableValue readNullableMetricsValue(MetricsCondition condition, Durati
* Read time-series values in the duration of required metrics
*/
public MetricsValues readMetricsValues(MetricsCondition condition, Duration duration) throws IOException {
if (!condition.senseScope() || !condition.getEntity().isValid()) {
boolean hasScope = condition.senseScope();
if (!hasScope || !condition.getEntity().isValid()) {
final List<PointOfTime> pointOfTimes = duration.assembleDurationPoints();
String entityId = "UNKNOWN_METRIC_NAME";
if (hasScope) {
entityId = "ILLEGAL_ENTITY";
}
MetricsValues values = new MetricsValues();
pointOfTimes.forEach(pointOfTime -> {
String id = pointOfTime.id(
condition.getEntity().isValid() ? condition.getEntity().buildId() : "ILLEGAL_ENTITY"
);
for (PointOfTime pointOfTime : pointOfTimes) {
String id = pointOfTime.id(entityId);
final KVInt kvInt = new KVInt();
kvInt.setId(id);
kvInt.setValue(0);
kvInt.setEmptyValue(true);
values.getValues().addKVInt(kvInt);
});
}
return values;
}
return getMetricsQueryService().readMetricsValues(condition, duration);
Expand All @@ -173,25 +176,27 @@ public List<SelectedRecord> sortMetrics(TopNCondition condition, Duration durati
public List<MetricsValues> readLabeledMetricsValues(MetricsCondition condition,
List<String> labels,
Duration duration) throws IOException {
if (!condition.senseScope() || !condition.getEntity().isValid()) {
boolean hasScope = condition.senseScope();
if (!hasScope || !condition.getEntity().isValid()) {
final List<PointOfTime> pointOfTimes = duration.assembleDurationPoints();

String entityId = "UNKNOWN_METRIC_NAME";
if (hasScope) {
entityId = "ILLEGAL_ENTITY";
}
List<MetricsValues> labeledValues = new ArrayList<>(labels.size());
labels.forEach(label -> {
for (String label : labels) {
MetricsValues values = new MetricsValues();
pointOfTimes.forEach(pointOfTime -> {
String id = pointOfTime.id(
condition.getEntity().isValid() ? condition.getEntity().buildId() : "ILLEGAL_ENTITY"
);
for (PointOfTime pointOfTime : pointOfTimes) {
String id = pointOfTime.id(entityId);
final KVInt kvInt = new KVInt();
kvInt.setId(id);
kvInt.setValue(0);
kvInt.setEmptyValue(true);
values.getValues().addKVInt(kvInt);
});
}
values.setLabel(label);
labeledValues.add(values);
});
}
return labeledValues;
}
return getMetricsQueryService().readLabeledMetricsValues(condition, labels, duration);
Expand All @@ -210,18 +215,21 @@ public List<MetricsValues> readLabeledMetricsValues(MetricsCondition condition,
* </pre>
*/
public HeatMap readHeatMap(MetricsCondition condition, Duration duration) throws IOException {
if (!condition.senseScope() || !condition.getEntity().isValid()) {
boolean hasScope = condition.senseScope();
if (!hasScope || !condition.getEntity().isValid()) {
DataTable emptyData = new DataTable();
emptyData.put("0", 0L);
final String rawdata = emptyData.toStorageData();
final HeatMap heatMap = new HeatMap();
final List<PointOfTime> pointOfTimes = duration.assembleDurationPoints();
pointOfTimes.forEach(pointOfTime -> {
String id = pointOfTime.id(
condition.getEntity().isValid() ? condition.getEntity().buildId() : "ILLEGAL_ENTITY"
);
String entityId = "UNKNOWN_METRIC_NAME";
if (hasScope) {
entityId = "ILLEGAL_ENTITY";
}
for (PointOfTime pointOfTime : pointOfTimes) {
String id = pointOfTime.id(entityId);
heatMap.buildColumn(id, rawdata, 0);
});
}
return heatMap;
}
return getMetricsQueryService().readHeatMap(condition, duration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
},
"metrics": [
"browser_app_pv",
"browser_app_error_rage"
"browser_app_error_rate"
],
"metricTypes": [
"readMetricsValues",
Expand Down
Loading