mirror of
https://github.com/wahyd4/pinpoint.git
synced 2026-08-17 00:36:02 +10:00
Merge pull request #379 from emeroad/#377_support_depth-limited-search
#377 support depth-limited search
This commit is contained in:
@@ -30,7 +30,7 @@ import com.navercorp.pinpoint.web.vo.Application;
|
||||
import com.navercorp.pinpoint.web.vo.Range;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import com.navercorp.pinpoint.web.vo.SearchRange;
|
||||
import com.navercorp.pinpoint.web.vo.SearchOption;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -108,12 +108,12 @@ public class MapController {
|
||||
this.dateLimit.limit(from, to);
|
||||
logger.debug("range:{}", TimeUnit.MILLISECONDS.toMinutes(range.getRange()));
|
||||
|
||||
SearchRange searchRange = new SearchRange(callerRange, calleeRange);
|
||||
SearchOption searchOption = new SearchOption(callerRange, calleeRange);
|
||||
|
||||
ServiceType serviceType = registry.findServiceTypeByName(serviceTypeName);
|
||||
Application application = new Application(applicationName, serviceType);
|
||||
|
||||
ApplicationMap map = mapService.selectApplicationMap(application, range, searchRange);
|
||||
ApplicationMap map = mapService.selectApplicationMap(application, range, searchOption);
|
||||
|
||||
return new MapWrap(map);
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ public class LinkDataSelector {
|
||||
* @param range
|
||||
* @return
|
||||
*/
|
||||
private LinkDataDuplexMap selectCaller(Application callerApplication, Range range, SearchLevel searchLevel) {
|
||||
private LinkDataDuplexMap selectCaller(Application callerApplication, Range range, SearchDepth searchDepth) {
|
||||
// skip if the callerApplication has already been checked
|
||||
if (linkVisitChecker.visitCaller(callerApplication)) {
|
||||
return new LinkDataDuplexMap();
|
||||
@@ -112,8 +112,8 @@ public class LinkDataSelector {
|
||||
}
|
||||
|
||||
// search depth check
|
||||
final SearchLevel nextLevel = searchLevel.nextLevel();
|
||||
if (nextLevel.isLevelOverflow()) {
|
||||
final SearchDepth nextLevel = searchDepth.nextDepth();
|
||||
if (nextLevel.isDepthOverflow()) {
|
||||
continue;
|
||||
}
|
||||
logger.debug(" Find subCaller of {}", toApplication);
|
||||
@@ -140,7 +140,7 @@ public class LinkDataSelector {
|
||||
* @param range
|
||||
* @return
|
||||
*/
|
||||
private LinkDataDuplexMap selectCallee(Application calleeApplication, Range range, SearchLevel searchLevel) {
|
||||
private LinkDataDuplexMap selectCallee(Application calleeApplication, Range range, SearchDepth searchDepth) {
|
||||
// skip if the calleeApplication has already been checked
|
||||
if (linkVisitChecker.visitCallee(calleeApplication)) {
|
||||
return new LinkDataDuplexMap();
|
||||
@@ -154,8 +154,8 @@ public class LinkDataSelector {
|
||||
calleeSet.addTargetLinkData(stat);
|
||||
|
||||
// search depth check
|
||||
final SearchLevel nextLevel = searchLevel.nextLevel();
|
||||
if (nextLevel.isLevelOverflow()) {
|
||||
final SearchDepth nextLevel = searchDepth.nextDepth();
|
||||
if (nextLevel.isDepthOverflow()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -358,12 +358,12 @@ public class LinkDataSelector {
|
||||
return new LinkKey(fromApplication, toApplication);
|
||||
}
|
||||
|
||||
public LinkDataDuplexMap select(Application sourceApplication, Range range, int callerSearchLevel, int calleeSearchLevel) {
|
||||
final SearchLevel callerLevel = new SearchLevel(callerSearchLevel);
|
||||
public LinkDataDuplexMap select(Application sourceApplication, Range range, int callerSearchDepth, int calleeSearchDepth) {
|
||||
final SearchDepth callerLevel = new SearchDepth(callerSearchDepth);
|
||||
LinkDataDuplexMap caller = selectCaller(sourceApplication, range, callerLevel);
|
||||
logger.debug("Result of finding caller {}", caller);
|
||||
|
||||
final SearchLevel calleeLevel = new SearchLevel(calleeSearchLevel);
|
||||
final SearchDepth calleeLevel = new SearchDepth(calleeSearchDepth);
|
||||
LinkDataDuplexMap callee = selectCallee(sourceApplication, range, calleeLevel);
|
||||
logger.debug("Result of finding callee {}", callee);
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ import com.navercorp.pinpoint.web.applicationmap.ApplicationMap;
|
||||
import com.navercorp.pinpoint.web.applicationmap.histogram.NodeHistogram;
|
||||
import com.navercorp.pinpoint.web.vo.Application;
|
||||
import com.navercorp.pinpoint.web.vo.Range;
|
||||
import com.navercorp.pinpoint.web.vo.SearchRange;
|
||||
import com.navercorp.pinpoint.web.vo.SearchOption;
|
||||
|
||||
/**
|
||||
* @author netspider
|
||||
@@ -33,7 +33,7 @@ public interface MapService {
|
||||
* @param range
|
||||
* @return
|
||||
*/
|
||||
ApplicationMap selectApplicationMap(Application sourceApplication, Range range, SearchRange searchRange);
|
||||
ApplicationMap selectApplicationMap(Application sourceApplication, Range range, SearchOption searchOption);
|
||||
|
||||
@Deprecated
|
||||
NodeHistogram linkStatistics(Application sourceApplication, Application destinationApplication, Range range);
|
||||
|
||||
@@ -71,7 +71,7 @@ public class MapServiceImpl implements MapService {
|
||||
* Used in the main UI - draws the server map by querying the timeslot by time.
|
||||
*/
|
||||
@Override
|
||||
public ApplicationMap selectApplicationMap(Application sourceApplication, Range range, SearchRange searchRange) {
|
||||
public ApplicationMap selectApplicationMap(Application sourceApplication, Range range, SearchOption searchOption) {
|
||||
if (sourceApplication == null) {
|
||||
throw new NullPointerException("sourceApplication must not be null");
|
||||
}
|
||||
@@ -83,7 +83,7 @@ public class MapServiceImpl implements MapService {
|
||||
StopWatch watch = new StopWatch("applicationMapWatch");
|
||||
watch.start();
|
||||
LinkDataSelector linkDataSelector = new LinkDataSelector(this.mapStatisticsCalleeDao, this.mapStatisticsCallerDao, hostApplicationMapDao);
|
||||
LinkDataDuplexMap linkDataDuplexMap = linkDataSelector.select(sourceApplication, range, searchRange.getCallerRange(), searchRange.getCalleeRange());
|
||||
LinkDataDuplexMap linkDataDuplexMap = linkDataSelector.select(sourceApplication, range, searchOption.getCallerSearchDepth(), searchOption.getCalleeSearchDepth());
|
||||
|
||||
ApplicationMapBuilder builder = new ApplicationMapBuilder(range, matcherGroup);
|
||||
ApplicationMap map = builder.build(linkDataDuplexMap, agentInfoService, this.mapResponseDao);
|
||||
|
||||
+15
-15
@@ -22,46 +22,46 @@ import org.slf4j.LoggerFactory;
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class SearchLevel {
|
||||
public class SearchDepth {
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
private final int limit;
|
||||
private final int level;
|
||||
private final int depth;
|
||||
|
||||
public SearchLevel(int limit) {
|
||||
public SearchDepth(int limit) {
|
||||
this(limit, 0);
|
||||
}
|
||||
|
||||
private SearchLevel(int limit, int level) {
|
||||
private SearchDepth(int limit, int depth) {
|
||||
if (limit < 0) {
|
||||
throw new IllegalArgumentException("negative limit " + limit);
|
||||
}
|
||||
if (level < 0) {
|
||||
throw new IllegalArgumentException("negative level" + level);
|
||||
if (depth < 0) {
|
||||
throw new IllegalArgumentException("negative depth" + depth);
|
||||
}
|
||||
this.limit = limit;
|
||||
this.level = level;
|
||||
this.depth = depth;
|
||||
}
|
||||
|
||||
public SearchLevel nextLevel() {
|
||||
public SearchDepth nextDepth() {
|
||||
final int nextLevel = next();
|
||||
return new SearchLevel(limit, nextLevel);
|
||||
return new SearchDepth(limit, nextLevel);
|
||||
}
|
||||
|
||||
public int getLevel() {
|
||||
return level;
|
||||
public int getDepth() {
|
||||
return depth;
|
||||
}
|
||||
|
||||
public boolean isLevelOverflow() {
|
||||
if (limit < level) {
|
||||
logger.debug("level overflow level:{}, limit:{}", level, limit);
|
||||
public boolean isDepthOverflow() {
|
||||
if (limit < depth) {
|
||||
logger.debug("depth overflow depth:{}, limit:{}", depth, limit);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private int next() {
|
||||
return level + 1;
|
||||
return depth + 1;
|
||||
}
|
||||
|
||||
}
|
||||
+12
-12
@@ -21,22 +21,22 @@ import org.springframework.util.Assert;
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class SearchRange {
|
||||
private final int callerRange;
|
||||
private final int calleeRange;
|
||||
public class SearchOption {
|
||||
private final int callerSearchDepth;
|
||||
private final int calleeSearchDepth;
|
||||
|
||||
public SearchRange(int callerRange, int calleeRange) {
|
||||
Assert.isTrue(callerRange >= 0, "negative callerRange");
|
||||
Assert.isTrue(calleeRange >= 0, "negative calleeRange");
|
||||
this.callerRange = callerRange;
|
||||
this.calleeRange = calleeRange;
|
||||
public SearchOption(int callerSearchDepth, int calleeSearchDepth) {
|
||||
Assert.isTrue(callerSearchDepth >= 0, "negative callerSearchDepth");
|
||||
Assert.isTrue(calleeSearchDepth >= 0, "negative calleeSearchDepth");
|
||||
this.callerSearchDepth = callerSearchDepth;
|
||||
this.calleeSearchDepth = calleeSearchDepth;
|
||||
}
|
||||
|
||||
public int getCallerRange() {
|
||||
return callerRange;
|
||||
public int getCallerSearchDepth() {
|
||||
return callerSearchDepth;
|
||||
}
|
||||
|
||||
public int getCalleeRange() {
|
||||
return calleeRange;
|
||||
public int getCalleeSearchDepth() {
|
||||
return calleeSearchDepth;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2014 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.service;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class SearchDepthTest {
|
||||
|
||||
@Test
|
||||
public void testSearchDepth() throws Exception {
|
||||
SearchDepth test = new SearchDepth(1);
|
||||
|
||||
Assert.assertEquals(test.getDepth(), 0);
|
||||
|
||||
SearchDepth oneDepth = test.nextDepth();
|
||||
Assert.assertEquals(oneDepth.getDepth(), 1);
|
||||
Assert.assertFalse(oneDepth.isDepthOverflow());
|
||||
|
||||
Assert.assertEquals(oneDepth.nextDepth().getDepth(), 2);
|
||||
Assert.assertTrue(oneDepth.nextDepth().isDepthOverflow());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user