Compare commits

...
Author SHA1 Message Date
tomsun28 bf45de3435 Merge branch 'master' into fix-greptime-history 2025-05-22 23:29:39 +08:00
tomsun28 8674a93193 Merge branch 'master' into fix-greptime-history 2025-05-22 23:10:13 +08:00
tomsun28 0e46923a52 Merge branch 'master' into fix-greptime-history 2025-05-21 23:18:38 +08:00
Logic 2fd8848bf4 Merge branch 'master' into fix-greptime-history 2025-05-21 22:52:50 +08:00
Logic cbaba18ec4 feat(warehouse): improve GreptimeDB data storage and querying
- Update table name generation to use monitor ID instead of app name
- Prefix table names with "hzb" to avoid potential conflicts
- Fix history data querying by using correct table name
- Improve error handling in history data querying
- Update Prometheus collector to change field name from "value" to "metric_value"
2025-05-21 22:46:02 +08:00
Logic 383be0732b feat(warehouse): improve GreptimeDB data storage and querying
- Update table name generation to use monitor ID instead of app name
- Prefix table names with "hzb" to avoid potential conflicts
- Fix history data querying by using correct table name
- Improve error handling in history data querying
- Update Prometheus collector to change field name from "value" to "metric_value"
2025-05-21 22:38:24 +08:00
2 changed files with 9 additions and 7 deletions
@@ -179,7 +179,7 @@ public class PrometheusAutoCollectImpl {
builder.addField(CollectRep.Field.newBuilder().setName(label.getName())
.setType(CommonConstants.TYPE_STRING).setLabel(true).build());
});
builder.addField(CollectRep.Field.newBuilder().setName("value")
builder.addField(CollectRep.Field.newBuilder().setName("metric_value")
.setType(CommonConstants.TYPE_NUMBER).setLabel(false).build());
}
Map<String, String> labelMap = metric.getLabels()
@@ -126,7 +126,7 @@ public class GreptimeDbDataStorage extends AbstractHistoryDataStorage {
return;
}
String monitorId = String.valueOf(metricsData.getId());
String tableName = getTableName(metricsData.getApp(), metricsData.getMetrics());
String tableName = getTableName(metricsData.getId(), metricsData.getMetrics());
TableSchema.Builder tableSchemaBuilder = TableSchema.newBuilder(tableName);
tableSchemaBuilder.addTag("instance", DataType.String)
@@ -194,7 +194,7 @@ public class GreptimeDbDataStorage extends AbstractHistoryDataStorage {
@Override
public Map<String, List<Value>> getHistoryMetricData(Long monitorId, String app, String metrics, String metric,
String label, String history) {
String name = getTableName(app, metrics);
String name = getTableName(monitorId, metrics);
String timeSeriesSelector = LABEL_KEY_NAME + "=\"" + name + "\""
+ "," + LABEL_KEY_INSTANCE + "=\"" + monitorId + "\"";
if (!CommonConstants.PROMETHEUS.equals(app)) {
@@ -227,6 +227,7 @@ public class GreptimeDbDataStorage extends AbstractHistoryDataStorage {
log.error("history time error: {}. use default: 6h", e.getMessage());
start = now.minus(6, ChronoUnit.HOURS).getEpochSecond();
}
long end = now.getEpochSecond();
String step = "60s";
if (end - start < Duration.ofDays(7).getSeconds() && end - start > Duration.ofDays(1).getSeconds()) {
@@ -234,13 +235,15 @@ public class GreptimeDbDataStorage extends AbstractHistoryDataStorage {
} else if (end - start >= Duration.ofDays(7).getSeconds()) {
step = "4h";
}
HttpEntity<Void> httpEntity = new HttpEntity<>(headers);
URI uri = UriComponentsBuilder.fromHttpUrl(greptimeProperties.httpEndpoint() + QUERY_RANGE_PATH)
URI uri = UriComponentsBuilder.fromUriString(greptimeProperties.httpEndpoint() + QUERY_RANGE_PATH)
.queryParam(URLEncoder.encode("query", StandardCharsets.UTF_8), URLEncoder.encode("{" + timeSeriesSelector + "}", StandardCharsets.UTF_8))
.queryParam("start", start)
.queryParam("end", end)
.queryParam("step", step)
.build(true).toUri();
ResponseEntity<PromQlQueryContent> responseEntity = restTemplate.exchange(uri,
HttpMethod.GET, httpEntity, PromQlQueryContent.class);
if (responseEntity.getStatusCode().is2xxSuccessful()) {
@@ -258,7 +261,6 @@ public class GreptimeDbDataStorage extends AbstractHistoryDataStorage {
for (Object[] valueArr : content.getValues()) {
long timestamp = ((Double) valueArr[0]).longValue();
String value = new BigDecimal(String.valueOf(valueArr[1])).setScale(4, RoundingMode.HALF_UP).stripTrailingZeros().toPlainString();
// read timestamp here is s unit
valueList.add(new Value(value, timestamp * 1000));
}
}
@@ -273,8 +275,8 @@ public class GreptimeDbDataStorage extends AbstractHistoryDataStorage {
return instanceValuesMap;
}
private String getTableName(String app, String metrics) {
return app + SPILT + metrics;
private String getTableName(Long monitorId, String metrics) {
return "hzb" + SPILT + monitorId + SPILT + metrics;
}
@Override