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.8-alpha-1</version>
<version>1.0.8-alpha-2</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.8-alpha-1</version>
<version>1.0.8-alpha-2</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.8-alpha-1</version>
<version>1.0.8-alpha-2</version>
</parent>

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

import com.google.common.collect.Lists;
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.domain.core.configuration.SubConfigurationResp;
import group.rxcloud.cloudruntimes.utils.TypeRef;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Flux;

import java.io.Serializable;
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 transient String FILE_PATH = "capa-sample.properties";
private static final long serialVersionUID = -2113523925814197551L;

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

public static final transient String COMMON_FILE_SUFFIX = "telemetry-common";

/**
* Sample all data as default.
*/
public static final transient SamplerConfig DEFAULT_CONFIG = new SamplerConfig();
public static final transient SamplerConfig DEFAULT_CONFIG = new SamplerConfig() {{
setTraceEnable(true);
setMetricsEnable(true);
}};

private static final transient Logger log = LoggerFactory.getLogger(CapaMeterProviderBuilder.class);
public static final transient SamplerConfig CONFIG = new SamplerConfig();

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;
}
return CONFIG;
};

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


static {
Mixer.configurationHooksNullable().ifPresent(hooks -> {
try {
subscribeConfiguration(hooks, hooks.defaultConfigurationAppId(), true);
} catch (Throwable throwable) {
log.warn("Fail to load global telemetry config. Dynamic global config is disabled for capa telemetry.",
throwable);
}
try {
subscribeConfiguration(hooks,
CapaProperties.COMPONENT_PROPERTIES_SUPPLIER.apply(COMMON_FILE_SUFFIX).getProperty("appId"),
false);
} catch (Throwable throwable) {
log.warn("Fail to load global telemetry config. Dynamic global config is disabled for capa telemetry.",
throwable);
}
} catch (Throwable throwable) {
log.warn("Fail to load config item. Dynamic config is disabled for capa telemetry.", throwable);
}
});

return DEFAULT_CONFIG;
};
}

private static final long serialVersionUID = -2113523925814197551L;
private Boolean metricsEnable;

private boolean metricsEnable = true;
private Boolean traceEnable;

private boolean traceEnable = true;
private static void subscribeConfiguration(ConfigurationHooks configurationHooks, String appId, boolean prior) {
String storeName = configurationHooks.registryStoreNames().get(0);
Flux<SubConfigurationResp<SamplerConfig>> configFlux = configurationHooks.subscribeConfiguration(
storeName,
appId,
Lists.newArrayList(FILE_PATH),
null,
StringUtils.EMPTY,
StringUtils.EMPTY,
TypeRef.get(SamplerConfig.class));
configFlux.subscribe(resp -> {
if (CollectionUtils.isNotEmpty(resp.getItems())) {
SamplerConfig config = resp.getItems().get(0).getContent();
if (config != null) {
if (config.metricsEnable != null && (prior || CONFIG.metricsEnable == null)) {
CONFIG.metricsEnable = config.metricsEnable;
}
if (config.traceEnable != null && (prior || CONFIG.traceEnable == null)) {
CONFIG.traceEnable = config.traceEnable;
}
}
}
});
}

