-
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
cec5c0a
commit 87f04a5
Showing
19 changed files
with
731 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)); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...c/main/java/com/navercorp/pinpoint/metric/web/service/SystemMetricHostExclusionCache.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,43 @@ | ||
package com.navercorp.pinpoint.metric.web.service; | ||
|
||
|
||
import com.navercorp.pinpoint.metric.web.cache.MetricWebCacheConfiguration; | ||
import com.navercorp.pinpoint.metric.web.dao.SystemMetricHostExclusionDao; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.springframework.cache.annotation.Cacheable; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
@Component | ||
public class SystemMetricHostExclusionCache { | ||
private final Logger logger = LogManager.getLogger(this.getClass()); | ||
private final SystemMetricHostExclusionDao systemMetricHostExclusionDao; | ||
|
||
public SystemMetricHostExclusionCache(SystemMetricHostExclusionDao systemMetricHostExclusionDao) { | ||
this.systemMetricHostExclusionDao = Objects.requireNonNull(systemMetricHostExclusionDao, "systemMetricHostExclusionDao"); | ||
} | ||
|
||
@Cacheable(cacheNames = "metricHostGroupExclusion", key = "#tenantId", cacheManager = MetricWebCacheConfiguration.METRIC_HOST_GROUP_EXCLUSION_CACHE_NAME) | ||
public List<String> getExcludedHostGroupNameList(String tenantId) { | ||
try { | ||
return systemMetricHostExclusionDao.selectExcludedHostGroupNameList(tenantId); | ||
} catch (Exception e) { | ||
logger.warn("error getting excludedHostGroupNameList, return empty list.", e); | ||
return Collections.emptyList(); | ||
} | ||
} | ||
|
||
@Cacheable(cacheNames = "metricHostExclusion", key = "{#tenantId, #hostGroupName}", cacheManager = MetricWebCacheConfiguration.METRIC_HOST_EXCLUSION_CACHE_NAME) | ||
public List<String> getExcludedHostNameList(String tenantId, String hostGroupName) { | ||
try { | ||
return systemMetricHostExclusionDao.selectExcludedHostNameList(tenantId, hostGroupName); | ||
} catch (Exception e) { | ||
logger.warn("error getting excludedHostNameList, return empty list.", e); | ||
return Collections.emptyList(); | ||
} | ||
} | ||
} |
Oops, something went wrong.