-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#9903] system metric host management
- Loading branch information
1 parent
a5dff7d
commit 97bd678
Showing
19 changed files
with
780 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
...vercorp/pinpoint/metric/web/authorization/controller/SystemMetricExclusionController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
package com.navercorp.pinpoint.metric.web.authorization.controller; | ||
|
||
import com.navercorp.pinpoint.metric.web.service.SystemMetricHostExclusionService; | ||
import com.navercorp.pinpoint.metric.web.view.SystemMetricHostGroupInfo; | ||
import com.navercorp.pinpoint.metric.web.view.SystemMetricHostInfo; | ||
import com.navercorp.pinpoint.pinot.tenant.TenantProvider; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.server.ResponseStatusException; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping(value = "/exclusion/systemMetric") | ||
public class SystemMetricExclusionController { | ||
private final Logger logger = LogManager.getLogger(this.getClass()); | ||
|
||
private final SystemMetricHostExclusionService systemMetricHostExclusionService; | ||
private final TenantProvider tenantProvider; | ||
|
||
public SystemMetricExclusionController(SystemMetricHostExclusionService systemMetricHostExclusionService, TenantProvider tenantProvider) { | ||
this.systemMetricHostExclusionService = systemMetricHostExclusionService; | ||
this.tenantProvider = tenantProvider; | ||
} | ||
|
||
@GetMapping(value = "/hostGroup/hostGroupInfo") | ||
public SystemMetricHostGroupInfo getHostGroupExclusionInfo(@RequestParam("hostGroupName") String hostGroupName) { | ||
String tenantId = tenantProvider.getTenantId(); | ||
return systemMetricHostExclusionService.getHostGroupInfo(tenantId, hostGroupName); | ||
} | ||
|
||
@GetMapping(value = "/hostGroup/hostInfoList") | ||
public List<SystemMetricHostInfo> getHostExclusionInfoList( | ||
@RequestParam("hostGroupName") String hostGroupName) { | ||
String tenantId = tenantProvider.getTenantId(); | ||
List<SystemMetricHostInfo> result = systemMetricHostExclusionService.getHostInfoList(tenantId, hostGroupName); | ||
|
||
return result; | ||
} | ||
|
||
@PostMapping(value = "/hostGroup") | ||
public String insertHostGroupExclusion(@RequestParam("hostGroupName") String hostGroupName) { | ||
logger.debug("add hostGroup exclusion - hostGroupName: [{}]", hostGroupName); | ||
try { | ||
systemMetricHostExclusionService.insertHostGroupExclusion(hostGroupName); | ||
return "OK"; | ||
} catch (Exception e) { | ||
logger.error("error while adding hostGroup exclusion", e); | ||
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage()); | ||
} | ||
} | ||
|
||
@DeleteMapping(value = "/hostGroup") | ||
public String deleteHostGroupExclusion(@RequestParam("hostGroupName") String hostGroupName) { | ||
logger.debug("delete host group exclusion - hostGroupName: [{}]", hostGroupName); | ||
try { | ||
systemMetricHostExclusionService.deleteHostGroupExclusion(hostGroupName); | ||
return "OK"; | ||
} catch (Exception e) { | ||
logger.error("error while deleting hostGroup exclusion", e); | ||
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage()); | ||
} | ||
} | ||
|
||
@PostMapping(value = "/hostGroup/host") | ||
public String insertHostExclusion(@RequestParam("hostGroupName") String hostGroupName, | ||
@RequestParam("hostName") String hostName) { | ||
logger.debug("add host exclusion - hostGroupName: [{}], hostName: [{}]", hostGroupName, hostName); | ||
try { | ||
systemMetricHostExclusionService.insertHostExclusion(hostGroupName, hostName); | ||
return "OK"; | ||
} catch (Exception e) { | ||
logger.error("error while adding host exclusion", e); | ||
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage()); | ||
} | ||
} | ||
|
||
@DeleteMapping(value = "/hostGroup/host") | ||
public String deleteHostExclusion(@RequestParam("hostGroupName") String hostGroupName, | ||
@RequestParam("hostName") String hostName) { | ||
logger.debug("delete host exclusion - hostGroupName: [{}], hostName: [{}]", hostGroupName, hostName); | ||
try { | ||
systemMetricHostExclusionService.deleteHostExclusion(hostGroupName, hostName); | ||
return "OK"; | ||
} catch (Exception e) { | ||
logger.error("error while deleting host exclusion", e); | ||
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage()); | ||
} | ||
} | ||
|
||
@DeleteMapping(value = "/hostGroup/unusedHosts") | ||
public String deleteUnusedHostExclusions(@RequestParam("hostGroupName") String hostGroupName) { | ||
logger.debug("delete unused host exclusions - hostGroupName: [{}]", hostGroupName); | ||
String tenantId = tenantProvider.getTenantId(); | ||
try { | ||
systemMetricHostExclusionService.deleteUnusedHostExclusions(tenantId, hostGroupName); | ||
return "OK"; | ||
} catch (Exception e) { | ||
logger.error("error while deleting unused host exclusions", e); | ||
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage()); | ||
} | ||
} | ||
|
||
@DeleteMapping(value = "/unusedGroups") | ||
public String deleteUnusedGroupExclusions() { | ||
logger.debug("delete exclusions from unused groups"); | ||
String tenantId = tenantProvider.getTenantId(); | ||
try { | ||
systemMetricHostExclusionService.deleteUnusedGroupExclusions(tenantId); | ||
return "OK"; | ||
} catch (Exception e) { | ||
logger.error("error while deleting exclusions from unused groups", e); | ||
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage()); | ||
} | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...rc/main/java/com/navercorp/pinpoint/metric/web/config/MetricWebMysqlDaoConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.navercorp.pinpoint.metric.web.config; | ||
|
||
import com.navercorp.pinpoint.metric.collector.config.MyBatisRegistryHandler; | ||
import com.navercorp.pinpoint.pinot.mybatis.MyBatisConfiguration; | ||
import org.apache.ibatis.session.Configuration; | ||
import org.apache.ibatis.session.SqlSessionFactory; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.mybatis.spring.SqlSessionFactoryBean; | ||
import org.mybatis.spring.SqlSessionTemplate; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.core.io.Resource; | ||
|
||
import javax.sql.DataSource; | ||
|
||
@org.springframework.context.annotation.Configuration | ||
public class MetricWebMysqlDaoConfiguration { | ||
private final Logger logger = LogManager.getLogger(MetricWebMysqlDaoConfiguration.class); | ||
|
||
@Bean | ||
public SqlSessionFactoryBean metricSqlSessionFactory( | ||
@Qualifier("dataSource") DataSource dataSource, | ||
@Value("classpath*:/pinot-web/mapper/mysql/*Mapper.xml") Resource[] mappers) { | ||
|
||
for (Resource mapper : mappers) { | ||
logger.info("Mapper location: {}", mapper.getDescription()); | ||
} | ||
|
||
SqlSessionFactoryBean sessionFactoryBean = new SqlSessionFactoryBean(); | ||
sessionFactoryBean.setDataSource(dataSource); | ||
sessionFactoryBean.setMapperLocations(mappers); | ||
|
||
Configuration config = MyBatisConfiguration.defaultConfiguration(); | ||
sessionFactoryBean.setConfiguration(config); | ||
|
||
MyBatisRegistryHandler registry = registryHandler(); | ||
registry.registerTypeAlias(config.getTypeAliasRegistry()); | ||
|
||
sessionFactoryBean.setFailFast(true); | ||
|
||
return sessionFactoryBean; | ||
} | ||
|
||
private MyBatisRegistryHandler registryHandler() { | ||
return new WebRegistryHandler(); | ||
} | ||
|
||
@Bean | ||
public SqlSessionTemplate metricSqlSessionTemplate( | ||
@Qualifier("metricSqlSessionFactory") SqlSessionFactory sessionFactory) { | ||
return new SqlSessionTemplate(sessionFactory); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...ric/src/main/java/com/navercorp/pinpoint/metric/web/dao/SystemMetricHostExclusionDao.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.navercorp.pinpoint.metric.web.dao; | ||
|
||
import java.util.List; | ||
|
||
public interface SystemMetricHostExclusionDao { | ||
|
||
List<String> selectExcludedHostGroupNameList(); | ||
|
||
void insertHostGroupExclusion(String hostGroupName); | ||
|
||
void deleteHostGroupExclusion(String hostGroupName); | ||
|
||
List<String> selectExcludedHostNameList(String hostGroupName); | ||
|
||
void insertHostExclusion(String hostGroupName, String hostName); | ||
|
||
void deleteHostExclusion(String hostGroupName, String hostName); | ||
|
||
void deleteHostExclusions(String hostGroupName); | ||
|
||
List<String> selectGroupNameListFromHostExclusion(); | ||
} |
37 changes: 37 additions & 0 deletions
37
...ric/src/main/java/com/navercorp/pinpoint/metric/web/dao/model/HostExclusionSearchKey.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright 2023 NAVER Corp. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.navercorp.pinpoint.metric.web.dao.model; | ||
|
||
import java.util.Objects; | ||
|
||
public class HostExclusionSearchKey { | ||
private final String hostGroupName; | ||
private final String hostName; | ||
|
||
public HostExclusionSearchKey(String hostGroupName, String hostName) { | ||
this.hostGroupName = Objects.requireNonNull(hostGroupName, "hostGroupName"); | ||
this.hostName = Objects.requireNonNull(hostName, "hostName"); | ||
} | ||
|
||
public String getHostGroupName() { | ||
return hostGroupName; | ||
} | ||
|
||
public String getHostName() { | ||
return hostName; | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
...n/java/com/navercorp/pinpoint/metric/web/dao/mysql/MysqlSystemMetricHostExclusionDao.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.navercorp.pinpoint.metric.web.dao.mysql; | ||
|
||
import com.navercorp.pinpoint.metric.web.dao.SystemMetricHostExclusionDao; | ||
import com.navercorp.pinpoint.metric.web.dao.model.HostExclusionSearchKey; | ||
import org.mybatis.spring.SqlSessionTemplate; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.context.annotation.Primary; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
@Primary | ||
@Repository | ||
public class MysqlSystemMetricHostExclusionDao implements SystemMetricHostExclusionDao { | ||
|
||
private static final String NAMESPACE = MysqlSystemMetricHostExclusionDao.class.getName() + "."; | ||
|
||
private final SqlSessionTemplate sqlMetricSessionTemplate; | ||
|
||
public MysqlSystemMetricHostExclusionDao(@Qualifier("metricSqlSessionTemplate") SqlSessionTemplate sqlMetricSessionTemplate) { | ||
this.sqlMetricSessionTemplate = Objects.requireNonNull(sqlMetricSessionTemplate, "sqlSessionTemplate"); | ||
} | ||
|
||
@Override | ||
public List<String> selectExcludedHostGroupNameList() { | ||
return sqlMetricSessionTemplate.selectList(NAMESPACE + "selectExcludedHostGroupNames"); | ||
} | ||
|
||
@Override | ||
public void insertHostGroupExclusion(String hostGroupName) { | ||
sqlMetricSessionTemplate.insert(NAMESPACE + "insertHostGroupExclusion", hostGroupName); | ||
} | ||
|
||
@Override | ||
public void deleteHostGroupExclusion(String hostGroupName) { | ||
sqlMetricSessionTemplate.delete(NAMESPACE + "deleteHostGroupExclusion", hostGroupName); | ||
} | ||
|
||
@Override | ||
public List<String> selectExcludedHostNameList(String hostGroupName) { | ||
return sqlMetricSessionTemplate.selectList(NAMESPACE + "selectExcludedHostNames", hostGroupName); | ||
} | ||
|
||
@Override | ||
public void insertHostExclusion(String hostGroupName, String hostName) { | ||
sqlMetricSessionTemplate.insert(NAMESPACE + "insertHostExclusion", new HostExclusionSearchKey(hostGroupName, hostName)); | ||
} | ||
|
||
@Override | ||
public void deleteHostExclusion(String hostGroupName, String hostName) { | ||
sqlMetricSessionTemplate.delete(NAMESPACE + "deleteHostExclusion", new HostExclusionSearchKey(hostGroupName, hostName)); | ||
} | ||
|
||
@Override | ||
public void deleteHostExclusions(String hostGroupName) { | ||
sqlMetricSessionTemplate.delete(NAMESPACE + "deleteHostExclusions", hostGroupName); | ||
} | ||
|
||
@Override | ||
public List<String> selectGroupNameListFromHostExclusion() { | ||
return sqlMetricSessionTemplate.selectList(NAMESPACE + "selectGroupNamesFromHostExclusion"); | ||
} | ||
} |
Oops, something went wrong.