Skip to content
Merged
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
2 changes: 1 addition & 1 deletion examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<artifactId>capa-parent</artifactId>
<groupId>group.rxcloud</groupId>
<version>1.0.7.RELEASE</version>
<version>1.0.8-alpha-1</version>
</parent>

<artifactId>capa-examples</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<groupId>group.rxcloud</groupId>
<artifactId>capa-parent</artifactId>
<packaging>pom</packaging>
<version>1.0.7.RELEASE</version>
<version>1.0.8-alpha-1</version>
<name>capa-sdk-parent</name>
<description>SDK for Capa.</description>
<url>https://github.com/reactivegroup</url>
Expand Down
2 changes: 1 addition & 1 deletion sdk-component/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<groupId>group.rxcloud</groupId>
<artifactId>capa-parent</artifactId>
<version>1.0.7.RELEASE</version>
<version>1.0.8-alpha-1</version>
</parent>

<artifactId>capa-sdk-component</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,66 +16,81 @@
*/
package group.rxcloud.capa.component.telemetry;

import group.rxcloud.capa.infrastructure.utils.SpiUtils;
import group.rxcloud.capa.component.telemetry.metrics.CapaMeterProviderBuilder;
import group.rxcloud.capa.infrastructure.CapaProperties;
import group.rxcloud.capa.infrastructure.hook.ConfigurationHooks;
import group.rxcloud.capa.infrastructure.hook.Mixer;
import group.rxcloud.cloudruntimes.domain.core.configuration.ConfigurationItem;
import group.rxcloud.cloudruntimes.utils.TypeRef;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.Serializable;
import java.util.Properties;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.function.Supplier;

