Skip to content

Commit

Permalink
[#12019] Add logic to prevent error when metadata is missing.
Browse files Browse the repository at this point in the history
  • Loading branch information
minwoo-jung committed Feb 5, 2025
1 parent 4f6700a commit ac8354d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
@Service
public class OtlpMetricWebServiceImpl implements OtlpMetricWebService {
private final Logger logger = LogManager.getLogger(this.getClass());
private static final String EMPTY_STRING = "";

@Deprecated
public static final OtlpChartView EMPTY_CHART = OtlpChartViewBuilder.EMPTY_CHART_VIEW;
@Deprecated
Expand Down Expand Up @@ -138,6 +140,10 @@ private OtlpMetricChartQueryParameter setupQueryParameter(OtlpMetricChartQueryPa
public MetricData getMetricData(String tenantId, String serviceName, String applicationName, String agentId, String metricGroupName, String metricName, PrimaryForFieldAndTagRelation primaryForFieldAndTagRelation, List<String> tagGroupList, List<String> fieldNameList, ChartType chartType, AggregationFunction aggregationFunction, TimeWindow timeWindow) {
List<FieldAttribute> fields = otlpMetricDao.getFields(serviceName, applicationName, agentId, metricGroupName, metricName, tagGroupList, fieldNameList);

if(fields.size() == 0) {
return createEmptyMetricData(timeWindow, chartType);
}

OtlpMetricDataQueryParameter.Builder builder =
new OtlpMetricDataQueryParameter.Builder()
.setServiceName(serviceName)
Expand Down Expand Up @@ -175,6 +181,10 @@ public MetricData getMetricData(String tenantId, String serviceName, String appl
return metricData;
}

private MetricData createEmptyMetricData(TimeWindow timeWindow, ChartType chartType) {
return new MetricData(TimeUtils.createTimeStampList(timeWindow), chartType, EMPTY_STRING, "There is no metadata for the metric query.");
}

private String getLegendName(OtlpMetricDataQueryParameter chartQueryParameter, PrimaryForFieldAndTagRelation primaryForFieldAndTagRelation) {
switch (primaryForFieldAndTagRelation) {
case FIELD:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ public class MetricDataView {
private ChartType chartType;
private String unit;
private List<MetricValue> metricValueList;
private final String message;

public MetricDataView(MetricData metricData) {
this.timestamp = metricData.getTimestampList();
this.chartType = metricData.getChartType();
this.unit = metricData.getUnit();
this.metricValueList = metricData.getMetricValueList();
this.message = metricData.getMessage();
}

public List<Long> getTimestamp() {
Expand All @@ -56,6 +58,10 @@ public List<MetricValueView> getMetricValues() {
return metricValueList.stream().map(MetricValueView::new).collect(Collectors.toList());
}

public String getMessage() {
return message;
}

public static class MetricValueView {
private String legendName;
private List<Number> valueList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,23 @@
* @author minwoo-jung
*/
public class MetricData {
private final static String EMPTY_MESSAEG = "";
private List<Long> timestampList;
private final ChartType chartType;
private final String unit;
private final List<MetricValue> metricValueList;
private final String message;

public MetricData(List<Long> timestampList, ChartType chartType, String unit) {
public MetricData(List<Long> timestampList, ChartType chartType, String unit, String message) {
this.timestampList = timestampList;
this.chartType = chartType;
this.unit = unit;
this.metricValueList = new ArrayList<>();
this.message = message;
}

public MetricData(List<Long> timestampList, ChartType chartType, String unit) {
this(timestampList, chartType, unit, EMPTY_MESSAEG);
}

public void addMetricValue(MetricValue metricValue) {
Expand All @@ -57,4 +64,8 @@ public String getUnit() {
public List<MetricValue> getMetricValueList() {
return metricValueList;
}

public String getMessage() {
return message;
}
}

0 comments on commit ac8354d

Please sign in to comment.