Skip to content

Commit 97bd678

Browse files
committed
[#9903] system metric host management
1 parent a5dff7d commit 97bd678

19 files changed

+780
-25
lines changed

metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/web/MetricWebApp.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.navercorp.pinpoint.metric.web;
22

33

4+
import com.navercorp.pinpoint.metric.web.config.MetricWebMysqlDaoConfiguration;
45
import com.navercorp.pinpoint.metric.web.config.MetricWebPinotDaoConfiguration;
56
import com.navercorp.pinpoint.pinot.config.PinotConfiguration;
67
import org.springframework.context.annotation.ComponentScan;
@@ -14,7 +15,8 @@
1415
@Import({
1516
WebMetricPropertySources.class,
1617
MetricWebPinotDaoConfiguration.class,
17-
PinotConfiguration.class
18+
PinotConfiguration.class,
19+
MetricWebMysqlDaoConfiguration.class
1820
})
1921
@Profile("metric")
2022
public class MetricWebApp {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
package com.navercorp.pinpoint.metric.web.authorization.controller;
2+
3+
import com.navercorp.pinpoint.metric.web.service.SystemMetricHostExclusionService;
4+
import com.navercorp.pinpoint.metric.web.view.SystemMetricHostGroupInfo;
5+
import com.navercorp.pinpoint.metric.web.view.SystemMetricHostInfo;
6+
import com.navercorp.pinpoint.pinot.tenant.TenantProvider;
7+
import org.apache.logging.log4j.LogManager;
8+
import org.apache.logging.log4j.Logger;
9+
import org.springframework.http.HttpStatus;
10+
import org.springframework.web.bind.annotation.DeleteMapping;
11+
import org.springframework.web.bind.annotation.GetMapping;
12+
import org.springframework.web.bind.annotation.PostMapping;
13+
import org.springframework.web.bind.annotation.RequestMapping;
14+
import org.springframework.web.bind.annotation.RequestParam;
15+
import org.springframework.web.bind.annotation.RestController;
16+
import org.springframework.web.server.ResponseStatusException;
17+
18+
import java.util.List;
19+
20+
@RestController
21+
@RequestMapping(value = "/exclusion/systemMetric")
22+
public class SystemMetricExclusionController {
23+
private final Logger logger = LogManager.getLogger(this.getClass());
24+
25+
private final SystemMetricHostExclusionService systemMetricHostExclusionService;
26+
private final TenantProvider tenantProvider;
27+
28+
public SystemMetricExclusionController(SystemMetricHostExclusionService systemMetricHostExclusionService, TenantProvider tenantProvider) {
29+
this.systemMetricHostExclusionService = systemMetricHostExclusionService;
30+
this.tenantProvider = tenantProvider;
31+
}
32+
33+
@GetMapping(value = "/hostGroup/hostGroupInfo")
34+
public SystemMetricHostGroupInfo getHostGroupExclusionInfo(@RequestParam("hostGroupName") String hostGroupName) {
35+
String tenantId = tenantProvider.getTenantId();
36+
return systemMetricHostExclusionService.getHostGroupInfo(tenantId, hostGroupName);
37+
}
38+
39+
@GetMapping(value = "/hostGroup/hostInfoList")
40+
public List<SystemMetricHostInfo> getHostExclusionInfoList(
41+
@RequestParam("hostGroupName") String hostGroupName) {
42+
String tenantId = tenantProvider.getTenantId();
43+
List<SystemMetricHostInfo> result = systemMetricHostExclusionService.getHostInfoList(tenantId, hostGroupName);
44+
45+
return result;
46+
}
47+
48+
@PostMapping(value = "/hostGroup")
49+
public String insertHostGroupExclusion(@RequestParam("hostGroupName") String hostGroupName) {
50+
logger.debug("add hostGroup exclusion - hostGroupName: [{}]", hostGroupName);
51+
try {
52+
systemMetricHostExclusionService.insertHostGroupExclusion(hostGroupName);
53+
return "OK";
54+
} catch (Exception e) {
55+
logger.error("error while adding hostGroup exclusion", e);
56+
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage());
57+
}
58+
}
59+
60+
@DeleteMapping(value = "/hostGroup")
61+
public String deleteHostGroupExclusion(@RequestParam("hostGroupName") String hostGroupName) {
62+
logger.debug("delete host group exclusion - hostGroupName: [{}]", hostGroupName);
63+
try {
64+
systemMetricHostExclusionService.deleteHostGroupExclusion(hostGroupName);
65+
return "OK";
66+
} catch (Exception e) {
67+
logger.error("error while deleting hostGroup exclusion", e);
68+
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage());
69+
}
70+
}
71+
72+
@PostMapping(value = "/hostGroup/host")
73+
public String insertHostExclusion(@RequestParam("hostGroupName") String hostGroupName,
74+
@RequestParam("hostName") String hostName) {
75+
logger.debug("add host exclusion - hostGroupName: [{}], hostName: [{}]", hostGroupName, hostName);
76+
try {
77+
systemMetricHostExclusionService.insertHostExclusion(hostGroupName, hostName);
78+
return "OK";
79+
} catch (Exception e) {
80+
logger.error("error while adding host exclusion", e);
81+
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage());
82+
}
83+
}
84+
85+
@DeleteMapping(value = "/hostGroup/host")
86+
public String deleteHostExclusion(@RequestParam("hostGroupName") String hostGroupName,
87+
@RequestParam("hostName") String hostName) {
88+
logger.debug("delete host exclusion - hostGroupName: [{}], hostName: [{}]", hostGroupName, hostName);
89+
try {
90+
systemMetricHostExclusionService.deleteHostExclusion(hostGroupName, hostName);
91+
return "OK";
92+
} catch (Exception e) {
93+
logger.error("error while deleting host exclusion", e);
94+
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage());
95+
}
96+
}
97+
98+
@DeleteMapping(value = "/hostGroup/unusedHosts")
99+
public String deleteUnusedHostExclusions(@RequestParam("hostGroupName") String hostGroupName) {
100+
logger.debug("delete unused host exclusions - hostGroupName: [{}]", hostGroupName);
101+
String tenantId = tenantProvider.getTenantId();
102+
try {
103+
systemMetricHostExclusionService.deleteUnusedHostExclusions(tenantId, hostGroupName);
104+
return "OK";
105+
} catch (Exception e) {
106+
logger.error("error while deleting unused host exclusions", e);
107+
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage());
108+
}
109+
}
110+
111+
@DeleteMapping(value = "/unusedGroups")
112+
public String deleteUnusedGroupExclusions() {
113+
logger.debug("delete exclusions from unused groups");
114+
String tenantId = tenantProvider.getTenantId();
115+
try {
116+
systemMetricHostExclusionService.deleteUnusedGroupExclusions(tenantId);
117+
return "OK";
118+
} catch (Exception e) {
119+
logger.error("error while deleting exclusions from unused groups", e);
120+
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage());
121+
}
122+
}
123+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.navercorp.pinpoint.metric.web.config;
2+
3+
import com.navercorp.pinpoint.metric.collector.config.MyBatisRegistryHandler;
4+
import com.navercorp.pinpoint.pinot.mybatis.MyBatisConfiguration;
5+
import org.apache.ibatis.session.Configuration;
6+
import org.apache.ibatis.session.SqlSessionFactory;
7+
import org.apache.logging.log4j.LogManager;
8+
import org.apache.logging.log4j.Logger;
9+
import org.mybatis.spring.SqlSessionFactoryBean;
10+
import org.mybatis.spring.SqlSessionTemplate;
11+
import org.springframework.beans.factory.annotation.Qualifier;
12+
import org.springframework.beans.factory.annotation.Value;
13+
import org.springframework.context.annotation.Bean;
14+
import org.springframework.core.io.Resource;
15+
16+
import javax.sql.DataSource;
17+
18+
@org.springframework.context.annotation.Configuration
19+
public class MetricWebMysqlDaoConfiguration {
20+
private final Logger logger = LogManager.getLogger(MetricWebMysqlDaoConfiguration.class);
21+
22+
@Bean
23+
public SqlSessionFactoryBean metricSqlSessionFactory(
24+
@Qualifier("dataSource") DataSource dataSource,
25+
@Value("classpath*:/pinot-web/mapper/mysql/*Mapper.xml") Resource[] mappers) {
26+
27+
for (Resource mapper : mappers) {
28+
logger.info("Mapper location: {}", mapper.getDescription());
29+
}
30+
31+
SqlSessionFactoryBean sessionFactoryBean = new SqlSessionFactoryBean();
32+
sessionFactoryBean.setDataSource(dataSource);
33+
sessionFactoryBean.setMapperLocations(mappers);
34+
35+
Configuration config = MyBatisConfiguration.defaultConfiguration();
36+
sessionFactoryBean.setConfiguration(config);
37+
38+
MyBatisRegistryHandler registry = registryHandler();
39+
registry.registerTypeAlias(config.getTypeAliasRegistry());
40+
41+
sessionFactoryBean.setFailFast(true);
42+
43+
return sessionFactoryBean;
44+
}
45+
46+
private MyBatisRegistryHandler registryHandler() {
47+
return new WebRegistryHandler();
48+
}
49+
50+
@Bean
51+
public SqlSessionTemplate metricSqlSessionTemplate(
52+
@Qualifier("metricSqlSessionFactory") SqlSessionFactory sessionFactory) {
53+
return new SqlSessionTemplate(sessionFactory);
54+
}
55+
}

metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/web/config/WebRegistryHandler.java

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.navercorp.pinpoint.metric.collector.config.MyBatisRegistryHandler;
44
import com.navercorp.pinpoint.metric.common.config.CommonRegistryHandler;
55
import com.navercorp.pinpoint.metric.common.model.Tag;
6+
import com.navercorp.pinpoint.metric.web.dao.model.HostExclusionSearchKey;
67
import com.navercorp.pinpoint.metric.web.dao.model.HostInfoSearchKey;
78
import com.navercorp.pinpoint.metric.web.dao.model.MetricInfoSearchKey;
89
import com.navercorp.pinpoint.metric.web.dao.model.MetricTagsSearchKey;
@@ -45,6 +46,8 @@ public void registerTypeAlias(TypeAliasRegistry typeAliasRegistry) {
4546
typeAliasRegistry.registerAlias("metricInfoSearchKey", MetricInfoSearchKey.class);
4647
typeAliasRegistry.registerAlias("metricTagsSearchKey", MetricTagsSearchKey.class);
4748
typeAliasRegistry.registerAlias("hostInfoSearchKey", HostInfoSearchKey.class);
49+
50+
typeAliasRegistry.registerAlias("hostExclusionSearchKey", HostExclusionSearchKey.class);
4851
}
4952

