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

[#12019] Add logic to prevent error when metadata is missing. #12020

Merged
merged 1 commit into from
Feb 5, 2025
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
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;
}
}
Loading