public boolean isMetricsEnable() {
return metricsEnable;
public Boolean isMetricsEnable() {
return metricsEnable == null ? DEFAULT_CONFIG.metricsEnable : metricsEnable;
}

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

public boolean isTraceEnable() {
return traceEnable;
public Boolean isTraceEnable() {
return traceEnable == null ? DEFAULT_CONFIG.traceEnable : traceEnable;
}

public void setTraceEnable(boolean traceEnable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
*/
public interface CapaContextPropagatorSettings {

// FIXME: 2021/11/28 change to capa-component-telemetry-context.json
String FILE_PATH = "/capa-context.json";
String FILE_PATH = "/capa-component-telemetry-context.json";

/**
* Replace the whole context config.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
*/
public interface CapaMeterProviderSettings {

// FIXME: 2021/11/28 change to capa-component-telemetry-meter.json
String FILE_PATH ="/capa-meter.json";
String FILE_PATH ="/capa-component-telemetry-meter.json";

/**
* Replace the whole config for the meter.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
*/
public interface CapaTracerProviderSettings {

// FIXME: 2021/11/28 change to capa-component-telemetry-tracer.json
String FILE_PATH = "/capa-tracer.json";
String FILE_PATH = "/capa-component-telemetry-tracer.json";

/**
* Replace the whole config for the meter.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertFalse;

/**
* @author: chenyijiang
* @date: 2021/12/2 12:33
*/
public class SamplerConfigTest {

@Test
public void isMetricsEnable() {
assertFalse(SamplerConfig.DEFAULT_SUPPLIER.get().isMetricsEnable());
}

@Test
public void isTraceEnable() {
assertFalse(SamplerConfig.DEFAULT_SUPPLIER.get().isTraceEnable());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* 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;

import com.google.common.collect.Lists;
import group.rxcloud.capa.infrastructure.hook.ConfigurationHooks;
import group.rxcloud.capa.infrastructure.hook.Mixer;
import group.rxcloud.capa.infrastructure.hook.TelemetryHooks;
import group.rxcloud.cloudruntimes.domain.core.configuration.ConfigurationItem;
import group.rxcloud.cloudruntimes.domain.core.configuration.SubConfigurationResp;
import group.rxcloud.cloudruntimes.utils.TypeRef;
import reactor.core.publisher.Flux;

import java.util.List;
import java.util.Map;

/**
* @author: chenyijiang
* @date: 2021/12/2 12:39
*/
public class TestMixerProvider implements Mixer.MixerProvider {

SamplerConfig app = new SamplerConfig() {{setMetricsEnable(false);}};
SamplerConfig global = new SamplerConfig() {{setTraceEnable(false); setMetricsEnable(true);}};


private ConfigurationHooks configurationHooks = new ConfigurationHooks() {
@Override
public List<String> registryStoreNames() {
return Lists.newArrayList("QConfig");
}

@Override
public String defaultConfigurationAppId() {
return "1234567";
}

@Override
public <T> Flux<SubConfigurationResp<T>> subscribeConfiguration(String storeName, String appId, List<String> keys, Map<String, String> metadata, String group, String label, TypeRef<T> type) {

if (type.getType() == SamplerConfig.class) {
if ("123".equals(appId)) {
return Flux.just(getSubscribeResponse(global));
}
if (defaultConfigurationAppId().equals(appId)) {
return Flux.just(getSubscribeResponse(app));
}
return Flux.just(null);
}
return ConfigurationHooks.super.subscribeConfiguration(storeName, appId, keys, metadata, type);
}
};

private <T> SubConfigurationResp<T> getSubscribeResponse(SamplerConfig samplerConfig) {
SubConfigurationResp<T> subConfigurationResp = new SubConfigurationResp<>();
ConfigurationItem item = new ConfigurationItem();
item.setContent(samplerConfig);
subConfigurationResp.setItems(Lists.newArrayList(item));
return subConfigurationResp;
}

@Override
public ConfigurationHooks provideConfigurationHooks() {
return configurationHooks;
}

@Override
public TelemetryHooks provideTelemetryHooks() {
return null;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public boolean matches(ReadableSpan span) {
@Test
public void buildFromTraceConfig() {
CapaTracerProvider provider = new CapaTracerProviderBuilder()
.setSamplerConfig(() -> SamplerConfig.DEFAULT_CONFIG)
.buildTracerProvider();

Span span = provider.tracerBuilder("test")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
appId=123
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
group.rxcloud.capa.infrastructure.hook.Mixer$MixerProvider=group.rxcloud.capa.component.telemetry.TestMixerProvider
2 changes: 1 addition & 1 deletion sdk-infrastructure/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.8-alpha-1</version>
<version>1.0.8-alpha-2</version>
</parent>

<artifactId>capa-sdk-infrastructure</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion sdk-spi-demo/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.8-alpha-1</version>
<version>1.0.8-alpha-2</version>
</parent>

<artifactId>capa-sdk-spi-demo</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion sdk-spi/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.8-alpha-1</version>
<version>1.0.8-alpha-2</version>
</parent>

<artifactId>capa-sdk-spi</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion sdk-springboot/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.8-alpha-1</version>
<version>1.0.8-alpha-2</version>
</parent>

<artifactId>sdk-springboot</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion sdk/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.8-alpha-1</version>
<version>1.0.8-alpha-2</version>
</parent>

<artifactId>capa-sdk</artifactId>
Expand Down
Loading