Skip to content

Commit

Permalink
feat: add MetricRemoteWriteConfig. (#129)
Browse files Browse the repository at this point in the history
* feat: add MetricRemoteWriteConfig.

* fix: refine import.

* fix: refine metricsConfig test.

* fix: add MetricRemoteWriteConfig replica_field and replica_timeout_seconds.
  • Loading branch information
Mr-Xzz authored Dec 5, 2023
1 parent 98618d1 commit 83bde72
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package com.aliyun.openservices.log.common;

import com.alibaba.fastjson.annotation.JSONField;

/**
* @author xzz
*/
public class MetricRemoteWriteConfig {

@JSONField(name = "enable")
private boolean enable;

@JSONField(name = "history_interval")
private int historyInterval;

@JSONField(name = "future_interval")
private int futureInterval;

@JSONField(name = "replica_field")
private String replicaField;

@JSONField(name = "replica_timeout_seconds")
private int replicaTimeoutSeconds;

public int getHistoryInterval() {
return historyInterval;
}

public void setHistoryInterval(int historyInterval) {
this.historyInterval = historyInterval;
}

public int getFutureInterval() {
return futureInterval;
}

public void setFutureInterval(int futureInterval) {
this.futureInterval = futureInterval;
}

public boolean isEnable() {
return enable;
}

public void setEnable(boolean enable) {
this.enable = enable;
}

public String getReplicaField() {
return replicaField;
}

public void setReplicaField(String replicaField) {
this.replicaField = replicaField;
}

public int getReplicaTimeoutSeconds() {
return replicaTimeoutSeconds;
}

public void setReplicaTimeoutSeconds(int replicaTimeoutSeconds) {
this.replicaTimeoutSeconds = replicaTimeoutSeconds;
}

@Override
public boolean equals(Object o) {
if (this == o) {return true;}
if (o == null || getClass() != o.getClass()) {return false;}

MetricRemoteWriteConfig that = (MetricRemoteWriteConfig) o;

if (enable != that.enable) {return false;}
if (historyInterval != that.historyInterval) {return false;}
if (futureInterval != that.futureInterval) {return false;}
if (replicaTimeoutSeconds != that.replicaTimeoutSeconds) {return false;}
return replicaField != null ? replicaField.equals(that.replicaField) : that.replicaField == null;
}

@Override
public int hashCode() {
int result = (enable ? 1 : 0);
result = 31 * result + historyInterval;
result = 31 * result + futureInterval;
result = 31 * result + (replicaField != null ? replicaField.hashCode() : 0);
result = 31 * result + replicaTimeoutSeconds;
return result;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.aliyun.openservices.log.common;

import java.io.Serializable;

import com.alibaba.fastjson.annotation.JSONField;

import java.io.Serializable;

/**
* @author xizongzheng.xzz
*/
Expand All @@ -21,6 +21,9 @@ public class MetricsConfig implements Serializable {
@JSONField(name = "pushdown_config")
private MetricPushdownConfig pushdownConfig;

@JSONField(name = "remote_write_config")
private MetricRemoteWriteConfig remoteWriteConfig;

public MetricsConfig(MetricDownSamplingConfig downSamplingConfig) {
this.downSamplingConfig = downSamplingConfig;
}
Expand All @@ -37,6 +40,10 @@ public MetricsConfig(MetricPushdownConfig pushdownConfig) {
this.pushdownConfig = pushdownConfig;
}

public MetricsConfig(MetricRemoteWriteConfig remoteWriteConfig) {
this.remoteWriteConfig = remoteWriteConfig;
}

public MetricsConfig(MetricParallelConfig parallelConfig, MetricQueryCacheConfig queryCacheConfig) {
this.parallelConfig = parallelConfig;
this.queryCacheConfig = queryCacheConfig;
Expand All @@ -62,6 +69,14 @@ public MetricsConfig(MetricQueryCacheConfig queryCacheConfig, MetricParallelConf
this.pushdownConfig = pushdownConfig;
}

public MetricsConfig(MetricQueryCacheConfig queryCacheConfig, MetricParallelConfig parallelConfig, MetricDownSamplingConfig downSamplingConfig, MetricPushdownConfig pushdownConfig, MetricRemoteWriteConfig remoteWriteConfig) {
this.queryCacheConfig = queryCacheConfig;
this.parallelConfig = parallelConfig;
this.downSamplingConfig = downSamplingConfig;
this.pushdownConfig = pushdownConfig;
this.remoteWriteConfig = remoteWriteConfig;
}

public MetricQueryCacheConfig getQueryCacheConfig() {
return queryCacheConfig;
}
Expand All @@ -86,6 +101,14 @@ public void setPushdownConfig(MetricPushdownConfig pushdownConfig) {
this.pushdownConfig = pushdownConfig;
}

public MetricRemoteWriteConfig getRemoteWriteConfig() {
return remoteWriteConfig;
}

public void setRemoteWriteConfig(MetricRemoteWriteConfig remoteWriteConfig) {
this.remoteWriteConfig = remoteWriteConfig;
}

public MetricDownSamplingConfig getDownSamplingConfig() {
return downSamplingConfig;
}
Expand All @@ -111,6 +134,9 @@ public boolean equals(Object o) {
if (pushdownConfig != null ? !pushdownConfig.equals(that.pushdownConfig) : that.pushdownConfig != null){
return false;
}
if (remoteWriteConfig != null ? !remoteWriteConfig.equals(that.remoteWriteConfig) : that.remoteWriteConfig != null){
return false;
}
return downSamplingConfig != null ? downSamplingConfig.equals(that.downSamplingConfig)
: that.downSamplingConfig == null;
}
Expand All @@ -120,6 +146,7 @@ public int hashCode() {
int result = queryCacheConfig != null ? queryCacheConfig.hashCode() : 0;
result = 31 * result + (parallelConfig != null ? parallelConfig.hashCode() : 0);
result = 31 * result + (pushdownConfig != null ? pushdownConfig.hashCode() : 0);
result = 31 * result + (remoteWriteConfig != null ? remoteWriteConfig.hashCode() : 0);
result = 31 * result + (downSamplingConfig != null ? downSamplingConfig.hashCode() : 0);
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.alibaba.fastjson.parser.Feature;
import com.aliyun.openservices.log.common.LogStore;
import com.aliyun.openservices.log.common.MetricDownSamplingConfig;
import com.aliyun.openservices.log.common.MetricRemoteWriteConfig;
import com.aliyun.openservices.log.common.MetricDownSamplingConfig.MetricDownSamplingStatus;
import com.aliyun.openservices.log.common.MetricParallelConfig;
import com.aliyun.openservices.log.common.MetricsConfig;
Expand Down Expand Up @@ -40,6 +41,13 @@ public class MetricsConfigFunctionTest extends FunctionTest {
+ " \"pushdown_config\" : {\n"
+ " \"enable\" : true\n"
+ " },\n"
+ " \"remote_write_config\" : {\n"
+ " \"enable\" : true,\n"
+ " \"history_interval\" : 500,\n"
+ " \"future_interval\" : 600,\n"
+ " \"replica_field\" : \"xzz_test\",\n"
+ " \"replica_timeout_seconds\" : 30\n"
+ " },\n"
+ " \"downsampling_config\": {\n"
+ " \"base\": {\n"
+ " \"create_time\": 12345678901,\n"
Expand Down Expand Up @@ -67,6 +75,7 @@ public class MetricsConfigFunctionTest extends FunctionTest {
static String PARAMETERINVALID = "ParameterInvalid";
static String METRICSCONFIGNOTEXIST = "MetricsConfigNotExist";
static String METRICSCONFIGALREADYEXIST = "MetricsConfigAlreadyExist";
static String NOTSUPPORTED = "NotSupported";

@Before
public void setUp() throws LogException {
Expand All @@ -91,6 +100,11 @@ public void testMetricsConfigValue() {
Assert.assertEquals(parallelConfig.getTimePieceCount(), 8);
Assert.assertEquals(parallelConfig.getParallelCountPerHost(), 2);
Assert.assertEquals(parallelConfig.getTotalParallelCount(), 64);
MetricRemoteWriteConfig remoteWriteConfig = CONFIG.getRemoteWriteConfig();
Assert.assertEquals(remoteWriteConfig.getHistoryInterval(), 500);
Assert.assertEquals(remoteWriteConfig.getFutureInterval(), 600);
Assert.assertEquals(remoteWriteConfig.getReplicaField(), "xzz_test");
Assert.assertEquals(remoteWriteConfig.getReplicaTimeoutSeconds(), 30);
MetricDownSamplingConfig downSamplingConfig = CONFIG.getDownSamplingConfig();
MetricDownSamplingStatus base = downSamplingConfig.getBase();
List<MetricDownSamplingStatus> downsampling = downSamplingConfig.getDownsampling();
Expand All @@ -116,7 +130,7 @@ public void testCreateMetricsConfig() {
client.createMetricsConfig(new CreateMetricsConfigRequest(PROJECTEXIST, LOGSTOREEXIST, CONFIG));
Assert.fail("should fail");
} catch (LogException e) {
Assert.assertEquals(PARAMETERINVALID, e.GetErrorCode());
Assert.assertEquals(NOTSUPPORTED, e.GetErrorCode());
}
try {
client.createMetricsConfig(new CreateMetricsConfigRequest(PROJECTEXIST, METRICSNOTEXIST, CONFIG));
Expand Down Expand Up @@ -161,7 +175,7 @@ public void testUpdateMetricsConfig() {
client.updateMetricsConfig(new UpdateMetricsConfigRequest(PROJECTEXIST, LOGSTOREEXIST, CONFIG));
Assert.fail("should fail");
} catch (LogException e) {
Assert.assertEquals(PARAMETERINVALID, e.GetErrorCode());
Assert.assertEquals(NOTSUPPORTED, e.GetErrorCode());
}
try {
client.updateMetricsConfig(new UpdateMetricsConfigRequest(PROJECTEXIST, METRICSNOTEXIST, CONFIG));
Expand Down Expand Up @@ -211,7 +225,7 @@ public void testDeleteMetricsConfig() {
client.deleteMetricsConfig(new DeleteMetricsConfigRequest(PROJECTEXIST, LOGSTOREEXIST));
Assert.fail("should fail");
} catch (LogException e) {
Assert.assertEquals(PARAMETERINVALID, e.GetErrorCode());
Assert.assertEquals(NOTSUPPORTED, e.GetErrorCode());
}
try {
client.deleteMetricsConfig(new DeleteMetricsConfigRequest(PROJECTEXIST, METRICSNOTEXIST));
Expand Down Expand Up @@ -239,7 +253,7 @@ public void testGetMetricsConfig() {
client.getMetricsConfig(new GetMetricsConfigRequest(PROJECTEXIST, LOGSTOREEXIST));
Assert.fail("should fail");
} catch (LogException e) {
Assert.assertEquals(PARAMETERINVALID, e.GetErrorCode());
Assert.assertEquals(NOTSUPPORTED, e.GetErrorCode());
}
try {
client.getMetricsConfig(new GetMetricsConfigRequest(PROJECTEXIST, METRICSNOTEXIST));
Expand Down

0 comments on commit 83bde72

Please # to comment.