Skip to content

Commit 6e87ed4

Browse files
committed
[#9903] add system metric host management function
1 parent 704bd85 commit 6e87ed4

18 files changed

+773
-23
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,111 @@
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.pinot.tenant.TenantProvider;
6+
import org.apache.logging.log4j.LogManager;
7+
import org.apache.logging.log4j.Logger;
8+
import org.springframework.http.HttpStatus;
9+
import org.springframework.web.bind.annotation.DeleteMapping;
10+
import org.springframework.web.bind.annotation.GetMapping;
11+
import org.springframework.web.bind.annotation.PostMapping;
12+
import org.springframework.web.bind.annotation.RequestMapping;
13+
import org.springframework.web.bind.annotation.RequestParam;
14+
import org.springframework.web.bind.annotation.RestController;
15+
import org.springframework.web.server.ResponseStatusException;
16+
17+
@RestController
18+
@RequestMapping(value = "/systemMetric/exclusion")
19+
public class SystemMetricExclusionController {
20+
private final Logger logger = LogManager.getLogger(this.getClass());
21+
22+
private final SystemMetricHostExclusionService systemMetricHostExclusionService;
23+
private final TenantProvider tenantProvider;
24+
25+
public SystemMetricExclusionController(SystemMetricHostExclusionService systemMetricHostExclusionService, TenantProvider tenantProvider) {
26+
this.systemMetricHostExclusionService = systemMetricHostExclusionService;
27+
this.tenantProvider = tenantProvider;
28+
}
29+
30+
@GetMapping(value = "/hostGroup")
31+
public SystemMetricHostGroupInfo getHostGroupExclusionInfo(@RequestParam("hostGroupName") String hostGroupName) {
32+
String tenantId = tenantProvider.getTenantId();
33+
return systemMetricHostExclusionService.getHostGroupInfo(tenantId, hostGroupName);
34+
}
35+
36+
@PostMapping(value = "/hostGroup")
37+
public String insertHostGroupExclusion(@RequestParam("hostGroupName") String hostGroupName) {
38+
logger.debug("add hostGroup exclusion - hostGroupName: [{}]", hostGroupName);
39+
try {
40+
systemMetricHostExclusionService.insertHostGroupExclusion(hostGroupName);
41+
return "OK";
42+
} catch (Exception e) {
43+
logger.error("error while excluding hostGroupName", e);
44+
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage());
45+
}
46+
}
47+
48+
@DeleteMapping(value = "/hostGroup")
49+
public String deleteHostGroupExclusion(@RequestParam("hostGroupName") String hostGroupName) {
50+
logger.debug("delete host group exclusion - hostGroupName: [{}]", hostGroupName);
51+
try {
52+
systemMetricHostExclusionService.deleteHostGroupExclusion(hostGroupName);
53+
return "OK";
54+
} catch (Exception e) {
55+
logger.error("error while accepting hostGroupName", e);
56+
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage());
57+
}
58+
}
59+
60+
@PostMapping(value = "/hostGroup/host")
61+
public String insertHostExclusion(@RequestParam String hostGroupName,
62+
@RequestParam String hostName) {
63+
logger.debug("add host exclusion - hostGroupName: [{}], hostName: [{}]", hostGroupName, hostName);
64+
try {
65+
systemMetricHostExclusionService.insertHostExclusion(hostGroupName, hostName);
66+
return "OK";
67+
} catch (Exception e) {
68+
logger.error("error while excluding hostName", e);
69+
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage());
70+
}
71+
}
72+
73+
@DeleteMapping(value = "/hostGroup/host")
74+
public String deleteHostExclusion(@RequestParam("hostGroupName") String hostGroupName,
75+
@RequestParam("hostName") String hostName) {
76+
logger.debug("delete host exclusion - hostGroupName: [{}], hostName: [{}]", hostGroupName, hostName);
77+
try {
78+
systemMetricHostExclusionService.deleteHostExclusion(hostGroupName, hostName);
79+
return "OK";
80+
} catch (Exception e) {
81+
logger.error("error while deleting host exclusion", e);
82+
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage());
83+
}
84+
}
85+
86+
@DeleteMapping(value = "/hostGroup/unusedHosts")
87+
public String deleteUnusedHostExclusions(@RequestParam("hostGroupName") String hostGroupName) {
88+
logger.debug("delete unused hosts exclusions - hostGroupName: [{}]", hostGroupName);
89+
String tenantId = tenantProvider.getTenantId();
90+
try {
91+
systemMetricHostExclusionService.deleteUnusedHostExclusions(tenantId, hostGroupName);
92+
return "OK";
93+
} catch (Exception e) {
94+
logger.error("error while deleting unused host exclusions", e);
95+
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage());
96+
}
97+
}
98+
99+
@DeleteMapping(value = "/cleanupUnusedGroups")
100+
public String deleteUnusedGroupExclusions() {
101+
logger.debug("delete exclusions from unused groups");
102+
String tenantId = tenantProvider.getTenantId();
103+
try {
104+
systemMetricHostExclusionService.deleteUnusedGroupExclusions(tenantId);
105+
return "OK";
106+
} catch (Exception e) {
107+
logger.error("error while deleting exclusions from unused groups", e);
108+
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage());
109+
}
110+
}
111+
}
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

+6-5
Original file line numberDiff line numberDiff line change
@@ -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 = "showExcluded", defaultValue = "false") boolean showExcluded) {
6666
String tenantId = tenantProvider.getTenantId();
67-
return systemMetricHostInfoService.getHostGroupNameList(tenantId);
67+
return systemMetricHostInfoService.getHostGroupNameList(tenantId, showExcluded);
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 = "showExcluded", defaultValue = "false") boolean showExcluded) {
7273
String tenantId = tenantProvider.getTenantId();
73-
return systemMetricHostInfoService.getHostList(tenantId, hostGroupName);
74+
return systemMetricHostInfoService.getHostList(tenantId, hostGroupName, showExcluded);
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+
List<String> selectGroupNameListFromHostExclusion();
20+
21+
void deleteHostExclusions(String hostGroupName);
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 List<String> selectGroupNameListFromHostExclusion() {
57+
return sqlMetricSessionTemplate.selectList(NAMESPACE + "selectGroupNamesFromHostExclusion");
58+
}
59+
60+
@Override
61+
public void deleteHostExclusions(String hostGroupName) {
62+
sqlMetricSessionTemplate.delete(NAMESPACE + "deleteHostExclusions", hostGroupName);
63+
}
64+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.navercorp.pinpoint.metric.web.service;
2+
3+
import com.navercorp.pinpoint.metric.web.view.SystemMetricHostGroupInfo;
4+
5+
public interface SystemMetricHostExclusionService {
6+
7+
SystemMetricHostGroupInfo getHostGroupInfo(String tenantId, String hostGroupName);
8+
9+
void insertHostGroupExclusion(String hostGroupName);
10+
11+
void deleteHostGroupExclusion(String hostGroupName);
12+
13+
void deleteUnusedGroupExclusions(String tenantId);
14+
15+
void insertHostExclusion(String hostGroupName, String hostName);
16+
17+
void deleteHostExclusion(String hostGroupName, String hostName);
18+
19+
void deleteUnusedHostExclusions(String tenantId, String hostGroupName);
20+
}

0 commit comments

Comments
 (0)