Skip to content
Open
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
5 changes: 5 additions & 0 deletions hertzbeat-manager/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@ warehouse:
password: root
expire-time: '30d'
replication: 1
alibabacloud-es:
enabled: false
url: http://127.0.01:9200
username: elastic
password: elastic
# store real-time metrics data, enable only one below
real-time:
memory:
Expand Down
7 changes: 7 additions & 0 deletions hertzbeat-warehouse/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,12 @@
<artifactId>snappy-java</artifactId>
<version>${snappy-java.version}</version>
</dependency>

<dependency>
<groupId>io.searchbox</groupId>
<artifactId>jest</artifactId>
<version>${io.searchbox.version}</version>
</dependency>

</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public interface WarehouseConstants {
* History database name.
*/
interface HistoryName {

String ALIBABACLOUD_ES = "alibabacloud-es";

String GREPTIME = "greptime";

String INFLUXDB = "influxdb";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.hertzbeat.warehouse.db;

import lombok.extern.slf4j.Slf4j;
import org.apache.hertzbeat.warehouse.store.history.tsdb.alibabacloud.AlibabaCloudEsProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

/**
* query executor for alibaba cloud elasticsearch
*/
@Slf4j
@Component
@ConditionalOnProperty(prefix = "warehouse.store.alibabacloud-es", name = "enabled", havingValue = "true")
public class AlibabaCloudEsPromqlQueryExecutor extends PromqlQueryExecutor {

private static final String QUERY_PATH = "/_time_stream/prom/%s/query";
private static final String QUERY_RANGE_PATH = "/_time_stream/prom/%s/query_range";

private final String datasource;

AlibabaCloudEsPromqlQueryExecutor(AlibabaCloudEsProperties properties, RestTemplate restTemplate) {
super(restTemplate, new HttpPromqlProperties(properties.url(), properties.username(), properties.password(),
String.format(QUERY_PATH, properties.database()), String.format(QUERY_RANGE_PATH, properties.database())));
this.datasource = properties.database();
}

@Override
public String getDatasource() {
return datasource;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,13 @@ public abstract class PromqlQueryExecutor implements QueryExecutor {
protected record HttpPromqlProperties(
String url,
String username,
String password
String password,
String queryPath,
String queryRangePath
) {
public HttpPromqlProperties(String url, String username, String password) {
this(url, username, password, QUERY_PATH, QUERY_RANGE_PATH);
}
}

@Override
Expand All @@ -98,7 +103,7 @@ public List<Map<String, Object>> execute(String queryString) {
}
HttpEntity<Void> httpEntity = new HttpEntity<>(headers);

UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromUriString(httpPromqlProperties.url + QUERY_PATH);
UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromUriString(httpPromqlProperties.url + httpPromqlProperties.queryPath);
uriComponentsBuilder.queryParam(HTTP_QUERY_PARAM, queryString);
URI uri = uriComponentsBuilder.build().toUri();
ResponseEntity<PromQlQueryContent> responseEntity = restTemplate.exchange(uri,
Expand Down Expand Up @@ -150,14 +155,14 @@ public DatasourceQueryData query(DatasourceQuery datasourceQuery) {
HttpEntity<Void> httpEntity = new HttpEntity<>(headers);
URI uri;
if (datasourceQuery.getTimeType().equals(RANGE)) {
uri = UriComponentsBuilder.fromUriString(httpPromqlProperties.url() + QUERY_RANGE_PATH)
uri = UriComponentsBuilder.fromUriString(httpPromqlProperties.url() + httpPromqlProperties.queryRangePath)
.queryParam(HTTP_QUERY_PARAM, datasourceQuery.getExpr())
.queryParam(HTTP_START_PARAM, datasourceQuery.getStart())
.queryParam(HTTP_END_PARAM, datasourceQuery.getEnd())
.queryParam(HTTP_STEP_PARAM, datasourceQuery.getStep())
.build().toUri();
} else if (datasourceQuery.getTimeType().equals(INSTANT)) {
uri = UriComponentsBuilder.fromUriString(httpPromqlProperties.url() + QUERY_PATH)
uri = UriComponentsBuilder.fromUriString(httpPromqlProperties.url() + httpPromqlProperties.queryPath)
.queryParam(HTTP_QUERY_PARAM, datasourceQuery.getExpr())
.build().toUri();
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.hertzbeat.warehouse.store.history.tsdb.alibabacloud;

/**
* Constants for AlibabaCloud Elasticsearch data storage
*/
public final class AlibabaCloudEsConstants {

private AlibabaCloudEsConstants() {

}

// Elasticsearch specific constants
public static final String TIME_STREAM = "_time_stream";
public static final String INDEX_TYPE = "_doc";
public static final String QUERY_RANGE_PATH = TIME_STREAM + "/prom/%s/query_range";

// Label keys
public static final String LABEL_KEY_HOST = "host";
public static final String LABEL_KEY_INSTANCE = "instance";
public static final String LABEL_KEY_JOB = "job";
public static final String LABEL_KEY_NAME = "__name__";

// Separators
public static final String SPLIT = "_";

// Error messages
public static final String ES_INIT_ERROR_MSG = """

\t---------------Alibaba Cloud Elasticsearch Init Failed---------------
\t--------------Please Config Alibaba Cloud Elasticsearch--------------
\t----------Can Not Use Metric History Now----------
""";
}
Loading
Loading