Skip to content

Commit

Permalink
[#9597] add new inspector function
Browse files Browse the repository at this point in the history
  • Loading branch information
minwoo-jung committed Jun 23, 2023
1 parent f00f184 commit 67c83ac
Show file tree
Hide file tree
Showing 75 changed files with 4,082 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
import com.navercorp.pinpoint.common.server.bo.stat.AgentStatBo;
import com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint;
import com.navercorp.pinpoint.common.server.bo.stat.AgentStatType;
import com.navercorp.pinpoint.common.server.bo.stat.JvmGcBo;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Put;

import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.function.Function;
Expand Down Expand Up @@ -61,6 +63,17 @@ public void insert(String agentId, List<T> dataPoints) {
return;
}

if (agentStatType.equals(AgentStatType.JVM_GC)) {
for (T dataPoint : dataPoints) {
if (dataPoint instanceof JvmGcBo)
{
JvmGcBo jvmGcBo = (JvmGcBo) dataPoint;
System.out.println("#### time : " + new Date(jvmGcBo.getTimestamp()) + " Gc count : " + jvmGcBo.getGcOldCount());
}

}

}
dataPoints = preprocessor.apply(dataPoints);
List<Put> puts = this.operations.createPuts(agentId, agentStatType, dataPoints, this.serializer);
if (!puts.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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.common.util;

/**
* @author minwoo.jung
*/
public class ObjectUtils {

public static <T> T defaultIfNull(T object, T defaultValue) {
return object != null ? object : defaultValue;
}
}
44 changes: 44 additions & 0 deletions inspector-module/inspector-collector/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>pinpoint-inspector-module</artifactId>
<groupId>com.navercorp.pinpoint</groupId>
<version>2.6.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>pinpoint-inspector-collector</artifactId>
<name>pinpoint-inspector-collector</name>

<properties>
<jdk.version>11</jdk.version>
<jdk.home>${env.JAVA_11_HOME}</jdk.home>
</properties>


<dependencies>
<dependency>
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-collector</artifactId>
<scope>provided</scope>
</dependency>
<!-- todo : (minwoo) It is necessary to think about removing the dependency on the metric side. -->
<dependency>
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-metric</artifactId>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-pinot-kafka</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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.inspector.collector;

import com.navercorp.pinpoint.inspector.collector.config.InspectorKafkaConfiguration;
import com.navercorp.pinpoint.inspector.collector.config.InspectorPropertySources;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration;
import org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.ImportResource;
import org.springframework.context.annotation.PropertySource;

/**
* @author minwoo.jung
*/
@ComponentScan({"com.navercorp.pinpoint.inspector.collector"})
@EnableAutoConfiguration(exclude = {KafkaAutoConfiguration.class})
@Import({
InspectorPropertySources.class,
InspectorKafkaConfiguration.class})
public class InspectorCollectorApp {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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.inspector.collector.config;

import com.navercorp.pinpoint.inspector.collector.model.kafka.AgentStat;
import com.navercorp.pinpoint.pinot.kafka.KafkaConfiguration;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.kafka.core.ProducerFactory;

/**
* @author minwoo.jung
*/
@Configuration
@Import({KafkaConfiguration.class})
public class InspectorKafkaConfiguration {

@Bean
public KafkaTemplate<String, AgentStat> kafkaAgentStatTemplate(@Qualifier("kafkaProducerFactory") ProducerFactory producerFactory) {
return new KafkaTemplate<>(producerFactory);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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.inspector.collector.config;

import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.PropertySources;

/**
* @author minwoo.jung
*/

@PropertySources({
@PropertySource(name = "InspectorPropertySources-KAFKA", value = { InspectorPropertySources.KAFKA_TOPIC}),
})
public class InspectorPropertySources {
public static final String KAFKA_TOPIC = "classpath:inspector/collector/kafka-topic.properties";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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.inspector.collector.dao;

import com.navercorp.pinpoint.common.server.bo.stat.AgentStatBo;
import com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
* @author minwoo.jung
*/
@Repository
public interface AgentStatDao<T extends AgentStatDataPoint> {
void insert(String agentId, List<T> agentStatDataPoints);

void dispatch(AgentStatBo agentStatBo);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* 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.inspector.collector.dao.pinot;

import com.navercorp.pinpoint.common.server.bo.stat.AgentStatBo;
import com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint;
import com.navercorp.pinpoint.inspector.collector.dao.AgentStatDao;
import com.navercorp.pinpoint.inspector.collector.model.kafka.AgentStat;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.kafka.core.KafkaTemplate;

import java.util.List;
import java.util.Objects;
import java.util.function.Function;

/**
* @author minwoo.jung
*/
public class DefaultAgentStatDao <T extends AgentStatDataPoint> implements AgentStatDao<T> {

private final Logger logger = LogManager.getLogger(DefaultAgentStatDao.class.getName());

private final Function<AgentStatBo, List<T>> dataPointFunction;
private final Function<List<T>, List<AgentStat>> convertToKafkaModelFunction;
private final KafkaTemplate kafkaAgentStatTemplate;
private final String topic;

public DefaultAgentStatDao(Function<AgentStatBo, List<T>> dataPointFunction, KafkaTemplate kafkaAgentStatTemplate, Function<List<T>, List<AgentStat>> convertToKafkaModelFunction, String topic) {
this.dataPointFunction = Objects.requireNonNull(dataPointFunction, "dataPointFunction");
this.kafkaAgentStatTemplate = Objects.requireNonNull(kafkaAgentStatTemplate, "kafkaAgentStatTemplate");
this.convertToKafkaModelFunction = convertToKafkaModelFunction;
this.topic = topic;
}

@Override
public void insert(String agentId, List<T> agentStatData) {
List<AgentStat> agentStatList = convertDataToKafkaModel(agentStatData);
for (AgentStat agentStat : agentStatList) {
String kafkaKey = generateKafkaKey(agentStat);
kafkaAgentStatTemplate.send(topic, kafkaKey, agentStat);
}
}

private List<AgentStat> convertDataToKafkaModel(List<T> AgentStatDataPointList) {
List<AgentStat> agentStatList = convertToKafkaModelFunction.apply(AgentStatDataPointList);
return agentStatList;
}

@Override
public void dispatch(AgentStatBo agentStatBo) {
Objects.requireNonNull(agentStatBo, "agentStatBo");
List<T> dataPointList = this.dataPointFunction.apply(agentStatBo);
insert(agentStatBo.getAgentId(), dataPointList);
}

private String generateKafkaKey(AgentStat agentStat) {
StringBuilder sb = new StringBuilder();
sb.append(agentStat.getApplicationName());
sb.append("_");
sb.append(agentStat.getAgentId());
sb.append("_");
sb.append(agentStat.getMetricName());
return sb.toString();
}
}
Loading

0 comments on commit 67c83ac

Please sign in to comment.