use of com.megaease.easeagent.plugin.api.config.IPluginConfig in project easeagent by megaease.
the class PluginConfigManagerTest method getConfig1.
@Test
public void getConfig1() throws InterruptedException {
PluginConfigManager pluginConfigManager = build();
PluginConfig pluginConfig = pluginConfigManager.getConfig(PluginSourceConfigTest.DOMAIN, "global", PluginSourceConfigTest.GLOBAL_ID);
checkPluginConfigString(pluginConfig, PluginConfigTest.globalSource());
pluginConfig = pluginConfigManager.getConfig(PluginSourceConfigTest.DOMAIN, PluginSourceConfigTest.NAMESPACE, PluginSourceConfigTest.TEST_TRACE_ID);
checkPluginConfigString(pluginConfig, PluginConfigTest.globalSource());
pluginConfig = pluginConfigManager.getConfig(PluginSourceConfigTest.DOMAIN, PluginSourceConfigTest.NAMESPACE, PluginSourceConfigTest.TEST_METRIC_ID);
checkPluginConfigString(pluginConfig, PluginConfigTest.globalSource());
Map<String, String> source = buildSource();
source.putAll(getSource("trace", TEST_TRACE_ID, PluginConfigTest.coverSource()));
source.putAll(getSource("trace", GLOBAL_ID, PluginConfigTest.coverSource()));
build(source);
Configs configs = new Configs(buildSource());
pluginConfigManager = PluginConfigManager.builder(configs).build();
final PluginConfig pluginConfig1 = pluginConfigManager.getConfig(DOMAIN, NAMESPACE, TEST_TRACE_ID);
final AtomicReference<IPluginConfig> oldPluginConfig = new AtomicReference<>();
final AtomicReference<IPluginConfig> newPluginConfig = new AtomicReference<>();
PluginConfigTest.checkAllType(pluginConfig1);
pluginConfig1.addChangeListener((oldConfig, newConfig) -> {
oldPluginConfig.set(oldConfig);
newPluginConfig.set(newConfig);
});
configs.updateConfigs(Collections.singletonMap(String.format("plugin.%s.%s.%s.enabled", DOMAIN, NAMESPACE, TEST_TRACE_ID), "false"));
assertNotNull(oldPluginConfig.get());
assertNotNull(newPluginConfig.get());
assertTrue(oldPluginConfig.get() == pluginConfig1);
final AtomicReference<PluginConfigChangeListener> oldPluginConfigListener = new AtomicReference<>();
final AtomicReference<PluginConfigChangeListener> newPluginConfigListener = new AtomicReference<>();
((PluginConfig) oldPluginConfig.get()).foreachConfigChangeListener(listener -> oldPluginConfigListener.set(listener));
((PluginConfig) newPluginConfig.get()).foreachConfigChangeListener(listener -> newPluginConfigListener.set(listener));
assertTrue(oldPluginConfigListener.get() == newPluginConfigListener.get());
assertTrue(oldPluginConfig.get().getBoolean("enabled"));
assertFalse(newPluginConfig.get().getBoolean("enabled"));
PluginConfigTest.checkAllType((PluginConfig) oldPluginConfig.get());
configs.updateConfigs(Collections.singletonMap(String.format("plugin.%s.%s.%s.enabled", DOMAIN, NAMESPACE, TEST_TRACE_ID), "true"));
assertFalse(oldPluginConfig.get().getBoolean("enabled"));
assertTrue(newPluginConfig.get().getBoolean("enabled"));
configs.updateConfigs(Collections.singletonMap(String.format("plugin.%s.global.%s.enabled", DOMAIN, TEST_TRACE_ID), "false"));
assertTrue(oldPluginConfig.get().getBoolean("enabled"));
assertFalse(newPluginConfig.get().getBoolean("enabled"));
IPluginConfig newConfig = newPluginConfig.get();
configs.updateConfigs(Collections.singletonMap(String.format("plugin.%s.global.%s.enabled", DOMAIN, TEST_AAA_ID), "false"));
assertTrue(newPluginConfig.get() == newConfig);
configs.updateConfigs(Collections.singletonMap(String.format("ssss.%s.global.%s.enabled", DOMAIN, TEST_AAA_ID), "false"));
}
use of com.megaease.easeagent.plugin.api.config.IPluginConfig in project easeagent by megaease.
the class SessionContextTest method getConfig.
@Test
public void getConfig() {
SessionContext sessionContext = new SessionContext();
assertNotNull(sessionContext.getConfig());
IPluginConfig iPluginConfig = sessionContext.getConfig();
assertEquals(NoOpIPluginConfig.INSTANCE.domain(), iPluginConfig.domain());
assertEquals(NoOpIPluginConfig.INSTANCE.namespace(), iPluginConfig.namespace());
assertEquals(NoOpIPluginConfig.INSTANCE.id(), iPluginConfig.id());
sessionContext.pushConfig(NoOpIPluginConfig.INSTANCE);
assertNotNull(sessionContext.getConfig());
PluginConfigManager pluginConfigManager = PluginConfigManager.builder(MockConfig.getCONFIGS()).build();
String domain = "observability";
String namespace = "test_config";
String id = "test";
PluginConfig config = pluginConfigManager.getConfig(domain, namespace, id);
sessionContext.pushConfig(config);
iPluginConfig = sessionContext.getConfig();
assertEquals(domain, iPluginConfig.domain());
assertEquals(namespace, iPluginConfig.namespace());
assertEquals(id, iPluginConfig.id());
IPluginConfig oppConfig = sessionContext.popConfig();
assertEquals(domain, oppConfig.domain());
assertEquals(namespace, oppConfig.namespace());
assertEquals(id, oppConfig.id());
iPluginConfig = sessionContext.getConfig();
assertEquals(NoOpIPluginConfig.INSTANCE.domain(), iPluginConfig.domain());
assertEquals(NoOpIPluginConfig.INSTANCE.namespace(), iPluginConfig.namespace());
assertEquals(NoOpIPluginConfig.INSTANCE.id(), iPluginConfig.id());
}
use of com.megaease.easeagent.plugin.api.config.IPluginConfig in project easeagent by megaease.
the class MongoBaseTest method before.
@Before
public void before() {
EaseAgent.initializeContextSupplier.get().clear();
config = new AutoRefreshPluginConfigImpl();
IPluginConfig iPluginConfig = mock(IPluginConfig.class);
when(iPluginConfig.enabled()).thenReturn(true);
when(iPluginConfig.namespace()).thenReturn("mongodb");
when(iPluginConfig.domain()).thenReturn("observability");
config.onChange(null, iPluginConfig);
Context context = EaseAgent.getContext();
ContextUtils.setBeginTime(context);
MockEaseAgent.cleanLastSpan();
clusterId = new ClusterId("local-cluster");
serverAddress = new ServerAddress("127.0.0.1", 2020);
serverId = new ServerId(clusterId, serverAddress);
this.connectionDescription = new ConnectionDescription(serverId);
Map<String, Object> map = new HashMap<>();
map.put("collection", collection);
BsonDocument bsonDocument = BsonDocument.parse(JsonUtil.toJson(map));
this.startedEvent = new CommandStartedEvent(this.requestId, this.connectionDescription, this.dbName, this.cmdName, bsonDocument);
}
use of com.megaease.easeagent.plugin.api.config.IPluginConfig in project easeagent by megaease.
the class RabbitMqConsumerMetricTest method metricAfter.
@Test
public void metricAfter() {
IPluginConfig config = TestUtils.getMqMetricConfig();
RabbitMqConsumerMetric metric = EaseAgent.getOrCreateServiceMetric(config, RabbitMqConsumerMetric.buildConsumerTags(), RabbitMqConsumerMetric.SERVICE_METRIC_SUPPLIER);
String key = "testMetricAfter";
metric.metricAfter(key, System.currentTimeMillis() - 101, true);
TagVerifier tagVerifier = TagVerifier.build(RabbitMqConsumerMetric.buildConsumerTags(), key);
LastJsonReporter lastJsonReporter = MockEaseAgent.lastMetricJsonReporter(tagVerifier::verifyAnd);
Map<String, Object> metrics = lastJsonReporter.flushAndOnlyOne();
assertTrue((int) (double) metrics.get(MetricField.MIN_EXECUTION_TIME.getField()) > 100);
Meter meter = metric.meter(key, MetricSubType.CONSUMER);
Meter meterError = metric.meter(key, MetricSubType.CONSUMER_ERROR);
assertEquals(1, meter.getCount());
assertEquals(0, meterError.getCount());
metric.metricAfter(key, System.currentTimeMillis() - 100, false);
assertEquals(2, meter.getCount());
assertEquals(1, meterError.getCount());
}
use of com.megaease.easeagent.plugin.api.config.IPluginConfig in project easeagent by megaease.
the class ServletHttpLogInterceptorTest method init.
@Test
public void init() {
ServletHttpLogInterceptor servletHttpLogInterceptor = new ServletHttpLogInterceptor();
AccessPlugin accessPlugin = new AccessPlugin();
IPluginConfig iPluginConfig = EaseAgent.getConfig(accessPlugin.getDomain(), accessPlugin.getNamespace(), servletHttpLogInterceptor.getType());
servletHttpLogInterceptor.init(iPluginConfig, "", "", "");
assertNotNull(AgentFieldReflectAccessor.getFieldValue(servletHttpLogInterceptor, "reportConsumer"));
}
Aggregations