Skip to content

Commit 23bfd54

Browse files
committed
基础功能全部跑通!
1 parent 31c16d0 commit 23bfd54

File tree

13 files changed

+96
-53
lines changed

13 files changed

+96
-53
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ target/
2424
*.patch
2525
*.tmp
2626
.logs
27-
27+
logs/
2828

modules/hydra-collector-service/src/main/java/com/jd/bdp/hydra/collector/service/Bootstrap.java

+2-9
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,15 @@
99
* Time: 上午11:01
1010
*/
1111
public class Bootstrap {
12-
private CollectorService collectorService;
13-
private final String topic = "hydra_test";
1412

1513
public static void main(String[] strings){
1614
try {
1715
ApplicationContext context = new ClassPathXmlApplicationContext("hydra-collector-service.xml");
18-
Bootstrap bootstrap = new Bootstrap();
19-
bootstrap.collectorService = (CollectorService)context.getBean("collectorService");
20-
bootstrap.start();
16+
CollectorSerService collectorSerService = (CollectorSerService)context.getBean("collectorService");
17+
collectorSerService.subscribe();
2118
} catch (Exception e) {
2219
e.printStackTrace();
2320
}
2421
}
2522

26-
public void start()throws Exception{
27-
collectorService.subscribe(topic);
28-
}
29-
3023
}

