Skip to content

Commit 1964c22

Browse files
author
chenyijiang
committed
Fix Histogram Metrics.
Add sample config.
1 parent 0743ceb commit 1964c22

41 files changed

Lines changed: 810 additions & 209 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

examples/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<parent>
2424
<artifactId>capa-parent</artifactId>
2525
<groupId>group.rxcloud</groupId>
26-
<version>1.0.7.RELEASE</version>
26+
<version>1.0.8-alpha-1</version>
2727
</parent>
2828

2929
<artifactId>capa-examples</artifactId>

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<groupId>group.rxcloud</groupId>
2424
<artifactId>capa-parent</artifactId>
2525
<packaging>pom</packaging>
26-
<version>1.0.7.RELEASE</version>
26+
<version>1.0.8-alpha-1</version>
2727
<name>capa-sdk-parent</name>
2828
<description>SDK for Capa.</description>
2929
<url>https://github.com/reactivegroup</url>

sdk-component/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<parent>
2424
<groupId>group.rxcloud</groupId>
2525
<artifactId>capa-parent</artifactId>
26-
<version>1.0.7.RELEASE</version>
26+
<version>1.0.8-alpha-1</version>
2727
</parent>
2828

2929
<artifactId>capa-sdk-component</artifactId>

sdk-component/src/main/java/group/rxcloud/capa/component/telemetry/SamplerConfig.java

Lines changed: 51 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -16,66 +16,81 @@
1616
*/
1717
package group.rxcloud.capa.component.telemetry;
1818

19-
import group.rxcloud.capa.infrastructure.utils.SpiUtils;
19+
import group.rxcloud.capa.component.telemetry.metrics.CapaMeterProviderBuilder;
20+
import group.rxcloud.capa.infrastructure.CapaProperties;
21+
import group.rxcloud.capa.infrastructure.hook.ConfigurationHooks;
22+
import group.rxcloud.capa.infrastructure.hook.Mixer;
23+
import group.rxcloud.cloudruntimes.domain.core.configuration.ConfigurationItem;
24+
import group.rxcloud.cloudruntimes.utils.TypeRef;
25+
import org.slf4j.Logger;
26+
import org.slf4j.LoggerFactory;
2027

2128
import java.io.Serializable;
22-
import java.util.Properties;
29+
import java.util.Collections;
30+
import java.util.List;
31+
import java.util.Optional;
32+
import java.util.function.Supplier;
2333

