|
|
@ -20,50 +20,83 @@ package com.tencent.cloud.rpc.enhancement.stat.plugin;
|
|
|
|
import java.util.Objects;
|
|
|
|
import java.util.Objects;
|
|
|
|
|
|
|
|
|
|
|
|
import com.tencent.cloud.rpc.enhancement.stat.config.PolarisStatProperties;
|
|
|
|
import com.tencent.cloud.rpc.enhancement.stat.config.PolarisStatProperties;
|
|
|
|
|
|
|
|
import com.tencent.cloud.rpc.enhancement.stat.config.PolarisStatPropertiesAutoConfiguration;
|
|
|
|
import com.tencent.cloud.rpc.enhancement.stat.config.plugin.PrometheusPushGatewayContainer;
|
|
|
|
import com.tencent.cloud.rpc.enhancement.stat.config.plugin.PrometheusPushGatewayContainer;
|
|
|
|
import org.junit.Test;
|
|
|
|
import org.junit.Test;
|
|
|
|
import org.junit.jupiter.api.Assertions;
|
|
|
|
import org.junit.jupiter.api.Assertions;
|
|
|
|
import org.junit.runner.RunWith;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
|
|
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
|
|
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
|
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
|
|
|
|
|
|
import org.springframework.context.ApplicationContext;
|
|
|
|
|
|
|
|
import org.springframework.test.context.junit4.SpringRunner;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Test for {@link PrometheusPushGatewayContainer}.
|
|
|
|
* Test for {@link PrometheusPushGatewayContainer}.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @author lingxiao.wlx
|
|
|
|
* @author lingxiao.wlx
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@RunWith(SpringRunner.class)
|
|
|
|
|
|
|
|
@SpringBootTest(webEnvironment = RANDOM_PORT,
|
|
|
|
|
|
|
|
classes = PrometheusPushGatewayContainerTest.TestApplication.class,
|
|
|
|
|
|
|
|
properties = {"spring.cloud.polaris.stat.pushgateway.enabled=true",
|
|
|
|
|
|
|
|
"spring.cloud.polaris.stat.enabled=true",
|
|
|
|
|
|
|
|
"spring.cloud.polaris.stat.pushgateway.shut-down-strategy=DELETE",
|
|
|
|
|
|
|
|
"spring.cloud.polaris.stat.pushgateway.push-rate=1m",
|
|
|
|
|
|
|
|
"spring.cloud.polaris.stat.pushgateway.job=test",
|
|
|
|
|
|
|
|
"spring.cloud.polaris.stat.pushgateway.grouping-keys.instance=test"})
|
|
|
|
|
|
|
|
public class PrometheusPushGatewayContainerTest {
|
|
|
|
public class PrometheusPushGatewayContainerTest {
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
@Test
|
|
|
|
private ApplicationContext applicationContext;
|
|
|
|
public void testWithPushGatewayAndPushGatewayEnabled() {
|
|
|
|
|
|
|
|
ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
|
|
|
|
|
|
|
.withPropertyValues("spring.cloud.polaris.stat.pushgateway.enabled=true")
|
|
|
|
|
|
|
|
.withPropertyValues("spring.cloud.polaris.stat.enabled=true")
|
|
|
|
|
|
|
|
.withConfiguration(AutoConfigurations.of(PolarisStatPropertiesAutoConfiguration.class));
|
|
|
|
|
|
|
|
contextRunner.run(context -> {
|
|
|
|
|
|
|
|
assertThat(context).hasSingleBean(PrometheusPushGatewayContainer.class);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void testWithoutPushGatewayEnabled() {
|
|
|
|
|
|
|
|
ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
|
|
|
|
|
|
|
.withPropertyValues("spring.cloud.polaris.stat.pushgateway.enabled=false")
|
|
|
|
|
|
|
|
.withPropertyValues("spring.cloud.polaris.stat.enabled=true")
|
|
|
|
|
|
|
|
.withConfiguration(AutoConfigurations.of(PolarisStatPropertiesAutoConfiguration.class));
|
|
|
|
|
|
|
|
contextRunner.run(context -> {
|
|
|
|
|
|
|
|
assertThat(context).doesNotHaveBean(PrometheusPushGatewayContainer.class);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void prometheusPushGatewayContainerTest() {
|
|
|
|
public void testWithoutStatEnabled() {
|
|
|
|
PolarisStatProperties polarisStatProperties = applicationContext.getBean(PolarisStatProperties.class);
|
|
|
|
ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
|
|
|
PolarisStatProperties.PushGatewayProperties pushgateway = polarisStatProperties.getPushgateway();
|
|
|
|
.withPropertyValues("spring.cloud.polaris.stat.pushgateway.enabled=true")
|
|
|
|
Assertions.assertFalse(Objects.isNull(pushgateway));
|
|
|
|
.withPropertyValues("spring.cloud.polaris.stat.enabled=false")
|
|
|
|
Assertions.assertEquals(pushgateway.getJob(), "test");
|
|
|
|
.withConfiguration(AutoConfigurations.of(PolarisStatPropertiesAutoConfiguration.class));
|
|
|
|
Assertions.assertEquals(pushgateway.getPushRate().toMillis(), 60000);
|
|
|
|
contextRunner.run(context -> {
|
|
|
|
Assertions.assertEquals(pushgateway.getShutDownStrategy(), PolarisStatProperties.ShutDownStrategy.DELETE);
|
|
|
|
assertThat(context).doesNotHaveBean(PrometheusPushGatewayContainer.class);
|
|
|
|
applicationContext.getBean(PrometheusPushGatewayContainer.class);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@SpringBootApplication
|
|
|
|
@Test
|
|
|
|
protected static class TestApplication {
|
|
|
|
public void testWithoutPushGatewayAndStatEnabled() {
|
|
|
|
|
|
|
|
ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
|
|
|
|
|
|
|
.withPropertyValues("spring.cloud.polaris.stat.pushgateway.enabled=false")
|
|
|
|
|
|
|
|
.withPropertyValues("spring.cloud.polaris.stat.enabled=false")
|
|
|
|
|
|
|
|
.withConfiguration(AutoConfigurations.of(PolarisStatPropertiesAutoConfiguration.class));
|
|
|
|
|
|
|
|
contextRunner.run(context -> {
|
|
|
|
|
|
|
|
assertThat(context).doesNotHaveBean(PrometheusPushGatewayContainer.class);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void testPushGatewayProperties() {
|
|
|
|
|
|
|
|
ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
|
|
|
|
|
|
|
.withPropertyValues("spring.cloud.polaris.stat.pushgateway.enabled=true")
|
|
|
|
|
|
|
|
.withPropertyValues("spring.cloud.polaris.stat.enabled=true")
|
|
|
|
|
|
|
|
.withPropertyValues("spring.cloud.polaris.stat.pushgateway.job=test")
|
|
|
|
|
|
|
|
.withPropertyValues("spring.cloud.polaris.stat.pushgateway.grouping-keys.instance=test")
|
|
|
|
|
|
|
|
.withPropertyValues("spring.cloud.polaris.stat.pushgateway.push-rate=1m")
|
|
|
|
|
|
|
|
.withConfiguration(AutoConfigurations.of(PolarisStatPropertiesAutoConfiguration.class));
|
|
|
|
|
|
|
|
contextRunner.run(context -> {
|
|
|
|
|
|
|
|
assertThat(context).hasSingleBean(PrometheusPushGatewayContainer.class);
|
|
|
|
|
|
|
|
PolarisStatProperties properties = context.getBean(PolarisStatProperties.class);
|
|
|
|
|
|
|
|
PolarisStatProperties.PushGatewayProperties pushgateway = properties.getPushgateway();
|
|
|
|
|
|
|
|
Assertions.assertFalse(Objects.isNull(pushgateway));
|
|
|
|
|
|
|
|
Assertions.assertEquals(pushgateway.getJob(), "test");
|
|
|
|
|
|
|
|
Assertions.assertEquals(pushgateway.getPushRate().toMillis(), 60000);
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|