modules/hydra-collector-service/src/main/java/com/jd/bdp/hydra/collector/service/CollectorService.java renamed to modules/hydra-collector-service/src/main/java/com/jd/bdp/hydra/collector/service/CollectorSerService.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@
2121
* Date: 13-4-17
2222
* Time: 下午5:03
2323
*/
24-
public class CollectorService {
25-
private static final Logger log = LoggerFactory.getLogger(CollectorService.class);
24+
public class CollectorSerService {
25+
private static final Logger log = LoggerFactory.getLogger(CollectorSerService.class);
26+
private String topic;
2627
private MessageConsumer consumer;
2728
private HbaseService hbaseService;
2829
private ExecutorService executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
@@ -36,6 +37,10 @@ public void setHbaseService(HbaseService hbaseService) {
3637
this.hbaseService = hbaseService;
3738
}
3839

40+
public void setTopic(String topic) {
41+
this.topic = topic;
42+
}
43+
3944
class HbaseConsumer implements MessageListener{
4045
@Override
4146
public void recieveMessages(Message message) {
@@ -49,15 +54,14 @@ public Executor getExecutor() {
4954
}
5055

5156

52-
public void subscribe(String topic)throws Exception{
57+
public void subscribe()throws Exception{
5358
consumer.subscribe(topic,1024*1024,new HbaseConsumer()).completeSubscribe();
5459
}
5560

5661
public void persistent(Message message){
5762
List<Span> spanList = new ArrayList<Span>();
5863
try{
5964
spanList = (List)PB.parsePBBytes(message.getData());
60-
log.info("成功接受message");
6165
}catch (Exception e){
6266
log.error(e.getMessage());
6367
}

modules/hydra-collector-service/src/main/resources/config.properties

-3
This file was deleted.

modules/hydra-collector-service/src/main/resources/hydra-collector-service.xml

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@
2222
default-autowire="byName">
2323

2424
<bean id="hbaseService" class="com.jd.bdp.hydra.hbase.service.impl.HbaseServiceImpl"/>
25-
<bean id="collectorService" class="com.jd.bdp.hydra.collector.service.CollectorService" />
25+
<bean id="collectorSerService" class="com.jd.bdp.hydra.collector.service.CollectorSerService" >
26+
<property name="topic" value="hydra_test"></property>
27+
</bean>
28+
2629

2730
<bean id="sessionFactory" class="com.taobao.metamorphosis.client.MetaMessageSessionFactory">
2831
<constructor-arg>
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
metaq.zk=192.168.227.83:2181,192.168.227.86:2181,192.168.228.85:2181
1+
metaq.zk=192.168.227.83:2181
22
metaq.topic=hydra_test
33
metaq.zk.root=/meta
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright jd
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.jd.bdp.hydra.benchmark.startCollectorService;
18+
19+
import com.jd.bdp.hydra.agent.CollectorService;
20+
import com.jd.bdp.hydra.collector.service.CollectorSerService;
21+
import org.springframework.context.support.ClassPathXmlApplicationContext;
22+
23+
/**
24+
* User: xiangkui
25+
* Date: 13-4-23
26+
* Time: 下午6:19
27+
*/
28+
public class StartCollectorService {
29+
30+
public static void main(String[] args) throws Exception {
31+
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{
32+
"classpath*:hydra-collector-service.xml"
33+
});
34+
CollectorSerService collectorSerService = (CollectorSerService)context.getBean("collectorSerService");
35+
collectorSerService.subscribe();
36+
Thread.sleep(999999999);
37+
}
38+
}

modules/hydra-example/hydra-example-benchmark/src/main/java/com/jd/bdp/hydra/benchmark/startTrigger/StartTrigger.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static void main(String[] args) {
1717
context.start();
1818
Trigger trigger=(Trigger)context.getBean("trigger");
1919
// 每隔3s触发一次调用
20-
trigger.startWorkWithSleep(5,500);
20+
trigger.startWorkWithSleep(20,500);
2121
Thread.sleep(999999999);
2222
} catch (Exception e) {
2323
e.printStackTrace();

modules/hydra-example/pom.xml

+5
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@
3434
<groupId>com.jd.bdp</groupId>
3535
<artifactId>hydra-collector</artifactId>
3636
</dependency>
37+
<!-- 测试hydra-collector-service -->
38+
<dependency>
39+
<groupId>com.jd.bdp</groupId>
40+
<artifactId>hydra-collector-service</artifactId>
41+
</dependency>
3742

3843
<dependency>
3944
<groupId>org.springframework</groupId>

modules/hydra-hbase/src/main/java/com/jd/bdp/hydra/hbase/service/impl/HbaseServiceImpl.java

+32-23
Original file line numberDiff line numberDiff line change
@@ -144,34 +144,43 @@ public void annotationIndex(Span span) {
144144

145145

146146
public void durationIndex(Span span) {
147-
List<Annotation> alist = span.getAnnotations();
148-
Annotation cs = getCsAnnotation(alist);
149-
Annotation cr = getCrAnnotation(alist);
150-
if (cs != null) {
151-
long duration = cs.getTimestamp() - cr.getTimestamp();
152-
String rowkey = cs.getHost().getServiceName() + ":" + cs.getTimestamp();
153-
Put put = new Put(rowkey.getBytes());
154-
//rowkey:serviceId:csTime
155-
//每列的timestamp为duration
156-
//每列列名为traceId,值为1(用来区分1ms内的跟踪)
157-
put.add(duration_index_family_column.getBytes(), long2ByteArray(span.getTraceId()), duration, "1".getBytes());
158-
HTableInterface htable = null;
159-
try {
160-
htable = POOL.getTable(duration_index);
161-
htable.put(put);
162-
} catch (IOException e) {
163-
e.printStackTrace();
164-
}finally {
165-
if(htable != null){
166-
try {
167-
htable.close();
168-
} catch (IOException e) {
169-
e.printStackTrace();
147+
if (isRootSpan(span)) {
148+
List<Annotation> alist = span.getAnnotations();
149+
Annotation cs = getCsAnnotation(alist);
150+
Annotation cr = getCrAnnotation(alist);
151+
if (cs != null) {
152+
long duration = cr.getTimestamp() - cs.getTimestamp();
153+
String rowkey = cs.getHost().getServiceName() + ":" + cs.getTimestamp();
154+
Put put = new Put(rowkey.getBytes());
155+
//rowkey:serviceId:csTime
156+
//每列的timestamp为duration
157+
//每列列名为traceId,值为1(用来区分1ms内的跟踪)
158+
put.add(duration_index_family_column.getBytes(), long2ByteArray(span.getTraceId()), duration, "1".getBytes());
159+
HTableInterface htable = null;
160+
try {
161+
htable = POOL.getTable(duration_index);
162+
System.out.println(1);
163+
htable.put(put);
164+
} catch (IOException e) {
165+
e.printStackTrace();
166+
}catch (Exception e) {
167+
e.printStackTrace();
168+
}finally {
169+
if(htable != null){
170+
try {
171+
htable.close();
172+
} catch (IOException e) {
173+
e.printStackTrace();
174+
}
170175
}
171176
}
172177
}
173178
}
174179
}
175180

181+
private boolean isRootSpan(Span span) {
182+
return span.getParentId() == null;
183+
}
184+
176185

177186
}

modules/hydra-hbase/src/test/java/com/jd/bdp/hydra/hbase/service/HbaseServiceTest.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static void main(String[] args){
4242
cs.setTimestamp(System.currentTimeMillis());
4343
cs.setValue("cs");
4444
Annotation cr = new Annotation();
45-
cr.setTimestamp(System.currentTimeMillis()-(int)(Math.random() * 100));
45+
cr.setTimestamp(System.currentTimeMillis()+(int)(Math.random() * 100));
4646
cr.setValue("cr");
4747
cr.setHost(endpoint);
4848
span.setId(new Long(i));
@@ -68,10 +68,10 @@ public static void main(String[] args){
6868
Annotation sr = new Annotation();
6969
sr.setHost(endpoint);
7070
sr.setTimestamp(System.currentTimeMillis());
71-
sr.setValue("ss");
71+
sr.setValue("sr");
7272
Annotation ss = new Annotation();
73-
ss.setTimestamp(System.currentTimeMillis()-(int)(Math.random() * 100));
74-
ss.setValue("sr");
73+
ss.setTimestamp(System.currentTimeMillis()+(int)(Math.random() * 100));
74+
ss.setValue("ss");
7575
ss.setHost(endpoint);
7676
span.setParentId(new Long(i+1));
7777
span.setId(new Long(i));

modules/hydra-web/src/main/java/com/jd/bdp/hydra/rest/TraceController.java

-5
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ public class TraceController {
2626
@ResponseBody
2727
public JSONArray getTraces(@PathVariable String serviceId, @PathVariable long startTime, @PathVariable int durationMin, @PathVariable int durationMax, @PathVariable int sum) {
2828
try {
29-
serviceId = "22001";
30-
startTime = 1366614281166L;
31-
durationMin = 20;
32-
durationMax = 80;
33-
sum = 500;
3429
return queryService.getTracesByDuration(serviceId, startTime, sum, durationMin, durationMax);
3530
}catch (Exception e){
3631
e.printStackTrace();

modules/hydra-web/src/main/webapp/statics/js/service/sequence-service.js

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ angular.module('hydra.services.sequence', [])
2323
var spanIndex = {index: 0}
2424
getMySpan(span, spanIndex);
2525

26-
2726
function getMySpan(span, spanIndex) {
2827
var anMap = {};
2928
for (var i in span.annotations) {

0 commit comments

Comments
 (0)