Skip to content

Commit

Permalink
support push style for multiple messages (#1292)
Browse files Browse the repository at this point in the history
  • Loading branch information
leo-934 authored Oct 22, 2023
1 parent e18e019 commit 77ddae9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,6 @@ private HttpUriRequest createHttpRequest(PushProtocol pushProtocol, Long monitor
}

private void parseResponse(CollectRep.MetricsData.Builder builder, String resp, Metrics metric) {
// Map<String, Object> jsonMap = JsonUtil.fromJson(resp, new TypeReference<Map<String, Object>>() {
// });
// if (jsonMap == null) {
// throw new NullPointerException("parse result is null");
// }
Message<PushMetricsDto> msg = JsonUtil.fromJson(resp, new TypeReference<Message<PushMetricsDto>>() {
});
if (msg == null) {
Expand All @@ -153,13 +148,19 @@ private void parseResponse(CollectRep.MetricsData.Builder builder, String resp,
throw new NullPointerException("parse result is null");
}
for (PushMetricsDto.Metrics pushMetrics : pushMetricsDto.getMetricsList()) {
List<String> metricColumn = new ArrayList<>();
for (Metrics.Field field : metric.getFields()) {
metricColumn.add(pushMetrics.getMetrics().get(field.getField()));
List<CollectRep.ValueRow> rows = new ArrayList<>();
for (Map<String, String> metrics : pushMetrics.getMetrics()) {
List<String> metricColumn = new ArrayList<>();
for (Metrics.Field field : metric.getFields()) {
metricColumn.add(metrics.get(field.getField()));
}
CollectRep.ValueRow valueRow = CollectRep.ValueRow.newBuilder()
.addAllColumns(metricColumn).build();
rows.add(valueRow);
}
CollectRep.ValueRow.Builder valueRowBuilder = CollectRep.ValueRow.newBuilder()
.addAllColumns(metricColumn);
builder.addValues(valueRowBuilder.build());


builder.addAllValues(rows);
}
builder.setTime(System.currentTimeMillis());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ public PushMetricsDto() {
public static class Metrics {
private long monitorId;
private Long time;
private Map<String, String> metrics;
private List<Map<String, String>> metrics;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void pushMetricsData(PushMetricsDto pushMetricsDto) throws RuntimeExcepti
long monitorId = metrics.getMonitorId();
metrics.setTime(curTime);

if (!monitorIdCache.containsKey(monitorId) && (monitorIdCache.containsKey(monitorId) && curTime > monitorIdCache.get(monitorId) + cacheTimeout)) {
if (!monitorIdCache.containsKey(monitorId) || (monitorIdCache.containsKey(monitorId) && curTime > monitorIdCache.get(monitorId) + cacheTimeout)) {
Optional<Monitor> queryOption = monitorDao.findById(monitorId);
if (queryOption.isEmpty()) {
monitorIdCache.remove(monitorId);
Expand Down Expand Up @@ -103,7 +103,7 @@ public PushMetricsDto getPushMetricData(final Long monitorId, final Long time) {
if (pushMetrics == null || pushMetrics.getMetrics() == null) {
return pushMetricsDto;
}
Map<String, String> jsonMap = JsonUtil.fromJson(pushMetrics.getMetrics(), new TypeReference<Map<String, String>>() {
List<Map<String, String>> jsonMap = JsonUtil.fromJson(pushMetrics.getMetrics(), new TypeReference<List<Map<String, String>>>() {
});
metrics = PushMetricsDto.Metrics.builder().monitorId(monitorId).metrics(jsonMap).time(pushMetrics.getTime()).build();
lastPushMetrics.put(monitorId, metrics);
Expand All @@ -114,11 +114,10 @@ public PushMetricsDto getPushMetricData(final Long monitorId, final Long time) {
}
}
if (time > metrics.getTime()) {
// return void because time param is invalid
return pushMetricsDto;
}
pushMetricsDto.getMetricsList().add(metrics);
// 目前先不删除
// metricsDao.deleteAllById(toBeDelMetricsId);
return pushMetricsDto;
}

Expand Down

0 comments on commit 77ddae9

Please sign in to comment.