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

[#noissue] Cleanup #10158

Merged
merged 1 commit into from
Jul 24, 2023
Merged
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
Expand Up @@ -16,8 +16,6 @@

package com.navercorp.pinpoint.collector.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.navercorp.pinpoint.collector.cluster.ClusterPoint;
import com.navercorp.pinpoint.collector.cluster.ClusterPointLocator;
import com.navercorp.pinpoint.collector.cluster.GrpcAgentConnection;
Expand Down Expand Up @@ -66,12 +64,8 @@

private final ClusterPointLocator<ClusterPoint<?>> clusterPointLocator;

private final ObjectMapper mapper;


public ClusterPointController(ClusterPointLocator clusterPointLocator, ObjectMapper mapper) {
public ClusterPointController(ClusterPointLocator clusterPointLocator) {

Check warning on line 67 in collector/src/main/java/com/navercorp/pinpoint/collector/controller/ClusterPointController.java

View check run for this annotation

Codecov / codecov/patch

collector/src/main/java/com/navercorp/pinpoint/collector/controller/ClusterPointController.java#L67

Added line #L67 was not covered by tests
this.clusterPointLocator = Objects.requireNonNull(clusterPointLocator, "clusterPointLocator");
this.mapper = Objects.requireNonNull(mapper, "mapper");
}

@GetMapping(value = "/html/getClusterPoint")
Expand All @@ -85,21 +79,20 @@
}

@GetMapping(value = "/getClusterPoint")
public String getClusterPoint(
public List<GrpcAgentConnectionStats> getClusterPoint(
@RequestParam("applicationName") String applicationName,
@RequestParam(value = "agentId", defaultValue = "") String agentId,
@RequestParam(value = "startTimestamp", defaultValue = "-1") long startTimestamp) throws JsonProcessingException {
@RequestParam(value = "startTimestamp", defaultValue = "-1") long startTimestamp) {

List<GrpcAgentConnectionStats> result = getClusterPoint0(applicationName, agentId, startTimestamp);
return mapper.writeValueAsString(result);
return getClusterPoint0(applicationName, agentId, startTimestamp);

Check warning on line 87 in collector/src/main/java/com/navercorp/pinpoint/collector/controller/ClusterPointController.java

View check run for this annotation

Codecov / codecov/patch

collector/src/main/java/com/navercorp/pinpoint/collector/controller/ClusterPointController.java#L87

Added line #L87 was not covered by tests
}

@GetMapping(value = "/checkConnectionStatus")
public String checkConnectionStatus(
public List<GrpcAgentConnectionStats> checkConnectionStatus(
@RequestParam("applicationName") String applicationName,
@RequestParam("agentId") String agentId,
@RequestParam("startTimestamp") long startTimestamp,
@RequestParam(value = "checkCount", defaultValue = "3") int checkCount) throws JsonProcessingException {
@RequestParam(value = "checkCount", defaultValue = "3") int checkCount) {
Assert.isTrue(checkCount > 0, "checkCount must be ' > 0'");

List<GrpcAgentConnection> grpcAgentConnectionList = getGrpcAgentConnectionList(applicationName, agentId, startTimestamp);
Expand All @@ -115,7 +108,7 @@
result.add(new GrpcAgentConnectionStats(grpcAgentConnection, connectionStatusResult));
}

return mapper.writeValueAsString(result);
return result;

Check warning on line 111 in collector/src/main/java/com/navercorp/pinpoint/collector/controller/ClusterPointController.java

View check run for this annotation

Codecov / codecov/patch

collector/src/main/java/com/navercorp/pinpoint/collector/controller/ClusterPointController.java#L111

Added line #L111 was not covered by tests
}

private List<GrpcAgentConnectionStats> getClusterPoint0(final String applicationName, final String agentId, final long startTimestamp) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@

package com.navercorp.pinpoint.common.server.config;

import org.springframework.boot.autoconfigure.web.client.RestTemplateAutoConfiguration;
import org.springframework.boot.autoconfigure.web.client.RestTemplateBuilderConfigurer;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.web.client.RestTemplate;

import java.time.Duration;

@Configuration
@Import(RestTemplateAutoConfiguration.class)
public class RestTemplateConfiguration {

@Bean
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* 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.server.util.json;

import org.springframework.core.NestedRuntimeException;

public class JsonRuntimeException extends NestedRuntimeException {
public JsonRuntimeException(String msg) {
super(msg);
}

Check warning on line 25 in commons-server/src/main/java/com/navercorp/pinpoint/common/server/util/json/JsonRuntimeException.java

View check run for this annotation

Codecov / codecov/patch

commons-server/src/main/java/com/navercorp/pinpoint/common/server/util/json/JsonRuntimeException.java#L24-L25

Added lines #L24 - L25 were not covered by tests

public JsonRuntimeException(String msg, Throwable cause) {
super(msg, cause);
}

Check warning on line 29 in commons-server/src/main/java/com/navercorp/pinpoint/common/server/util/json/JsonRuntimeException.java

View check run for this annotation

Codecov / codecov/patch

commons-server/src/main/java/com/navercorp/pinpoint/common/server/util/json/JsonRuntimeException.java#L28-L29

Added lines #L28 - L29 were not covered by tests
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@

package com.navercorp.pinpoint.metric.common.model.mybatis;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.navercorp.pinpoint.common.server.util.json.Jackson;
import com.navercorp.pinpoint.common.server.util.json.JsonRuntimeException;
import com.navercorp.pinpoint.metric.common.model.Tag;
import com.navercorp.pinpoint.metric.common.model.json.Tags;
import org.apache.ibatis.type.JdbcType;
Expand All @@ -26,7 +28,6 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.IOException;
import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
Expand Down Expand Up @@ -76,19 +77,19 @@
public String serialize(List<Tag> tagList) {
try {
return OBJECT_MAPPER.writeValueAsString(tagList);
} catch (IOException e) {
} catch (JsonProcessingException e) {

Check warning on line 80 in metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/common/model/mybatis/TagListTypeHandler.java

View check run for this annotation

Codecov / codecov/patch

metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/common/model/mybatis/TagListTypeHandler.java#L80

Added line #L80 was not covered by tests
logger.error("Error serializing List<Tag> : {}", tagList, e);
throw new RuntimeException("Error serializing tagList", e);
throw new JsonRuntimeException("Error serializing tagList", e);

Check warning on line 82 in metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/common/model/mybatis/TagListTypeHandler.java

View check run for this annotation

Codecov / codecov/patch

metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/common/model/mybatis/TagListTypeHandler.java#L82

Added line #L82 was not covered by tests
}
}

public List<Tag> deserialize(String tagListJson) {
try {
Tags tags = OBJECT_MAPPER.readValue(tagListJson, Tags.class);
return tags.getTags();
} catch (IOException e) {
} catch (JsonProcessingException e) {

Check warning on line 90 in metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/common/model/mybatis/TagListTypeHandler.java

View check run for this annotation

Codecov / codecov/patch

metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/common/model/mybatis/TagListTypeHandler.java#L90

Added line #L90 was not covered by tests
logger.error("Error deserializing tagList json : {}", tagListJson, e);
throw new RuntimeException("Error deserializing tagListJson", e);
throw new JsonRuntimeException("Error deserializing tagListJson", e);

Check warning on line 92 in metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/common/model/mybatis/TagListTypeHandler.java

View check run for this annotation

Codecov / codecov/patch

metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/common/model/mybatis/TagListTypeHandler.java#L92

Added line #L92 was not covered by tests
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.navercorp.pinpoint.web.realtime.activethread.count.service.ActiveThreadCountSession;
import com.navercorp.pinpoint.web.websocket.ActiveThreadCountHandler;
import com.navercorp.pinpoint.web.websocket.PinpointWebSocketHandler;
import com.navercorp.pinpoint.web.websocket.message.PinpointWebSocketMessageConverter;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.lang.NonNull;
Expand All @@ -42,8 +43,8 @@ class ActiveThreadCountHandlerImpl extends ActiveThreadCountHandler implements P

private final ActiveThreadCountService atcService;

ActiveThreadCountHandlerImpl(ActiveThreadCountService atcSessionFactory) {
super(null);
ActiveThreadCountHandlerImpl(PinpointWebSocketMessageConverter converter, ActiveThreadCountService atcSessionFactory) {
super(converter, null);
this.atcService = Objects.requireNonNull(atcSessionFactory, "atcSessionFactory");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.navercorp.pinpoint.web.realtime.activethread.count.service.ActiveThreadCountWebServiceConfig;
import com.navercorp.pinpoint.web.realtime.service.RealtimeWebServiceConfig;
import com.navercorp.pinpoint.web.websocket.PinpointWebSocketHandler;
import com.navercorp.pinpoint.web.websocket.message.PinpointWebSocketMessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
Expand All @@ -31,8 +32,8 @@
public class ActiveThreadCountWebSocketConfig {

@Bean
PinpointWebSocketHandler redisActiveThreadCountHandler(ActiveThreadCountService atcSessionFactory) {
return new ActiveThreadCountHandlerImpl(atcSessionFactory);
public PinpointWebSocketHandler redisActiveThreadCountHandler(PinpointWebSocketMessageConverter converter, ActiveThreadCountService atcSessionFactory) {
return new ActiveThreadCountHandlerImpl(converter, atcSessionFactory);
}

}
17 changes: 12 additions & 5 deletions web/src/main/java/com/navercorp/pinpoint/web/WebSocketConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.navercorp.pinpoint.web;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.navercorp.pinpoint.thrift.io.DeserializerFactory;
import com.navercorp.pinpoint.thrift.io.HeaderTBaseDeserializer;
import com.navercorp.pinpoint.thrift.io.HeaderTBaseSerializer;
Expand All @@ -29,6 +30,7 @@
import com.navercorp.pinpoint.web.websocket.PinpointWebSocketConfigurer;
import com.navercorp.pinpoint.web.websocket.PinpointWebSocketHandler;
import com.navercorp.pinpoint.web.websocket.PinpointWebSocketHandlerManager;
import com.navercorp.pinpoint.web.websocket.message.PinpointWebSocketMessageConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
Expand All @@ -47,7 +49,7 @@
public class WebSocketConfig {

@Bean
WebSocketConfigurer webSocketConfigurer(
public WebSocketConfigurer webSocketConfigurer(
PinpointWebSocketHandlerManager handlerRepository,
ConfigProperties configProperties,
@Autowired(required = false) WebSocketHandlerDecoratorFactory webSocketHandlerDecoratorFactory,
Expand All @@ -62,7 +64,7 @@
}

@Bean
AgentService agentService(
public AgentService agentService(
AgentInfoService agentInfoService,
ClusterManager clusterManager,
@Qualifier("commandHeaderTBaseSerializerFactory") SerializerFactory<HeaderTBaseSerializer> commandSerializerFactory,
Expand All @@ -77,13 +79,18 @@
}

@Bean
PinpointWebSocketHandler activeThreadHandler(AgentService agentService) {
return new ActiveThreadCountHandler("/agent/activeThread", agentService);
public PinpointWebSocketHandler activeThreadHandler(PinpointWebSocketMessageConverter converter, AgentService agentService) {
return new ActiveThreadCountHandler(converter, "/agent/activeThread", agentService);

Check warning on line 83 in web/src/main/java/com/navercorp/pinpoint/web/WebSocketConfig.java

View check run for this annotation

Codecov / codecov/patch

web/src/main/java/com/navercorp/pinpoint/web/WebSocketConfig.java#L83

Added line #L83 was not covered by tests
}

@Bean
PinpointWebSocketHandlerManager handlerRegister(List<PinpointWebSocketHandler> handlers) {
public PinpointWebSocketHandlerManager handlerRegister(List<PinpointWebSocketHandler> handlers) {
return new PinpointWebSocketHandlerManager(handlers);
}

@Bean
public PinpointWebSocketMessageConverter pinpointWebSocketMessageConverter(ObjectMapper mapper) {
return new PinpointWebSocketMessageConverter(mapper);

Check warning on line 93 in web/src/main/java/com/navercorp/pinpoint/web/WebSocketConfig.java

View check run for this annotation

Codecov / codecov/patch

web/src/main/java/com/navercorp/pinpoint/web/WebSocketConfig.java#L93

Added line #L93 was not covered by tests
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Timer;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
Expand All @@ -64,7 +65,7 @@
private final AgentService agentService;
private final List<WebSocketSession> sessionRepository = new CopyOnWriteArrayList<>();
private final Map<String, PinpointWebSocketResponseAggregator> aggregatorRepository = new ConcurrentHashMap<>();
private final PinpointWebSocketMessageConverter messageConverter = new PinpointWebSocketMessageConverter();
private final PinpointWebSocketMessageConverter messageConverter;

private static final String DEFAULT_REQUEST_MAPPING = "/agent/activeThread";
private final String requestMapping;
Expand All @@ -90,19 +91,20 @@
@Autowired(required = false)
private TimerTaskDecoratorFactory timerTaskDecoratorFactory = new PinpointWebSocketTimerTaskDecoratorFactory();

public ActiveThreadCountHandler(AgentService agentService) {
this(DEFAULT_REQUEST_MAPPING, agentService);
public ActiveThreadCountHandler(PinpointWebSocketMessageConverter converter, AgentService agentService) {
this(converter, DEFAULT_REQUEST_MAPPING, agentService);

Check warning on line 95 in web/src/main/java/com/navercorp/pinpoint/web/websocket/ActiveThreadCountHandler.java

View check run for this annotation

Codecov / codecov/patch

web/src/main/java/com/navercorp/pinpoint/web/websocket/ActiveThreadCountHandler.java#L95

Added line #L95 was not covered by tests
}

public ActiveThreadCountHandler(String requestMapping, AgentService agentService) {
this(requestMapping, agentService, DEFAULT_FLUSH_DELAY);
public ActiveThreadCountHandler(PinpointWebSocketMessageConverter converter, String requestMapping, AgentService agentService) {
this(converter, requestMapping, agentService, DEFAULT_FLUSH_DELAY);

Check warning on line 99 in web/src/main/java/com/navercorp/pinpoint/web/websocket/ActiveThreadCountHandler.java

View check run for this annotation

Codecov / codecov/patch

web/src/main/java/com/navercorp/pinpoint/web/websocket/ActiveThreadCountHandler.java#L99

Added line #L99 was not covered by tests
}

public ActiveThreadCountHandler(String requestMapping, AgentService agentService, long flushDelay) {
this(requestMapping, agentService, flushDelay, DEFAULT_HEALTH_CHECk_DELAY);
public ActiveThreadCountHandler(PinpointWebSocketMessageConverter converter, String requestMapping, AgentService agentService, long flushDelay) {
this(converter, requestMapping, agentService, flushDelay, DEFAULT_HEALTH_CHECk_DELAY);

Check warning on line 103 in web/src/main/java/com/navercorp/pinpoint/web/websocket/ActiveThreadCountHandler.java

View check run for this annotation

Codecov / codecov/patch

web/src/main/java/com/navercorp/pinpoint/web/websocket/ActiveThreadCountHandler.java#L103

Added line #L103 was not covered by tests
}

public ActiveThreadCountHandler(String requestMapping, AgentService agentService, long flushDelay, long healthCheckDelay) {
public ActiveThreadCountHandler(PinpointWebSocketMessageConverter converter, String requestMapping, AgentService agentService, long flushDelay, long healthCheckDelay) {
this.messageConverter = Objects.requireNonNull(converter, "converter");

Check warning on line 107 in web/src/main/java/com/navercorp/pinpoint/web/websocket/ActiveThreadCountHandler.java

View check run for this annotation

Codecov / codecov/patch

web/src/main/java/com/navercorp/pinpoint/web/websocket/ActiveThreadCountHandler.java#L106-L107

Added lines #L106 - L107 were not covered by tests
this.requestMapping = requestMapping;
this.agentService = agentService;
this.flushDelay = flushDelay;
Expand Down Expand Up @@ -290,7 +292,7 @@
PinpointWebSocketResponseAggregator responseAggregator = aggregatorRepository.get(applicationName);
if (responseAggregator == null) {
TimerTaskDecorator timerTaskDecorator = timerTaskDecoratorFactory.createTimerTaskDecorator();
responseAggregator = new ActiveThreadCountResponseAggregator(applicationName, agentService, reactiveTimer, timerTaskDecorator);
responseAggregator = new ActiveThreadCountResponseAggregator(applicationName, agentService, reactiveTimer, timerTaskDecorator, messageConverter);

Check warning on line 295 in web/src/main/java/com/navercorp/pinpoint/web/websocket/ActiveThreadCountHandler.java

View check run for this annotation

Codecov / codecov/patch

web/src/main/java/com/navercorp/pinpoint/web/websocket/ActiveThreadCountHandler.java#L295

Added line #L295 was not covered by tests
responseAggregator.start();
aggregatorRepository.put(applicationName, responseAggregator);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,17 @@ public class ActiveThreadCountResponseAggregator implements PinpointWebSocketRes

private Map<String, AgentActiveThreadCount> activeThreadCountMap = new HashMap<>();

public ActiveThreadCountResponseAggregator(String applicationName, AgentService agentService, Timer timer, TimerTaskDecorator timerTaskDecorator) {
public ActiveThreadCountResponseAggregator(String applicationName,
AgentService agentService,
Timer timer,
TimerTaskDecorator timerTaskDecorator,
PinpointWebSocketMessageConverter messageConverter) {
this.applicationName = Objects.requireNonNull(applicationName, "applicationName");
this.agentService = Objects.requireNonNull(agentService, "agentService");

this.timer = Objects.requireNonNull(timer, "timer");
this.timerTaskDecorator = Objects.requireNonNull(timerTaskDecorator, "timerTaskDecorator");

this.messageConverter = new PinpointWebSocketMessageConverter();
this.messageConverter = Objects.requireNonNull(messageConverter, "messageConverter");
}

public int countWebSocketSession() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* 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.web.websocket.message;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.navercorp.pinpoint.common.server.util.json.JsonRuntimeException;

import java.util.Objects;


public class PingPongMessage {

private final String ping;
private final String pong;

public static PingPongMessage newMessage(ObjectMapper mapper) {
String ping = toJson(mapper, new PingMessage());
String pong = toJson(mapper, new PongMessage());
return new PingPongMessage(ping, pong);
}

public PingPongMessage(String ping, String pong) {
this.ping = Objects.requireNonNull(ping, "ping");
this.pong = Objects.requireNonNull(pong, "pong");
}

private static String toJson(ObjectMapper mapper, Object object) {
try {
return mapper.writeValueAsString(object);
} catch (JsonProcessingException e) {
throw new JsonRuntimeException(object + " message create fail.", e);

Check warning on line 47 in web/src/main/java/com/navercorp/pinpoint/web/websocket/message/PingPongMessage.java

View check run for this annotation

Codecov / codecov/patch

web/src/main/java/com/navercorp/pinpoint/web/websocket/message/PingPongMessage.java#L46-L47

Added lines #L46 - L47 were not covered by tests
}
}

public String ping() {
return ping;
}

public String pong() {
return pong;
}
}
Loading