Search in sources :

Example 1 with IPluginConfig

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"));
}
Also used : IPluginConfig(com.megaease.easeagent.plugin.api.config.IPluginConfig) PluginConfigChangeListener(com.megaease.easeagent.plugin.api.config.PluginConfigChangeListener) AtomicReference(java.util.concurrent.atomic.AtomicReference) IPluginConfig(com.megaease.easeagent.plugin.api.config.IPluginConfig) Test(org.junit.Test)

Example 2 with IPluginConfig

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());
}
Also used : PluginConfig(com.megaease.easeagent.config.PluginConfig) IPluginConfig(com.megaease.easeagent.plugin.api.config.IPluginConfig) NoOpIPluginConfig(com.megaease.easeagent.plugin.bridge.NoOpIPluginConfig) PluginConfigManager(com.megaease.easeagent.config.PluginConfigManager) IPluginConfig(com.megaease.easeagent.plugin.api.config.IPluginConfig) NoOpIPluginConfig(com.megaease.easeagent.plugin.bridge.NoOpIPluginConfig) Test(org.junit.Test)

Example 3 with IPluginConfig

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);
}
Also used : Context(com.megaease.easeagent.plugin.api.Context) ClusterId(com.mongodb.connection.ClusterId) HashMap(java.util.HashMap) ServerAddress(com.mongodb.ServerAddress) ConnectionDescription(com.mongodb.connection.ConnectionDescription) ServerId(com.mongodb.connection.ServerId) BsonDocument(org.bson.BsonDocument) CommandStartedEvent(com.mongodb.event.CommandStartedEvent) AutoRefreshPluginConfigImpl(com.megaease.easeagent.plugin.api.config.AutoRefreshPluginConfigImpl) IPluginConfig(com.megaease.easeagent.plugin.api.config.IPluginConfig) Before(org.junit.Before)

Example 4 with IPluginConfig

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());
}
Also used : TagVerifier(com.megaease.easeagent.mock.plugin.api.utils.TagVerifier) LastJsonReporter(com.megaease.easeagent.mock.report.impl.LastJsonReporter) Meter(com.megaease.easeagent.plugin.api.metric.Meter) IPluginConfig(com.megaease.easeagent.plugin.api.config.IPluginConfig) Test(org.junit.Test)

Example 5 with IPluginConfig

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"));
}
Also used : AccessPlugin(com.megaease.easeagent.plugin.httpservlet.AccessPlugin) IPluginConfig(com.megaease.easeagent.plugin.api.config.IPluginConfig) Test(org.junit.Test)

Aggregations

IPluginConfig (com.megaease.easeagent.plugin.api.config.IPluginConfig)28 Test (org.junit.Test)18 LastJsonReporter (com.megaease.easeagent.mock.report.impl.LastJsonReporter)7 TagVerifier (com.megaease.easeagent.mock.plugin.api.utils.TagVerifier)5 MetricRegistry (com.megaease.easeagent.plugin.api.metric.MetricRegistry)3 NoOpIPluginConfig (com.megaease.easeagent.plugin.bridge.NoOpIPluginConfig)3 MethodInfo (com.megaease.easeagent.plugin.interceptor.MethodInfo)3 Context (com.megaease.easeagent.plugin.api.Context)2 InitializeContext (com.megaease.easeagent.plugin.api.InitializeContext)2 Reporter (com.megaease.easeagent.plugin.api.Reporter)2 Meter (com.megaease.easeagent.plugin.api.metric.Meter)2 ServiceMetric (com.megaease.easeagent.plugin.api.metric.ServiceMetric)2 NameFactory (com.megaease.easeagent.plugin.api.metric.name.NameFactory)2 AccessPlugin (com.megaease.easeagent.plugin.httpservlet.AccessPlugin)2 HttpServletPlugin (com.megaease.easeagent.plugin.httpservlet.HttpServletPlugin)2 KafkaPlugin (com.megaease.easeagent.plugin.kafka.KafkaPlugin)2 RedisPlugin (com.megaease.easeagent.plugin.redis.RedisPlugin)2 HashMap (java.util.HashMap)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2