Skip to content

Commit

Permalink
Add HttpSender report plugin supporting http basic authorization (#203)
Browse files Browse the repository at this point in the history
* add HttpSender report plugin supporting HTTP basic authorization
  • Loading branch information
Oseenix authored Jan 27, 2022
1 parent 70ff170 commit 831841e
Show file tree
Hide file tree
Showing 30 changed files with 853 additions and 235 deletions.
186 changes: 96 additions & 90 deletions build/src/main/resources/agent.properties
Original file line number Diff line number Diff line change
Expand Up @@ -143,137 +143,143 @@ plugin.integrability.global.redirect.enabled=true
plugin.integrability.global.forwarded.enabled=true
plugin.hook.global.foundation.enabled=true


# ----------------------------------------------
# if the plugin configuration is consistent with the global namespace,
# do not add configuration items not commented out in this default configuration file.
# otherwise, they can not be overridden by Global configuration in user's configuration file.

#
# -------------------- jvm ---------------------
plugin.observability.jvmGc.metric.enabled=true
plugin.observability.jvmGc.metric.interval=30
plugin.observability.jvmGc.metric.topic=platform-meter
plugin.observability.jvmGc.metric.appendType=kafka
plugin.observability.jvmMemory.metric.enabled=true
plugin.observability.jvmMemory.metric.interval=30
plugin.observability.jvmMemory.metric.topic=platform-meter
plugin.observability.jvmMemory.metric.appendType=kafka
# plugin.observability.jvmGc.metric.enabled=true
# plugin.observability.jvmGc.metric.interval=30
# plugin.observability.jvmGc.metric.topic=platform-meter
# plugin.observability.jvmGc.metric.appendType=kafka
# plugin.observability.jvmMemory.metric.enabled=true
# plugin.observability.jvmMemory.metric.interval=30
# plugin.observability.jvmMemory.metric.topic=platform-meter
# plugin.observability.jvmMemory.metric.appendType=kafka
#
# -------------------- async ---------------------
plugin.observability.async.tracing.enabled=true
# plugin.observability.async.tracing.enabled=true
#
# -------------------- elasticsearch redirect ---------------------
plugin.integrability.elasticsearch.redirect.enabled=true
plugin.observability.elasticsearch.tracing.enabled=true
# plugin.integrability.elasticsearch.redirect.enabled=true
# plugin.observability.elasticsearch.tracing.enabled=true
# elasticsearch metric
plugin.observability.elasticsearch.metric.enabled=true
plugin.observability.elasticsearch.metric.interval=30
plugin.observability.elasticsearch.metric.topic=application-meter
plugin.observability.elasticsearch.metric.appendType=kafka
# plugin.observability.elasticsearch.metric.enabled=true
# plugin.observability.elasticsearch.metric.interval=30
# plugin.observability.elasticsearch.metric.topic=application-meter
# plugin.observability.elasticsearch.metric.appendType=kafka
#
# -------------------- httpServlet ---------------------
plugin.observability.httpServlet.tracing.enabled=true
plugin.observability.httpServlet.metric.enabled=true
plugin.observability.httpServlet.metric.interval=30
plugin.observability.httpServlet.metric.topic=application-meter
plugin.observability.httpServlet.metric.appendType=kafka
# plugin.observability.httpServlet.tracing.enabled=true
# plugin.observability.httpServlet.metric.enabled=true
# plugin.observability.httpServlet.metric.interval=30
# plugin.observability.httpServlet.metric.topic=application-meter
# plugin.observability.httpServlet.metric.appendType=kafka
#
# -------------------- jdbc ---------------------
# jdbc tracing
plugin.observability.jdbc.tracing.enabled=true
## jdbc tracing
# plugin.observability.jdbc.tracing.enabled=true
# jdbcStatement metric
plugin.observability.jdbcStatement.metric.enabled=true
plugin.observability.jdbcStatement.metric.interval=30
plugin.observability.jdbcStatement.metric.topic=application-meter
plugin.observability.jdbcStatement.metric.appendType=kafka
# jdbcConnection metric
plugin.observability.jdbcConnection.metric.enabled=true
plugin.observability.jdbcConnection.metric.interval=30
plugin.observability.jdbcConnection.metric.topic=application-meter
plugin.observability.jdbcConnection.metric.appendType=kafka
# md5Dictionary metric
plugin.observability.md5Dictionary.metric.enabled=true
plugin.observability.md5Dictionary.metric.interval=30
plugin.observability.md5Dictionary.metric.topic=application-meter
plugin.observability.md5Dictionary.metric.appendType=kafka
# jdbc redirect
plugin.integrability.jdbc.redirect.enabled=true
# plugin.observability.jdbcStatement.metric.enabled=true
# plugin.observability.jdbcStatement.metric.interval=30
# plugin.observability.jdbcStatement.metric.topic=application-meter
# plugin.observability.jdbcStatement.metric.appendType=kafka
## jdbcConnection metric
# plugin.observability.jdbcConnection.metric.enabled=true
# plugin.observability.jdbcConnection.metric.interval=30
# plugin.observability.jdbcConnection.metric.topic=application-meter
# plugin.observability.jdbcConnection.metric.appendType=kafka
## md5Dictionary metric
# plugin.observability.md5Dictionary.metric.enabled=true
# plugin.observability.md5Dictionary.metric.interval=30
# plugin.observability.md5Dictionary.metric.topic=application-meter
# plugin.observability.md5Dictionary.metric.appendType=kafka
## jdbc redirect
# plugin.integrability.jdbc.redirect.enabled=true
#
# -------------------- kafka ---------------------
# kafka tracing
plugin.observability.kafka.tracing.enabled=true
# plugin.observability.kafka.tracing.enabled=true
# kafka metric
plugin.observability.kafka.metric.enabled=true
plugin.observability.kafka.metric.interval=30
plugin.observability.kafka.metric.topic=application-meter
plugin.observability.kafka.metric.appendType=kafka
# plugin.observability.kafka.metric.enabled=true
# plugin.observability.kafka.metric.interval=30
# plugin.observability.kafka.metric.topic=application-meter
# plugin.observability.kafka.metric.appendType=kafka
# kafka redirect
plugin.integrability.kafka.redirect.enabled=true
# plugin.integrability.kafka.redirect.enabled=true
#
# -------------------- rabbitmq ---------------------
# rabbitmq tracing
plugin.observability.rabbitmq.tracing.enabled=true
# plugin.observability.rabbitmq.tracing.enabled=true
# rabbitmq metric
plugin.observability.rabbitmq.metric.enabled=true
plugin.observability.rabbitmq.metric.interval=30
plugin.observability.rabbitmq.metric.topic=application-meter
plugin.observability.rabbitmq.metric.appendType=kafka
# plugin.observability.rabbitmq.metric.enabled=true
# plugin.observability.rabbitmq.metric.interval=30
# plugin.observability.rabbitmq.metric.topic=application-meter
# plugin.observability.rabbitmq.metric.appendType=kafka
# rabbitmq redirect
plugin.integrability.rabbitmq.redirect.enabled=true
# plugin.integrability.rabbitmq.redirect.enabled=true
#
# -------------------- redis ---------------------
# redis tracing
plugin.observability.redis.tracing.enabled=true
# plugin.observability.redis.tracing.enabled=true
# redis metric
plugin.observability.redis.metric.enabled=true
plugin.observability.redis.metric.interval=30
plugin.observability.redis.metric.topic=application-meter
plugin.observability.redis.metric.appendType=kafka
# plugin.observability.redis.metric.enabled=true
# plugin.observability.redis.metric.interval=30
# plugin.observability.redis.metric.topic=application-meter
# plugin.observability.redis.metric.appendType=kafka
# redis redirect
plugin.integrability.redis.redirect.enabled=true
# plugin.integrability.redis.redirect.enabled=true
#
# -------------------- springGateway ---------------------
# springGateway tracing
plugin.observability.springGateway.tracing.enabled=true
# plugin.observability.springGateway.tracing.enabled=true
# springGateway metric
plugin.observability.springGateway.metric.enabled=true
plugin.observability.springGateway.metric.interval=30
plugin.observability.springGateway.metric.topic=application-meter
plugin.observability.springGateway.metric.appendType=kafka
# plugin.observability.springGateway.metric.enabled=true
# plugin.observability.springGateway.metric.interval=30
# plugin.observability.springGateway.metric.topic=application-meter
# plugin.observability.springGateway.metric.appendType=kafka
#
# -------------------- request ---------------------
# httpclient tracing:httpclient and httpclient5
plugin.observability.httpclient.tracing.enabled=true
# okHttp tracing
plugin.observability.okHttp.tracing.enabled=true
# webclient tracing
plugin.observability.webclient.tracing.enabled=true
# feignClient tracing
plugin.observability.feignClient.tracing.enabled=true
# restTemplate tracing
plugin.observability.restTemplate.tracing.enabled=true
## httpclient tracing:httpclient and httpclient5
# plugin.observability.httpclient.tracing.enabled=true
## okHttp tracing
# plugin.observability.okHttp.tracing.enabled=true
## webclient tracing
# plugin.observability.webclient.tracing.enabled=true
## feignClient tracing
# plugin.observability.feignClient.tracing.enabled=true
## restTemplate tracing
# plugin.observability.restTemplate.tracing.enabled=true
#
# -------------------- access ---------------------
# access: servlet and spring gateway
plugin.observability.access.metric.enabled=true
plugin.observability.access.metric.interval=30
plugin.observability.access.metric.topic=application-log
plugin.observability.access.metric.appendType=kafka
## access: servlet and spring gateway
# plugin.observability.access.metric.enabled=true
# plugin.observability.access.metric.interval=30
# plugin.observability.access.metric.topic=application-log
# plugin.observability.access.metric.appendType=kafka
#
# -------------------- service name ---------------------
# add service name to header by name for easemesh. default name: X-Mesh-RPC-Service
plugin.integrability.serviceName.addServiceNameHead.propagate.head=X-Mesh-RPC-Service
## add service name to header by name for easemesh. default name: X-Mesh-RPC-Service
# plugin.integrability.serviceName.addServiceNameHead.propagate.head=X-Mesh-RPC-Service
#
# -------------------- mongodb ---------------------
# mongodb tracing
plugin.observability.mongodb.tracing.enabled=true
# mongodb metric
plugin.observability.mongodb.metric.enabled=true
plugin.observability.mongodb.metric.interval=30
plugin.observability.mongodb.metric.topic=application-meter
plugin.observability.mongodb.metric.appendType=kafka
# mongodb redirect
plugin.integrability.mongodb.redirect.enabled=true
# mongodb foundation
plugin.hook.mongodb.foundation.enabled=true
## mongodb tracing
# plugin.observability.mongodb.tracing.enabled=true
## mongodb metric
# plugin.observability.mongodb.metric.enabled=true
# plugin.observability.mongodb.metric.interval=30
# plugin.observability.mongodb.metric.topic=application-meter
# plugin.observability.mongodb.metric.appendType=kafka
## mongodb redirect
# plugin.integrability.mongodb.redirect.enabled=true
## mongodb foundation
# plugin.hook.mongodb.foundation.enabled=true

# --------------------------------
#reporter.outputServer.bootstrapServer=127.0.0.1:9092
# reporter.outputServer.bootstrapServer=127.0.0.1:9092
reporter.outputServer.timeout=1000
reporter.outputServer.enabled=true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,12 @@
import java.util.*;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import static com.megaease.easeagent.plugin.api.config.ConfigConst.*;

public class ConfigUtils {
public static String extractServiceName(Configs configs) {
return configs.getString(ConfigConst.SERVICE_NAME);
}
private ConfigUtils() {}

public static <R> void bindProp(String name, Config configs, BiFunction<Config, String, R> func, Consumer<R> consumer, R def) {
Runnable process = () -> {
Expand Down Expand Up @@ -99,23 +96,15 @@ private static String join(String prefix, String current) {
}

public static boolean isGlobal(String namespace) {
return namespace != null && PLUGIN_GLOBAL.equals(namespace);
return PLUGIN_GLOBAL.equals(namespace);
}

public static boolean isPluginConfig(String key) {
boolean r = false;
if (key != null && key.startsWith(PLUGIN_PREFIX)) {
r = true;
}
return r;
return key != null && key.startsWith(PLUGIN_PREFIX);
}

public static boolean isPluginConfig(String key, String domain, String namespace, String id) {
boolean r = false;
if (key != null && key.startsWith(ConfigConst.join(PLUGIN, domain, namespace, id))) {
r = true;
}
return r;
return key != null && key.startsWith(ConfigConst.join(PLUGIN, domain, namespace, id));
}

public static PluginProperty pluginProperty(String path) {
Expand Down Expand Up @@ -148,28 +137,23 @@ public static String buildPluginProperty(String domain, String namespace, String
/**
* Convert config item with a fromPrefix to toPrefix for configuration Compatibility
*
* @param config config
* @param cfg config source map
* @param fromPrefix from
* @param toPrefix to
* @return Extracted and converted KV map
*/
public static Map<String, String> extractAndConvertPrefix(
Config config, String fromPrefix, String toPrefix) {
return extractAndConvertPrefix(config.getConfigs(), fromPrefix, toPrefix);
}

public static Map<String, String> extractAndConvertPrefix(Map<String, String> cfg, String fromPrefix, String toPrefix) {
Map<String, String> convert = new HashMap<>();

Set<String> keys = new HashSet<>();
cfg.forEach((key, value) -> {
if (key.startsWith(fromPrefix)) {
keys.add(key);
key = toPrefix + key.substring(fromPrefix.length());
convert.put(key, value);
keys.add(key);
}
});
keys.forEach(k -> cfg.remove(k));
keys.forEach(cfg::remove);

// override, new configuration KV override previous KV
convert.putAll(extractByPrefix(cfg, toPrefix));
Expand Down
10 changes: 9 additions & 1 deletion config/src/main/java/com/megaease/easeagent/config/Configs.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class Configs implements Config {
protected Configs() {}

public Configs(Map<String, String> source) {
this.source = new HashMap<>(source);
this.source = new TreeMap<>(source);
notifier = new ConfigNotifier("");
}

Expand Down Expand Up @@ -94,6 +94,14 @@ public Integer getInt(String name) {
}
}

public Boolean getBooleanNullForUnset(String name) {
String value = this.source.get(name);
if (value == null) {
return null;
}
return value.equalsIgnoreCase("yes") || value.equalsIgnoreCase("true");
}

public Boolean getBoolean(String name) {
String value = this.source.get(name);
if (value == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@
import com.megaease.easeagent.plugin.api.config.ConfigConst;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.*;

public class GlobalConfigs extends Configs implements ConfigManagerMXBean {
private static final Logger LOGGER = LoggerFactory.getLogger(GlobalConfigs.class);
Expand All @@ -37,9 +34,9 @@ public class GlobalConfigs extends Configs implements ConfigManagerMXBean {
public GlobalConfigs(Map<String, String> source) {
super();
// reporter adapter
Map<String, String> map = new HashMap<>(source);
Map<String, String> map = new TreeMap<>(source);
ReporterConfigAdapter.convertConfig(map);
this.source = new HashMap<>(source);
this.source = new TreeMap<>(map);
this.notifier = new ConfigNotifier("");
}

Expand Down
Loading

0 comments on commit 831841e

Please sign in to comment.