Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
kuixiang committed May 29, 2013
2 parents ef5f7c3 + 3680d19 commit 430be8c
Show file tree
Hide file tree
Showing 11 changed files with 219 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.jd.bdp.hydra.wrapper;

import com.jd.bdp.hydra.Span;
import com.jd.bdp.hydra.agent.Tracer;

import java.util.concurrent.Callable;

/**
* Date: 13-5-29
* Time: 上午9:44
*/
public class TraceCallable<V> implements Callable<V> {

private final Callable<V> impl;
private final Span parent;
private final Tracer tracer = Tracer.getTracer();

public TraceCallable(Callable<V> impl) {
this.parent = tracer.getParentSpan();
this.impl = impl;
}

public TraceCallable(Span parent, Callable<V> impl) {
this.impl = impl;
this.parent = parent;
}

@Override
public V call() throws Exception {
if (parent != null) {
tracer.setParentSpan(parent);
}
return impl.call();
}

public Callable<V> getImpl() {
return impl;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.jd.bdp.hydra.wrapper;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.*;


public class TraceExecutorService implements ExecutorService {

private final ExecutorService impl;

public TraceExecutorService(ExecutorService impl) {
this.impl = impl;
}

@Override
public void execute(Runnable command) {
impl.execute(new TraceRunnable(command));
}

@Override
public void shutdown() {
impl.shutdown();
}

@Override
public List<Runnable> shutdownNow() {
return impl.shutdownNow();
}

@Override
public boolean isShutdown() {
return impl.isShutdown();
}

@Override
public boolean isTerminated() {
return impl.isTerminated();
}

@Override
public boolean awaitTermination(long timeout, TimeUnit unit)
throws InterruptedException {
return impl.awaitTermination(timeout, unit);
}

@Override
public <T> Future<T> submit(Callable<T> task) {
return impl.submit(new TraceCallable<T>(task));
}

@Override
public <T> Future<T> submit(Runnable task, T result) {
return impl.submit(new TraceRunnable(task), result);
}

@Override
public Future<?> submit(Runnable task) {
return impl.submit(new TraceRunnable(task));
}

private <T> Collection<? extends Callable<T>> wrapCollection(
Collection<? extends Callable<T>> tasks) {
List<Callable<T>> result = new ArrayList<Callable<T>>();
for (Callable<T> task : tasks) {
result.add(new TraceCallable<T>(task));
}
return result;
}

@Override
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks)
throws InterruptedException {
return impl.invokeAll(wrapCollection(tasks));
}

@Override
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks,
long timeout, TimeUnit unit) throws InterruptedException {
return impl.invokeAll(wrapCollection(tasks), timeout, unit);
}

@Override
public <T> T invokeAny(Collection<? extends Callable<T>> tasks)
throws InterruptedException, ExecutionException {
return impl.invokeAny(wrapCollection(tasks));
}

@Override
public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout,
TimeUnit unit) throws InterruptedException, ExecutionException,
TimeoutException {
return impl.invokeAny(wrapCollection(tasks), timeout, unit);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.jd.bdp.hydra.wrapper;

import com.jd.bdp.hydra.Span;
import com.jd.bdp.hydra.agent.Tracer;

/**
* Date: 13-5-29
* Time: 上午9:50
*/
public class TraceRunnable implements Runnable{
private final Span parent;
private final Runnable runnable;
private Tracer tracer = Tracer.getTracer();


public TraceRunnable(Runnable r){
this.parent = tracer.getParentSpan();
this.runnable = r;
}

public TraceRunnable(Runnable r, Span p){
this.runnable = r;
this.parent = p;
}
@Override
public void run() {
if(parent != null){
tracer.setParentSpan(parent);
}
runnable.run();
}
}
4 changes: 2 additions & 2 deletions modules/hydra-web/src/main/webapp/WEB-INF/views/query.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
<div class="alert alert-error" id="alertDiv" ng-show="query.invalid">
{{query.validateMsg}}
</div>
<button class="btn btn-success btn-large" type="submit" style="width: 200px;">查询</button>
<button ng-class="query.queryBtn.myClass" type="submit" style="width: 200px;">{{query.queryBtn.name}}</button>
</td>
</tr>
</tbody>
Expand Down Expand Up @@ -149,7 +149,7 @@
<div class="traceDiv">
<div ng-show="!trace.available" class="alert alert-block">当前跟踪数据未收集全,无法展示.</div>
<div id="treeDiv" class="viewDiv" style="width:25%;" ng-show="trace.available"></div>
<div id="sequenceDiv" class="viewDiv" style="width:74%;" ng-show="trace.available"></div>
<div id="sequenceDiv" class="viewDiv" ng-show="trace.available" ng-style="env.sequenceDivStyle"></div>
</div>
</div>
</body>
Expand Down
1 change: 1 addition & 0 deletions modules/hydra-web/src/main/webapp/statics/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ path.link {
width: 98%;
margin: 20 20 20 20;
border: solid 1px #ddd;
overflow-x: hidden;
}

.myNavbar {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ function QueryCtrl($scope, $filter, $location,//内置
} else {
return '55%';
}
}()}};
}()},
sequenceDivStyle:{
width:'74%'
}
};
$scope.serviceMap = {};
$scope.tableType = 'duration';
var setting = queryService.getTableSetting($scope);
Expand Down Expand Up @@ -56,6 +60,18 @@ function QueryCtrl($scope, $filter, $location,//内置
}
}
},
queryBtn:{
name:'查询',
myClass: 'btn btn-success btn-large',
disable: function(){
query.queryBtn.myClass = 'btn btn-success btn-large disabled';
query.queryBtn.name = '查询中...';
},
enable: function(){
query.queryBtn.myClass = 'btn btn-success btn-large';
query.queryBtn.name = '查询';
}
},
appList: AppList.getAll(),
serviceList: [],
sum: 500,
Expand Down Expand Up @@ -92,17 +108,23 @@ function QueryCtrl($scope, $filter, $location,//内置

//查询
if (isValid) {
$scope.query.queryBtn.disable();
queryService.loadTableData($('#traceExTable').dataTable(), []);
queryService.loadTableData($('#traceTable').dataTable(), []);
if ($scope.query.exBtn.type) {//如果查询所有异常trace
$scope.tableType = 'ex';
$scope.traceListEx = TraceListEx.getTraceList({serviceId: serviceId, startTime: startTime, sum: $scope.query.sum}, function (traceList) {
queryService.loadTableData($('#traceExTable').dataTable(), traceList);
$scope.query.queryBtn.enable();
});
} else {//如果是查duration
$scope.tableType = 'duration';
$scope.traceList = TraceList.getTraceList({serviceId: serviceId, startTime: startTime, durationMin: durationMin, durationMax: durationMax, sum: $scope.query.sum}, function (traceList) {
queryService.loadTableData($('#traceTable').dataTable(), traceList);
$scope.query.queryBtn.enable();
});
}

}
},
appChange: function () {
Expand Down Expand Up @@ -132,7 +154,7 @@ function QueryCtrl($scope, $filter, $location,//内置
var spanMap = sequenceService.getSpanMap(t);

sequenceService.createView(t);//生成时序图的svg
sequenceService.createSpanAndDetail(t, spanMap);//生成时序图的具体细节
sequenceService.createSpanAndDetail(t, spanMap, $scope);//生成时序图的具体细节

treeService.createTree(t);//生成树的svg
treeService.createTreeDetail(t, $scope);//生成树的具体结构
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ angular.module('hydra.services.sequence', [])
.text("ms");
trace.view = view;
},
createSpanAndDetail:function (trace, spanMap) {
createSpanAndDetail:function (trace, spanMap, myScope) {

var rootSpan = trace.rootSpan;
var view = trace.view;
Expand Down Expand Up @@ -213,6 +213,7 @@ angular.module('hydra.services.sequence', [])
return view.color[time.hasEx?'ex':time.type];
});


//生成每一个span
function bar(rootSpan) {
var spans = [rootSpan.used, rootSpan.wasted];
Expand Down Expand Up @@ -270,7 +271,10 @@ angular.module('hydra.services.sequence', [])
.attr("class", "y axis")
.attr('id', 'yaxis')
.append("line")
.attr("y1", (maxIndex+1) * view.y * 1.2);
.attr("y1", function(){
myScope.env.sequenceDivStyle.height = ((maxIndex+1) * view.y * 1.2 + 50) > 500?((maxIndex+1) * view.y * 1.2 + 50):500;
return myScope.env.sequenceDivStyle.height;
});

createSpanTip(spanMap);//tip

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@
break;
case 'today':
var date = new Date();
date = UTCDate(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), 0);
date = UTCDate(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0, 0);

this.viewMode = this.startViewMode;
this.showMode(0);
Expand Down

Large diffs are not rendered by default.

0 comments on commit 430be8c

Please sign in to comment.