2434
/**
2535
* Sampler config.
2636
*/
2737
public class SamplerConfig implements Serializable {
2838

29-
public static final String FILE_PATH = "/capa-sample.properties";
39+
public static final transient String FILE_PATH = "capa-sample.properties";
3040

3141
/**
3242
* Sample all data as default.
3343
*/
3444
public static final transient SamplerConfig DEFAULT_CONFIG = new SamplerConfig();
3545

36-
private static final long serialVersionUID = -2113523925814197551L;
37-
38-
private boolean metricsSample = true;
46+
private static final transient Logger log = LoggerFactory.getLogger(CapaMeterProviderBuilder.class);
47+
48+
public static final transient Supplier<SamplerConfig> DEFAULT_SUPPLIER = () -> {
49+
try {
50+
String storeName = Optional.ofNullable(CapaProperties.COMPONENT_PROPERTIES_SUPPLIER.apply("configuration")
51+
.getProperty(
52+
"CONFIGURATION_COMPONENT_STORE_NAME"))
53+
.orElse("UN_CONFIGURED_STORE_CONFIG_NAME");
54+
Optional<ConfigurationHooks> hooksOptional = Mixer.configurationHooksNullable();
55+
if (hooksOptional.isPresent()) {
56+
List<ConfigurationItem<SamplerConfig>> config = hooksOptional.get().getConfiguration(storeName,
57+
null,
58+
Collections.singletonList(FILE_PATH),
59+
null,
60+
"",
61+
"",
62+
TypeRef.get(SamplerConfig.class)).block();
63+
if (!config.isEmpty()) {
64+
SamplerConfig item = config.get(0).getContent();
65+
return item == null ? DEFAULT_CONFIG : item;
66+
}
67+
}
68+
} catch (Throwable throwable) {
69+
log.warn("Fail to load config item. Dynamic config is disabled for capa telemetry.", throwable);
70+
}
3971

40-
private boolean traceSample = true;
72+
return DEFAULT_CONFIG;
73+
};
4174

42-
private boolean logSample = true;
75+
private static final long serialVersionUID = -2113523925814197551L;
4376

44-
public boolean isMetricsSample() {
45-
return metricsSample;
46-
}
77+
private boolean metricsEnable = true;
4778

48-
public void setMetricsSample(boolean metricsSample) {
49-
this.metricsSample = metricsSample;
50-
}
79+
private boolean traceEnable = true;
5180

52-
public boolean isTraceSample() {
53-
return traceSample;
81+
public boolean isMetricsEnable() {
82+
return metricsEnable;
5483
}
5584

56-
public void setTraceSample(boolean traceSample) {
57-
this.traceSample = traceSample;
85+
public void setMetricsEnable(boolean metricsEnable) {
86+
this.metricsEnable = metricsEnable;
5887
}
5988

60-
public boolean isLogSample() {
61-
return logSample;
89+
public boolean isTraceEnable() {
90+
return traceEnable;
6291
}
6392

64-
public void setLogSample(boolean logSample) {
65-
this.logSample = logSample;
66-
}
67-
68-
public static SamplerConfig loadOrDefault() {
69-
Properties properties = SpiUtils.loadPropertiesNullable(FILE_PATH);
70-
if (properties == null) {
71-
return DEFAULT_CONFIG;
72-
}
73-
74-
SamplerConfig result = new SamplerConfig();
75-
result.setMetricsSample(Boolean.valueOf(properties.getProperty("metricsSample", Boolean.TRUE.toString())));
76-
result.setTraceSample(Boolean.valueOf(properties.getProperty("traceSample", Boolean.TRUE.toString())));
77-
result.setLogSample(Boolean.valueOf(properties.getProperty("logSample", Boolean.TRUE.toString())));
78-
79-
return result;
93+
public void setTraceEnable(boolean traceEnable) {
94+
this.traceEnable = traceEnable;
8095
}
8196
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package group.rxcloud.capa.component.telemetry.metrics;
18+
19+
import io.opentelemetry.api.metrics.DoubleHistogram;
20+
21+
/**
22+
*/
23+
public abstract class CapaDoubleHistogram implements DoubleHistogram {
24+
25+
protected final String meterName;
26+
27+
protected final String schemaUrl;
28+
29+
protected final String version;
30+
31+
protected final String name;
32+
33+
protected String description;
34+
35+
protected String unit;
36+
37+
public CapaDoubleHistogram(String meterName, String schemaUrl, String version, String name,
38+
String description,
39+
String unit) {
40+
this.meterName = meterName;
41+
this.schemaUrl = schemaUrl;
42+
this.version = version;
43+
this.name = name;
44+
this.description = description;
45+
this.unit = unit;
46+
}
47+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package group.rxcloud.capa.component.telemetry.metrics;
18+
19+
import io.opentelemetry.api.metrics.DoubleHistogram;
20+
import io.opentelemetry.api.metrics.DoubleHistogramBuilder;
21+
import io.opentelemetry.api.metrics.LongHistogramBuilder;
22+
import io.opentelemetry.api.metrics.internal.NoopMeter;
23+
24+
/**
25+
*
26+
*/
27+
public class CapaDoubleHistogramBuilder implements DoubleHistogramBuilder {
28+
29+
protected final String meterName;
30+
31+
protected final String schemaUrl;
32+
33+
protected final String version;
34+
35+
private final String name;
36+
37+
private String description;
38+
39+
private String unit;
40+
41+
public CapaDoubleHistogramBuilder(String meterName, String schemaUrl, String version, String name) {
42+
this.meterName = meterName;
43+
this.schemaUrl = schemaUrl;
44+
this.version = version;
45+
this.name = name;
46+
}
47+
48+
@Override
49+
public DoubleHistogramBuilder setDescription(String description) {
50+
this.description = description;
51+
return this;
52+
}
53+
54+
@Override
55+
public DoubleHistogramBuilder setUnit(String unit) {
56+
this.unit = unit;
57+
return this;
58+
}
59+
60+
@Override
61+
public LongHistogramBuilder ofLongs() {
62+
return new CapaLongHistogramBuilder(meterName, schemaUrl, version, name).setDescription(description)
63+
.setUnit(unit);
64+
}
65+
66+
@Override
67+
public DoubleHistogram build() {
68+
DoubleHistogram histogram = CapaMeterWrapper
69+
.loadHistogramNullable(meterName, schemaUrl, version, name, description, unit,
70+
CapaDoubleHistogram.class);
71+
if (histogram == null) {
72+
return NoopMeter.getInstance().histogramBuilder(name).build();
73+
}
74+
return histogram;
75+
}
76+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package group.rxcloud.capa.component.telemetry.metrics;
18+
19+
import io.opentelemetry.api.metrics.LongHistogram;
20+
21+
/**
22+
*/
23+
public abstract class CapaLongHistogram implements LongHistogram {
24+
25+
protected final String meterName;
26+
27+
protected final String schemaUrl;
28+
29+
protected final String version;
30+
31+
protected final String name;
32+
33+
protected String description;
34+
35+
protected String unit;
36+
37+
public CapaLongHistogram(String meterName, String schemaUrl, String version, String name, String description, String unit) {
38+
this.meterName = meterName;
39+
this.schemaUrl = schemaUrl;
40+
this.version = version;
41+
this.name = name;
42+
this.description = description;
43+
this.unit = unit;
44+
}
45+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package group.rxcloud.capa.component.telemetry.metrics;
18+
19+
import io.opentelemetry.api.metrics.DoubleHistogramBuilder;
20+
import io.opentelemetry.api.metrics.LongHistogram;
21+
import io.opentelemetry.api.metrics.LongHistogramBuilder;
22+
import io.opentelemetry.api.metrics.internal.NoopMeter;
23+
24+
/**
25+
*
26+
*/
27+
public class CapaLongHistogramBuilder implements LongHistogramBuilder {
28+
29+
private final String meterName;
30+
31+
private final String schemaUrl;
32+
33+
private final String version;
34+
35+
private final String name;
36+
37+
private String description;
38+
39+
private String unit;
40+
41+
public CapaLongHistogramBuilder(String meterName, String schemaUrl, String version, String name) {
42+
this.meterName = meterName;
43+
this.schemaUrl = schemaUrl;
44+
this.version = version;
45+
this.name = name;
46+
}
47+
48+
@Override
49+
public LongHistogramBuilder setDescription(String description) {
50+
this.description = description;
51+
return this;
52+
}
53+
54+
@Override
55+
public LongHistogramBuilder setUnit(String unit) {
56+
this.unit = unit;
57+
return this;
58+
}
59+
60+
@Override
61+
public DoubleHistogramBuilder ofDoubles() {
62+
return new CapaDoubleHistogramBuilder(meterName, schemaUrl, version, name).setDescription(description)
63+
.setUnit(unit);
64+
}
65+
66+
@Override
67+
public LongHistogram build() {
68+
LongHistogram histogram = CapaMeterWrapper
69+
.loadHistogramNullable(meterName, schemaUrl, version, name, description, unit, CapaLongHistogram.class);
70+
if (histogram == null) {
71+
return NoopMeter.getInstance().histogramBuilder(name).ofLongs().build();
72+
}
73+
return histogram;
74+
}
75+
}

0 commit comments

Comments
 (0)