Skip to content

Commit 561ff2c

Browse files
committed
[#noissue] Refactor active agent validation to use agent ID and service type
1 parent 44659e5 commit 561ff2c

File tree

6 files changed

+27
-28
lines changed

6 files changed

+27
-28
lines changed

batch/src/main/java/com/navercorp/pinpoint/batch/alarm/AlarmProcessor.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,15 @@ private Supplier<List<String>> getAgentIdsSupplier(Application application, long
101101

102102
private List<String> fetchActiveAgents(Application application, Range activeRange) {
103103
List<String> agentList = batchAgentService.getIds(application.getName());
104-
return agentList
105-
.stream()
106-
.filter(id -> {
107-
Application agent = new Application(id, application.getServiceType());
108-
return batchAgentService.isActive(agent, activeRange);
109-
})
110-
.toList();
104+
105+
int code = application.getServiceType().getCode();
106+
List<String> list = new ArrayList<>();
107+
for (String agentId : agentList) {
108+
if (batchAgentService.isActive(agentId, code, activeRange)) {
109+
list.add(agentId);
110+
}
111+
}
112+
return list;
111113
}
112114

113115
private static class AlarmCheckerFactory {

batch/src/main/java/com/navercorp/pinpoint/batch/service/BatchAgentService.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package com.navercorp.pinpoint.batch.service;
1818

1919
import com.navercorp.pinpoint.common.timeseries.time.Range;
20-
import com.navercorp.pinpoint.web.vo.Application;
2120

2221
import java.util.List;
2322

@@ -30,6 +29,6 @@ public interface BatchAgentService {
3029

3130
boolean isActive(String agentId, Range range);
3231

33-
boolean isActive(Application agent, Range range);
32+
boolean isActive(String agentId, int agentServiceType, Range range);
3433

3534
}

batch/src/main/java/com/navercorp/pinpoint/batch/service/BatchAgentServiceImpl.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import com.navercorp.pinpoint.common.timeseries.time.Range;
2020
import com.navercorp.pinpoint.web.service.component.ActiveAgentValidator;
21-
import com.navercorp.pinpoint.web.vo.Application;
2221
import org.springframework.stereotype.Service;
2322

2423
import java.util.List;
@@ -51,7 +50,7 @@ public boolean isActive(String agentId, Range range) {
5150
}
5251

5352
@Override
54-
public boolean isActive(Application agent, Range range) {
55-
return this.activeAgentValidator.isActiveAgent(agent, range);
53+
public boolean isActive(String agentId, int agentServiceType, Range range) {
54+
return this.activeAgentValidator.isActiveAgent(agentId, agentServiceType, range);
5655
}
5756
}
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
package com.navercorp.pinpoint.web.service.component;
22

33
import com.navercorp.pinpoint.common.timeseries.time.Range;
4-
import com.navercorp.pinpoint.web.vo.Application;
54

65
public interface ActiveAgentValidator {
76
boolean isActiveAgent(String agentId, Range range);
87

9-
boolean isActiveAgent(Application agent, Range range);
8+
boolean isActiveAgent(String agentId, int agentServiceType, Range range);
109

11-
boolean isActiveAgent(Application agent, String version, Range range);
10+
boolean isActiveAgent(String agentId, int agentServiceType, String version, Range range);
1211

1312
boolean isActiveAgentByEvent(String agentId, Range range);
1413
}

web/src/main/java/com/navercorp/pinpoint/web/service/component/DefaultActiveAgentValidator.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import com.navercorp.pinpoint.common.util.CollectionUtils;
55
import com.navercorp.pinpoint.web.service.AgentEventService;
66
import com.navercorp.pinpoint.web.vo.AgentEvent;
7-
import com.navercorp.pinpoint.web.vo.Application;
87
import org.apache.logging.log4j.LogManager;
98
import org.apache.logging.log4j.Logger;
109
import org.springframework.stereotype.Component;
@@ -36,15 +35,15 @@ public boolean isActiveAgent(String agentId, Range range) {
3635
}
3736

3837
@Override
39-
public boolean isActiveAgent(Application agent, Range range) {
40-
return isActiveAgent(agent, null, range);
38+
public boolean isActiveAgent(String agentId, int agentServiceType, Range range) {
39+
return isActiveAgent(agentId, agentServiceType, null, range);
4140
}
4241

4342
@Override
44-
public boolean isActiveAgent(Application agent, String version, Range range) {
45-
Objects.requireNonNull(agent, "agent");
46-
String agentId = agent.getName();
47-
if (!agentCompatibility.isLegacyAgent(agent.getServiceTypeCode(), version)) {
43+
public boolean isActiveAgent(String agentId, int agentServiceType, String version, Range range) {
44+
Objects.requireNonNull(agentId, "agentId");
45+
46+
if (!agentCompatibility.isLegacyAgent(agentServiceType, version)) {
4847
logger.trace("isActiveAgentByPing");
4948

5049
if (isActiveAgentByEvent(agentId, range)) {

web/src/test/java/com/navercorp/pinpoint/web/service/component/DefaultActiveAgentValidatorTest.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
import com.navercorp.pinpoint.common.server.util.AgentEventType;
44
import com.navercorp.pinpoint.common.timeseries.time.Range;
5+
import com.navercorp.pinpoint.common.trace.ServiceType;
56
import com.navercorp.pinpoint.common.trace.ServiceTypeFactory;
67
import com.navercorp.pinpoint.web.service.AgentEventService;
78
import com.navercorp.pinpoint.web.vo.AgentEvent;
8-
import com.navercorp.pinpoint.web.vo.Application;
99
import org.junit.jupiter.api.Assertions;
1010
import org.junit.jupiter.api.Test;
1111
import org.junit.jupiter.api.extension.ExtendWith;
@@ -24,15 +24,16 @@ class DefaultActiveAgentValidatorTest {
2424
@Mock
2525
AgentEventService agentEventService;
2626

27-
Application node = new Application("testNodeApp", ServiceTypeFactory.of(1400, "node"));
27+
String agentId = "testNodeApp";
28+
ServiceType node = ServiceTypeFactory.of(1400, "node");
2829
// Application java = new Application("testJavaApp", ServiceTypeFactory.of(1010, "java"));
2930

3031
@Test
3132
void isActiveAgent_legacy_node() {
3233
LegacyAgentCompatibility agentCompatibility = new DefaultLegacyAgentCompatibility();
3334
ActiveAgentValidator validator = new DefaultActiveAgentValidator(agentEventService, agentCompatibility);
3435

35-
Assertions.assertFalse(validator.isActiveAgent(node, "0.7.0", Range.between(0, 1)));
36+
Assertions.assertFalse(validator.isActiveAgent(agentId, node.getCode(), "0.7.0", Range.between(0, 1)));
3637
}
3738

3839
@Test
@@ -43,15 +44,15 @@ void isActiveAgent_legacy_node_with_gc() {
4344
AgentEvent gc = new AgentEvent("test", 1, 1, AgentEventType.AGENT_PING);
4445
when(agentEventService.getAgentEvents(any(), any(), any())).thenReturn(List.of(gc));
4546

46-
Assertions.assertTrue(validator.isActiveAgent(node, "5.0.0", Range.between(0, 1)));
47+
Assertions.assertTrue(validator.isActiveAgent(agentId, node.getCode(), "5.0.0", Range.between(0, 1)));
4748
}
4849

4950
@Test
5051
void isActiveAgent_new_node_without_ping() {
5152
LegacyAgentCompatibility agentCompatibility = new DefaultLegacyAgentCompatibility();
5253
ActiveAgentValidator validator = new DefaultActiveAgentValidator(agentEventService, agentCompatibility);
5354

54-
Assertions.assertFalse(validator.isActiveAgent(node, "0.8.0", Range.between(0, 1)));
55+
Assertions.assertFalse(validator.isActiveAgent(agentId, node.getCode(), "0.8.0", Range.between(0, 1)));
5556

5657
verify(agentEventService).getAgentEvents(any(), any(), any());
5758
}
@@ -64,6 +65,6 @@ void isActiveAgent_new_node_with_event() {
6465
LegacyAgentCompatibility agentCompatibility = new DefaultLegacyAgentCompatibility();
6566
ActiveAgentValidator validator = new DefaultActiveAgentValidator(agentEventService, agentCompatibility);
6667

67-
Assertions.assertTrue(validator.isActiveAgent(node, "0.8.0", Range.between(0, 1)));
68+
Assertions.assertTrue(validator.isActiveAgent(agentId, node.getCode(), "0.8.0", Range.between(0, 1)));
6869
}
6970
}

0 commit comments

Comments
 (0)