-
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] add system metric host management function
- Loading branch information
1 parent
6267cb9
commit 6c48ab0
Showing
21 changed files
with
786 additions
and
10 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
90 changes: 90 additions & 0 deletions
90
...orp/pinpoint/metric/web/authorization/controller/SystemMetricHostExclusionController.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,90 @@ | ||
package com.navercorp.pinpoint.metric.web.authorization.controller; | ||
|
||
import com.navercorp.pinpoint.metric.web.service.SystemMetricHostExclusionService; | ||
import com.navercorp.pinpoint.pinot.tenant.TenantProvider; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping(value = "/admin/systemMetric") | ||
public class SystemMetricHostExclusionController { | ||
private final Logger logger = LogManager.getLogger(this.getClass()); | ||
|
||
private final SystemMetricHostExclusionService systemMetricHostExclusionService; | ||
private final TenantProvider tenantProvider; | ||
|
||
public SystemMetricHostExclusionController(SystemMetricHostExclusionService systemMetricHostExclusionService, TenantProvider tenantProvider) { | ||
this.systemMetricHostExclusionService = systemMetricHostExclusionService; | ||
this.tenantProvider = tenantProvider; | ||
} | ||
|
||
@RequestMapping(value = "/hostGroup/addExclusion") | ||
public String excludeHostGroup(@RequestParam("hostGroupName") String hostGroupName) { | ||
logger.info("add hostGroup exclusion - hostGroupName: [{}]", hostGroupName); | ||
try { | ||
String tenantId = tenantProvider.getTenantId(); | ||
systemMetricHostExclusionService.insertHostGroupExclusion(tenantId, hostGroupName); | ||
return "OK"; | ||
} catch (Exception e) { | ||
logger.error("error while excluding hostGroupName", e); | ||
return e.getMessage(); | ||
} | ||
} | ||
|
||
@RequestMapping(value = "/hostGroup/host/addExclusion") | ||
public String excludeHostGroup(@RequestParam("hostGroupName") String hostGroupName, | ||
@RequestParam("hostName") String hostName) { | ||
logger.info("add host exclusion - hostGroupName: [{}], hostName: [{}]", hostGroupName, hostName); | ||
try { | ||
String tenantId = tenantProvider.getTenantId(); | ||
systemMetricHostExclusionService.insertHostExclusion(tenantId, hostGroupName, hostName); | ||
return "OK"; | ||
} catch (Exception e) { | ||
logger.error("error while excluding hostName", e); | ||
return e.getMessage(); | ||
} | ||
} | ||
|
||
@RequestMapping(value = "/hostGroup/removeExclusion") | ||
public String acceptHostGroup(@RequestParam("hostGroupName") String hostGroupName) { | ||
logger.info("remove host group exclusion - hostGroupName: [{}]", hostGroupName); | ||
try { | ||
String tenantId = tenantProvider.getTenantId(); | ||
systemMetricHostExclusionService.deleteHostGroupExclusion(tenantId, hostGroupName); | ||
return "OK"; | ||
} catch (Exception e) { | ||
logger.error("error while accepting hostGroupName", e); | ||
return e.getMessage(); | ||
} | ||
} | ||
|
||
@RequestMapping(value = "/hostGroup/host/removeExclusion") | ||
public String acceptHostGroup(@RequestParam("hostGroupName") String hostGroupName, | ||
@RequestParam("hostName") String hostName) { | ||
logger.info("remove host exclusion - hostGroupName: [{}], hostName: [{}]", hostGroupName, hostName); | ||
try { | ||
String tenantId = tenantProvider.getTenantId(); | ||
systemMetricHostExclusionService.deleteHostExclusion(tenantId, hostGroupName, hostName); | ||
return "OK"; | ||
} catch (Exception e) { | ||
logger.error("error while accepting hostName", e); | ||
return e.getMessage(); | ||
} | ||
} | ||
|
||
@RequestMapping(value = "/hostGroup/removeUnusedExclusions") | ||
public String cleanupUnusedExclusions(@RequestParam("hostGroupName") String hostGroupName) { | ||
logger.info("remove unused hostGroup exclusion and host exclusions - hostGroupName: [{}]", hostGroupName); | ||
try { | ||
String tenantId = tenantProvider.getTenantId(); | ||
systemMetricHostExclusionService.deleteUnusedHostExclusion(tenantId, hostGroupName); | ||
return "OK"; | ||
} catch (Exception e) { | ||
logger.error("error while removing unused exclusions", e); | ||
return e.getMessage(); | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...ic/src/main/java/com/navercorp/pinpoint/metric/web/cache/MetricWebCacheConfiguration.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,34 @@ | ||
package com.navercorp.pinpoint.metric.web.cache; | ||
|
||
import com.github.benmanes.caffeine.cache.Caffeine; | ||
import org.springframework.cache.CacheManager; | ||
import org.springframework.cache.annotation.EnableCaching; | ||
import org.springframework.cache.caffeine.CaffeineCacheManager; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
@Configuration | ||
@EnableCaching | ||
public class MetricWebCacheConfiguration { | ||
|
||
public static final String METRIC_HOST_GROUP_EXCLUSION_CACHE_NAME = "metricHostGroupExclusion"; | ||
public static final String METRIC_HOST_EXCLUSION_CACHE_NAME = "metricHostExclusion"; | ||
|
||
@Bean | ||
public CacheManager metricHostGroupExclusion() { | ||
CaffeineCacheManager caffeineCacheManager = new CaffeineCacheManager(METRIC_HOST_GROUP_EXCLUSION_CACHE_NAME); | ||
caffeineCacheManager.setCaffeine(Caffeine.newBuilder() | ||
.expireAfterWrite(300, TimeUnit.SECONDS)); | ||
return caffeineCacheManager; | ||
} | ||
|
||
@Bean | ||
public CacheManager metricHostExclusion() { | ||
CaffeineCacheManager caffeineCacheManager = new CaffeineCacheManager(METRIC_HOST_EXCLUSION_CACHE_NAME); | ||
caffeineCacheManager.setCaffeine(Caffeine.newBuilder() | ||
.expireAfterWrite(300, TimeUnit.SECONDS)); | ||
return caffeineCacheManager; | ||
} | ||
} |
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
18 changes: 18 additions & 0 deletions
18
...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,18 @@ | ||
package com.navercorp.pinpoint.metric.web.dao; | ||
|
||
import java.util.List; | ||
|
||
public interface SystemMetricHostExclusionDao { | ||
|
||
List<String> selectExcludedHostGroupNameList(String tenantId); | ||
|
||
void insertMetricHostGroupExclusion(String tenantId, String hostGroupName); | ||
|
||
void deleteMetricHostGroupExclusion(String tenantId, String hostGroupName); | ||
|
||
List<String> selectExcludedHostNameList(String tenantId, String hostGroupName); | ||
|
||
void insertMetricHostExclusion(String tenantId, String hostGroupName, String hostName); | ||
|
||
void deleteMetricHostExclusion(String tenantId, String hostGroupName, String hostName); | ||
} |
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
54 changes: 54 additions & 0 deletions
54
...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,54 @@ | ||
package com.navercorp.pinpoint.metric.web.dao.mysql; | ||
|
||
import com.navercorp.pinpoint.metric.web.dao.SystemMetricHostExclusionDao; | ||
import com.navercorp.pinpoint.metric.web.dao.model.HostInfoSearchKey; | ||
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(String tenantId) { | ||
return sqlMetricSessionTemplate.selectList(NAMESPACE + "selectExcludedHostGroupNames", tenantId); | ||
} | ||
|
||
@Override | ||
public void insertMetricHostGroupExclusion(String tenantId, String hostGroupName) { | ||
sqlMetricSessionTemplate.insert(NAMESPACE + "insertHostGroupExclusion", new HostInfoSearchKey(tenantId, hostGroupName)); | ||
} | ||
|
||
@Override | ||
public void deleteMetricHostGroupExclusion(String tenantId, String hostGroupName) { | ||
sqlMetricSessionTemplate.delete(NAMESPACE + "deleteHostGroupExclusion", new HostInfoSearchKey(tenantId, hostGroupName)); | ||
} | ||
|
||
@Override | ||
public List<String> selectExcludedHostNameList(String tenantId, String hostGroupName) { | ||
return sqlMetricSessionTemplate.selectList(NAMESPACE + "selectExcludedHostNames", new HostInfoSearchKey(tenantId, hostGroupName)); | ||
} | ||
|
||
@Override | ||
public void insertMetricHostExclusion(String tenantId, String hostGroupName, String hostName) { | ||
sqlMetricSessionTemplate.insert(NAMESPACE + "insertHostExclusion", new HostInfoSearchKey(tenantId, hostGroupName, hostName)); | ||
} | ||
|
||
@Override | ||
public void deleteMetricHostExclusion(String tenantId, String hostGroupName, String hostName) { | ||
sqlMetricSessionTemplate.delete(NAMESPACE + "deleteHostExclusion", new HostInfoSearchKey(tenantId, hostGroupName, hostName)); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
.../src/main/java/com/navercorp/pinpoint/metric/web/model/SystemMetricHostExclusionData.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,19 @@ | ||
package com.navercorp.pinpoint.metric.web.model; | ||
|
||
public class SystemMetricHostExclusionData { | ||
private final String hostName; | ||
private final boolean excluded; | ||
|
||
public SystemMetricHostExclusionData(String hostName, boolean excluded) { | ||
this.hostName = hostName; | ||
this.excluded = excluded; | ||
} | ||
|
||
public String getHostName() { | ||
return hostName; | ||
} | ||
|
||
public boolean isExcluded() { | ||
return excluded; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...main/java/com/navercorp/pinpoint/metric/web/model/SystemMetricHostGroupExclusionData.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,34 @@ | ||
package com.navercorp.pinpoint.metric.web.model; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
public class SystemMetricHostGroupExclusionData { | ||
private final String hostGroupName; | ||
private final boolean excluded; | ||
private final List<String> excludedHostNameList; | ||
private final List<SystemMetricHostExclusionData> hostExclusionDataList; | ||
|
||
public SystemMetricHostGroupExclusionData(String hostGroupName, boolean excluded, List<String> excludedHostNameList, List<SystemMetricHostExclusionData> hostExclusionData) { | ||
this.hostGroupName = Objects.requireNonNull(hostGroupName, "hostGroupName"); | ||
this.excluded = Objects.requireNonNull(excluded, "excluded"); | ||
this.excludedHostNameList = Objects.requireNonNull(excludedHostNameList, "excludedHostNameList"); | ||
this.hostExclusionDataList = Objects.requireNonNull(hostExclusionData, "hostExclusionData"); | ||
} | ||
|
||
public String getHostGroupName() { | ||
return hostGroupName; | ||
} | ||
|
||
public boolean isExcluded() { | ||
return excluded; | ||
} | ||
|
||
public List<String> getExcludedHostNameList() { | ||
return excludedHostNameList; | ||
} | ||
|
||
public List<SystemMetricHostExclusionData> getHostExclusionDataList() { | ||
return hostExclusionDataList; | ||
} | ||
} |
Oops, something went wrong.