/**
* Sampler config.
*/
public class SamplerConfig implements Serializable {

public static final String FILE_PATH = "/capa-sample.properties";
public static final transient String FILE_PATH = "capa-sample.properties";

/**
* Sample all data as default.
*/
public static final transient SamplerConfig DEFAULT_CONFIG = new SamplerConfig();

private static final long serialVersionUID = -2113523925814197551L;

private boolean metricsSample = true;
private static final transient Logger log = LoggerFactory.getLogger(CapaMeterProviderBuilder.class);

public static final transient Supplier<SamplerConfig> DEFAULT_SUPPLIER = () -> {
try {
String storeName = Optional.ofNullable(CapaProperties.COMPONENT_PROPERTIES_SUPPLIER.apply("configuration")
.getProperty(
"CONFIGURATION_COMPONENT_STORE_NAME"))
.orElse("UN_CONFIGURED_STORE_CONFIG_NAME");
Optional<ConfigurationHooks> hooksOptional = Mixer.configurationHooksNullable();
if (hooksOptional.isPresent()) {
List<ConfigurationItem<SamplerConfig>> config = hooksOptional.get().getConfiguration(storeName,
null,
Collections.singletonList(FILE_PATH),
null,
"",
"",
TypeRef.get(SamplerConfig.class)).block();
if (!config.isEmpty()) {
SamplerConfig item = config.get(0).getContent();
return item == null ? DEFAULT_CONFIG : item;
}
}
} catch (Throwable throwable) {
log.warn("Fail to load config item. Dynamic config is disabled for capa telemetry.", throwable);
}

private boolean traceSample = true;
return DEFAULT_CONFIG;
};

private boolean logSample = true;
private static final long serialVersionUID = -2113523925814197551L;

public boolean isMetricsSample() {
return metricsSample;
}
private boolean metricsEnable = true;

public void setMetricsSample(boolean metricsSample) {
this.metricsSample = metricsSample;
}
private boolean traceEnable = true;

public boolean isTraceSample() {
return traceSample;
public boolean isMetricsEnable() {
return metricsEnable;
}

public void setTraceSample(boolean traceSample) {
this.traceSample = traceSample;
public void setMetricsEnable(boolean metricsEnable) {
this.metricsEnable = metricsEnable;
}

public boolean isLogSample() {
return logSample;
public boolean isTraceEnable() {
return traceEnable;
}

public void setLogSample(boolean logSample) {
this.logSample = logSample;
}

public static SamplerConfig loadOrDefault() {
Properties properties = SpiUtils.loadPropertiesNullable(FILE_PATH);
if (properties == null) {
return DEFAULT_CONFIG;
}

SamplerConfig result = new SamplerConfig();
result.setMetricsSample(Boolean.valueOf(properties.getProperty("metricsSample", Boolean.TRUE.toString())));
result.setTraceSample(Boolean.valueOf(properties.getProperty("traceSample", Boolean.TRUE.toString())));
result.setLogSample(Boolean.valueOf(properties.getProperty("logSample", Boolean.TRUE.toString())));

return result;
public void setTraceEnable(boolean traceEnable) {
this.traceEnable = traceEnable;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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 group.rxcloud.capa.component.telemetry.metrics;

import io.opentelemetry.api.metrics.DoubleHistogram;

/**
*/
public abstract class CapaDoubleHistogram implements DoubleHistogram {

protected final String meterName;

protected final String schemaUrl;

protected final String version;

protected final String name;

protected String description;

protected String unit;

public CapaDoubleHistogram(String meterName, String schemaUrl, String version, String name,
String description,
String unit) {
this.meterName = meterName;
this.schemaUrl = schemaUrl;
this.version = version;
this.name = name;
this.description = description;
this.unit = unit;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* 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 group.rxcloud.capa.component.telemetry.metrics;

import io.opentelemetry.api.metrics.DoubleHistogram;
import io.opentelemetry.api.metrics.DoubleHistogramBuilder;
import io.opentelemetry.api.metrics.LongHistogramBuilder;
import io.opentelemetry.api.metrics.internal.NoopMeter;

/**
*
*/
public class CapaDoubleHistogramBuilder implements DoubleHistogramBuilder {

protected final String meterName;

protected final String schemaUrl;

protected final String version;

private final String name;

private String description;

private String unit;

public CapaDoubleHistogramBuilder(String meterName, String schemaUrl, String version, String name) {
this.meterName = meterName;
this.schemaUrl = schemaUrl;
this.version = version;
this.name = name;
}

@Override
public DoubleHistogramBuilder setDescription(String description) {
this.description = description;
return this;
}

@Override
public DoubleHistogramBuilder setUnit(String unit) {
this.unit = unit;
return this;
}

@Override
public LongHistogramBuilder ofLongs() {
return new CapaLongHistogramBuilder(meterName, schemaUrl, version, name).setDescription(description)
.setUnit(unit);
}

@Override
public DoubleHistogram build() {
DoubleHistogram histogram = CapaMeterWrapper
.loadHistogramNullable(meterName, schemaUrl, version, name, description, unit,
CapaDoubleHistogram.class);
if (histogram == null) {
return NoopMeter.getInstance().histogramBuilder(name).build();
}
return histogram;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* 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 group.rxcloud.capa.component.telemetry.metrics;

import io.opentelemetry.api.metrics.LongHistogram;

/**
*/
public abstract class CapaLongHistogram implements LongHistogram {

protected final String meterName;

protected final String schemaUrl;

protected final String version;

protected final String name;

protected String description;

protected String unit;

public CapaLongHistogram(String meterName, String schemaUrl, String version, String name, String description, String unit) {
this.meterName = meterName;
this.schemaUrl = schemaUrl;
this.version = version;
this.name = name;
this.description = description;
this.unit = unit;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* 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 group.rxcloud.capa.component.telemetry.metrics;

import io.opentelemetry.api.metrics.DoubleHistogramBuilder;
import io.opentelemetry.api.metrics.LongHistogram;
import io.opentelemetry.api.metrics.LongHistogramBuilder;
import io.opentelemetry.api.metrics.internal.NoopMeter;

/**
*
*/
public class CapaLongHistogramBuilder implements LongHistogramBuilder {

private final String meterName;

private final String schemaUrl;

private final String version;

private final String name;

private String description;

private String unit;

public CapaLongHistogramBuilder(String meterName, String schemaUrl, String version, String name) {
this.meterName = meterName;
this.schemaUrl = schemaUrl;
this.version = version;
this.name = name;
}

@Override
public LongHistogramBuilder setDescription(String description) {
this.description = description;
return this;
}

@Override
public LongHistogramBuilder setUnit(String unit) {
this.unit = unit;
return this;
}

@Override
public DoubleHistogramBuilder ofDoubles() {
return new CapaDoubleHistogramBuilder(meterName, schemaUrl, version, name).setDescription(description)
.setUnit(unit);
}

@Override
public LongHistogram build() {
LongHistogram histogram = CapaMeterWrapper
.loadHistogramNullable(meterName, schemaUrl, version, name, description, unit, CapaLongHistogram.class);
if (histogram == null) {
return NoopMeter.getInstance().histogramBuilder(name).ofLongs().build();
}
return histogram;
}
}
Loading