5053
@Override

metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/web/controller/SystemMetricController.java

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020 NAVER Corp.
2+
* Copyright 2023 NAVER Corp.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -50,7 +50,7 @@ public class SystemMetricController {
5050
private final TenantProvider tenantProvider;
5151

5252
private final TimeWindowSampler DEFAULT_TIME_WINDOW_SAMPLER = new TimeWindowSlotCentricSampler(10000L, 200);
53-
53+
5454
public SystemMetricController(SystemMetricDataService systemMetricDataService,
5555
SystemMetricHostInfoService systemMetricHostInfoService,
5656
YMLSystemMetricBasicGroupManager systemMetricBasicGroupManager,
@@ -62,15 +62,16 @@ public SystemMetricController(SystemMetricDataService systemMetricDataService,
6262
}
6363

6464
@GetMapping(value = "/hostGroup")
65-
public List<String> getHostGroup() {
65+
public List<String> getHostGroup(@RequestParam(value = "showAll", defaultValue = "false", required = false) boolean showAll) {
6666
String tenantId = tenantProvider.getTenantId();
67-
return systemMetricHostInfoService.getHostGroupNameList(tenantId);
67+
return systemMetricHostInfoService.getHostGroupNameList(tenantId, showAll);
6868
}
6969

7070
@GetMapping(value = "/hostGroup/host")
71-
public List<String> getHostGroup(@RequestParam("hostGroupName") String hostGroupName) {
71+
public List<String> getHostGroup(@RequestParam("hostGroupName") String hostGroupName,
72+
@RequestParam(value = "showAll", defaultValue = "false", required = false) boolean showAll) {
7273
String tenantId = tenantProvider.getTenantId();
73-
return systemMetricHostInfoService.getHostList(tenantId, hostGroupName);
74+
return systemMetricHostInfoService.getHostList(tenantId, hostGroupName, showAll);
7475
}
7576

7677
@GetMapping(value = "/hostGroup/host/collectedMetricInfoV2")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.navercorp.pinpoint.metric.web.dao;
2+
3+
import java.util.List;
4+
5+
public interface SystemMetricHostExclusionDao {
6+
7+
List<String> selectExcludedHostGroupNameList();
8+
9+
void insertHostGroupExclusion(String hostGroupName);
10+
11+
void deleteHostGroupExclusion(String hostGroupName);
12+
13+
List<String> selectExcludedHostNameList(String hostGroupName);
14+
15+
void insertHostExclusion(String hostGroupName, String hostName);
16+
17+
void deleteHostExclusion(String hostGroupName, String hostName);
18+
19+
void deleteHostExclusions(String hostGroupName);
20+
21+
List<String> selectGroupNameListFromHostExclusion();
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2023 NAVER Corp.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.navercorp.pinpoint.metric.web.dao.model;
18+
19+
import java.util.Objects;
20+
21+
public class HostExclusionSearchKey {
22+
private final String hostGroupName;
23+
private final String hostName;
24+
25+
public HostExclusionSearchKey(String hostGroupName, String hostName) {
26+
this.hostGroupName = Objects.requireNonNull(hostGroupName, "hostGroupName");
27+
this.hostName = Objects.requireNonNull(hostName, "hostName");
28+
}
29+
30+
public String getHostGroupName() {
31+
return hostGroupName;
32+
}
33+
34+
public String getHostName() {
35+
return hostName;
36+
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package com.navercorp.pinpoint.metric.web.dao.mysql;
2+
3+
import com.navercorp.pinpoint.metric.web.dao.SystemMetricHostExclusionDao;
4+
import com.navercorp.pinpoint.metric.web.dao.model.HostExclusionSearchKey;
5+
import org.mybatis.spring.SqlSessionTemplate;
6+
import org.springframework.beans.factory.annotation.Qualifier;
7+
import org.springframework.context.annotation.Primary;
8+
import org.springframework.stereotype.Repository;
9+
10+
import java.util.List;
11+
import java.util.Objects;
12+
13+
@Primary
14+
@Repository
15+
public class MysqlSystemMetricHostExclusionDao implements SystemMetricHostExclusionDao {
16+
17+
private static final String NAMESPACE = MysqlSystemMetricHostExclusionDao.class.getName() + ".";
18+
19+
private final SqlSessionTemplate sqlMetricSessionTemplate;
20+
21+
public MysqlSystemMetricHostExclusionDao(@Qualifier("metricSqlSessionTemplate") SqlSessionTemplate sqlMetricSessionTemplate) {
22+
this.sqlMetricSessionTemplate = Objects.requireNonNull(sqlMetricSessionTemplate, "sqlSessionTemplate");
23+
}
24+
25+
@Override
26+
public List<String> selectExcludedHostGroupNameList() {
27+
return sqlMetricSessionTemplate.selectList(NAMESPACE + "selectExcludedHostGroupNames");
28+
}
29+
30+
@Override
31+
public void insertHostGroupExclusion(String hostGroupName) {
32+
sqlMetricSessionTemplate.insert(NAMESPACE + "insertHostGroupExclusion", hostGroupName);
33+
}
34+
35+
@Override
36+
public void deleteHostGroupExclusion(String hostGroupName) {
37+
sqlMetricSessionTemplate.delete(NAMESPACE + "deleteHostGroupExclusion", hostGroupName);
38+
}
39+
40+
@Override
41+
public List<String> selectExcludedHostNameList(String hostGroupName) {
42+
return sqlMetricSessionTemplate.selectList(NAMESPACE + "selectExcludedHostNames", hostGroupName);
43+
}
44+
45+
@Override
46+
public void insertHostExclusion(String hostGroupName, String hostName) {
47+
sqlMetricSessionTemplate.insert(NAMESPACE + "insertHostExclusion", new HostExclusionSearchKey(hostGroupName, hostName));
48+
}
49+
50+
@Override
51+
public void deleteHostExclusion(String hostGroupName, String hostName) {
52+
sqlMetricSessionTemplate.delete(NAMESPACE + "deleteHostExclusion", new HostExclusionSearchKey(hostGroupName, hostName));
53+
}
54+
55+
@Override
56+
public void deleteHostExclusions(String hostGroupName) {
57+
sqlMetricSessionTemplate.delete(NAMESPACE + "deleteHostExclusions", hostGroupName);
58+
}
59+
60+
@Override
61+
public List<String> selectGroupNameListFromHostExclusion() {
62+
return sqlMetricSessionTemplate.selectList(NAMESPACE + "selectGroupNamesFromHostExclusion");
63+
}
64+
}

0 commit comments

Comments
 (0)