Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#9903] add system metric host management function #9904

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.navercorp.pinpoint.metric.web;


import com.navercorp.pinpoint.metric.web.config.MetricWebMysqlDaoConfiguration;
import com.navercorp.pinpoint.metric.web.config.MetricWebPinotDaoConfiguration;
import com.navercorp.pinpoint.pinot.config.PinotConfiguration;
import org.springframework.context.annotation.ComponentScan;
Expand All @@ -14,7 +15,8 @@
@Import({
WebMetricPropertySources.class,
MetricWebPinotDaoConfiguration.class,
PinotConfiguration.class
PinotConfiguration.class,
MetricWebMysqlDaoConfiguration.class
})
@Profile("metric")
public class MetricWebApp {
Expand Down
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.navercorp.pinpoint.metric.collector.config.MyBatisRegistryHandler;
import com.navercorp.pinpoint.metric.common.config.CommonRegistryHandler;
import com.navercorp.pinpoint.metric.common.model.Tag;
import com.navercorp.pinpoint.metric.web.dao.model.HostExclusionSearchKey;
import com.navercorp.pinpoint.metric.web.dao.model.HostInfoSearchKey;
import com.navercorp.pinpoint.metric.web.dao.model.MetricInfoSearchKey;
import com.navercorp.pinpoint.metric.web.dao.model.MetricTagsSearchKey;
Expand Down Expand Up @@ -45,6 +46,8 @@ public void registerTypeAlias(TypeAliasRegistry typeAliasRegistry) {
typeAliasRegistry.registerAlias("metricInfoSearchKey", MetricInfoSearchKey.class);
typeAliasRegistry.registerAlias("metricTagsSearchKey", MetricTagsSearchKey.class);
typeAliasRegistry.registerAlias("hostInfoSearchKey", HostInfoSearchKey.class);

typeAliasRegistry.registerAlias("hostExclusionSearchKey", HostExclusionSearchKey.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package com.navercorp.pinpoint.metric.web.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")
public List<String> getHostGroupNameList() {
String tenantId = tenantProvider.getTenantId();
return systemMetricHostExclusionService.getHostGroupNameList(tenantId);
}

@GetMapping(value = "/hostGroup", params = {"hostGroupName"})
public SystemMetricHostGroupInfo getHostGroupExclusionInfo(@RequestParam("hostGroupName") String hostGroupName) {
String tenantId = tenantProvider.getTenantId();
return systemMetricHostExclusionService.getHostGroupInfo(tenantId, hostGroupName);
}

@GetMapping(value = "/hostGroup/host")
public List<SystemMetricHostInfo> getHostExclusionInfoList(@RequestParam("hostGroupName") String hostGroupName,
@RequestParam(value = "orderBy", defaultValue = "hostName") String orderBy) {
String tenantId = tenantProvider.getTenantId();
return systemMetricHostExclusionService.getHostInfoList(tenantId, hostGroupName, orderBy);
}

@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 = "/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());
}
}
}
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();
}
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;
}
}
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");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.navercorp.pinpoint.metric.web.service;

import com.navercorp.pinpoint.metric.web.view.SystemMetricHostGroupInfo;
import com.navercorp.pinpoint.metric.web.view.SystemMetricHostInfo;

import java.util.List;

public interface SystemMetricHostExclusionService {

List<String> getHostGroupNameList(String tenantId);

SystemMetricHostGroupInfo getHostGroupInfo(String tenantId, String hostGroupName);

List<SystemMetricHostInfo> getHostInfoList(String tenantId, String hostGroupName, String orderBy);

void insertHostGroupExclusion(String hostGroupName);

void deleteHostGroupExclusion(String hostGroupName);

void insertHostExclusion(String hostGroupName, String hostName);

void deleteHostExclusion(String hostGroupName, String hostName);

void deleteUnusedGroupExclusions(String tenantId);
}
Loading