当前位置: 首页>>代码示例>>Java>>正文


Java Tracer.newScope方法代码示例

本文整理汇总了Java中org.apache.htrace.core.Tracer.newScope方法的典型用法代码示例。如果您正苦于以下问题:Java Tracer.newScope方法的具体用法?Java Tracer.newScope怎么用?Java Tracer.newScope使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.htrace.core.Tracer的用法示例。


在下文中一共展示了Tracer.newScope方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import org.apache.htrace.core.Tracer; //导入方法依赖的package包/类
/**
 * Run basic test. Adds span to an existing htrace table in an existing hbase setup.
 * Requires a running hbase to send the traces too with an already created trace
 * table (Default table name is 'htrace' with column families 's' and 'i').
 *
 * @param args Default arguments which passed to main method
 * @throws InterruptedException  Thread.sleep() can cause interruption in current thread.
 */
public static void main(String[] args) throws Exception {
  Tracer tracer = new Tracer.Builder().
      conf(new HBaseHTraceConfiguration(HBaseConfiguration.create())).
      build();
  tracer.addSampler(Sampler.ALWAYS);
  TraceScope parent = tracer.newScope("HBaseSpanReceiver.main.parent");
  Thread.sleep(10);
  long traceid = parent.getSpan().getSpanId().getHigh();
  TraceScope child1 = tracer.newScope("HBaseSpanReceiver.main.child.1");
  Thread.sleep(10);
  child1.close();
  TraceScope child2 = tracer.newScope("HBaseSpanReceiver.main.child.2");
  Thread.sleep(10);
  TraceScope gchild = tracer.newScope("HBaseSpanReceiver.main.grandchild");
  gchild.addTimelineAnnotation("annotation 1.");
  Thread.sleep(10);
  gchild.addTimelineAnnotation("annotation 2.");
  gchild.close();
  Thread.sleep(10);
  child2.close();
  Thread.sleep(10);
  parent.close();
  tracer.close();
  System.out.println("trace id: " + traceid);
}
 
开发者ID:apache,项目名称:incubator-htrace,代码行数:34,代码来源:HBaseSpanReceiver.java

示例2: testSimpleTraces

import org.apache.htrace.core.Tracer; //导入方法依赖的package包/类
@Test
public void testSimpleTraces() throws IOException, InterruptedException {
  FakeZipkinTransport transport = new FakeZipkinTransport();
  Tracer tracer = newTracer(transport);
  Span rootSpan = new MilliSpan.Builder().
      description("root").
      spanId(new SpanId(100, 100)).
      tracerId("test").
      begin(System.currentTimeMillis()).
      build();
  TraceScope rootScope = tracer.newScope("root");
  TraceScope innerOne = tracer.newScope("innerOne");
  TraceScope innerTwo = tracer.newScope("innerTwo");
  innerTwo.close();
  Assert.assertTrue(transport.nextMessageAsSpan().getName().contains("innerTwo"));
  innerOne.close();
  Assert.assertTrue(transport.nextMessageAsSpan().getName().contains("innerOne"));
  rootSpan.addKVAnnotation("foo", "bar");
  rootSpan.addTimelineAnnotation("timeline");
  rootScope.close();
  Assert.assertTrue(transport.nextMessageAsSpan().getName().contains("root"));
  tracer.close();
}
 
开发者ID:apache,项目名称:incubator-htrace,代码行数:24,代码来源:TestZipkinSpanReceiver.java

示例3: testSimpleTraces

import org.apache.htrace.core.Tracer; //导入方法依赖的package包/类
@Test(timeout=120000)
public void testSimpleTraces() throws IOException, InterruptedException {
  Tracer tracer = newTracer();
  Span rootSpan = new MilliSpan.Builder().
      description("root").
      spanId(new SpanId(100, 100)).
      tracerId("test").
      begin(System.currentTimeMillis()).
      build();
  TraceScope rootScope = tracer.newScope("root");
  TraceScope innerOne = tracer.newScope("innerOne");
  TraceScope innerTwo = tracer.newScope("innerTwo");
  innerTwo.close();
  Assert.assertTrue(flumeServer.nextEventBodyAsString().contains("innerTwo"));
  innerOne.close();
  Assert.assertTrue(flumeServer.nextEventBodyAsString().contains("innerOne"));
  rootSpan.addKVAnnotation("foo", "bar");
  rootSpan.addTimelineAnnotation("timeline");
  rootScope.close();
  Assert.assertTrue(flumeServer.nextEventBodyAsString().contains("root"));
  tracer.close();
}
 
开发者ID:apache,项目名称:incubator-htrace,代码行数:23,代码来源:TestFlumeSpanReceiver.java

示例4: load

import org.apache.htrace.core.Tracer; //导入方法依赖的package包/类
/**
 * This method will block if a cache entry doesn't exist, and
 * any subsequent requests for the same user will wait on this
 * request to return. If a user already exists in the cache,
 * this will be run in the background.
 * @param user key of cache
 * @return List of groups belonging to user
 * @throws IOException to prevent caching negative entries
 */
@Override
public List<String> load(String user) throws Exception {
  TraceScope scope = null;
  Tracer tracer = Tracer.curThreadTracer();
  if (tracer != null) {
    scope = tracer.newScope("Groups#fetchGroupList");
    scope.addKVAnnotation("user", user);
  }
  List<String> groups = null;
  try {
    groups = fetchGroupList(user);
  } finally {
    if (scope != null) {
      scope.close();
    }
  }

  if (groups.isEmpty()) {
    if (isNegativeCacheEnabled()) {
      negativeCache.add(user);
    }

    // We throw here to prevent Cache from retaining an empty group
    throw noGroupsForUser(user);
  }

  return groups;
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:38,代码来源:Groups.java

示例5: createFileSystem

import org.apache.htrace.core.Tracer; //导入方法依赖的package包/类
private static FileSystem createFileSystem(URI uri, Configuration conf
    ) throws IOException {
  Tracer tracer = FsTracer.get(conf);
  TraceScope scope = tracer.newScope("FileSystem#createFileSystem");
  scope.addKVAnnotation("scheme", uri.getScheme());
  try {
    Class<?> clazz = getFileSystemClass(uri.getScheme(), conf);
    FileSystem fs = (FileSystem)ReflectionUtils.newInstance(clazz, conf);
    fs.initialize(uri, conf);
    return fs;
  } finally {
    scope.close();
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:15,代码来源:FileSystem.java

示例6: invoke

import org.apache.htrace.core.Tracer; //导入方法依赖的package包/类
@Override
public Object invoke(Object proxy, Method method, Object[] args)
  throws Throwable {
  long startTime = 0;
  if (LOG.isDebugEnabled()) {
    startTime = Time.now();
  }

  // if Tracing is on then start a new span for this rpc.
  // guard it in the if statement to make sure there isn't
  // any extra string manipulation.
  Tracer tracer = Tracer.curThreadTracer();
  TraceScope traceScope = null;
  if (tracer != null) {
    traceScope = tracer.newScope(RpcClientUtil.methodToTraceString(method));
  }
  ObjectWritable value;
  try {
    value = (ObjectWritable)
      client.call(RPC.RpcKind.RPC_WRITABLE, new Invocation(method, args),
        remoteId, fallbackToSimpleAuth);
  } finally {
    if (traceScope != null) traceScope.close();
  }
  if (LOG.isDebugEnabled()) {
    long callTime = Time.now() - startTime;
    LOG.debug("Call: " + method.getName() + " " + callTime);
  }
  return value.get();
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:31,代码来源:WritableRpcEngine.java

示例7: initWorkload

import org.apache.htrace.core.Tracer; //导入方法依赖的package包/类
private static void initWorkload(Properties props, Thread warningthread, Workload workload, Tracer tracer) {
  try {
    try (final TraceScope span = tracer.newScope(CLIENT_WORKLOAD_INIT_SPAN)) {
      workload.init(props);
      warningthread.interrupt();
    }
  } catch (WorkloadException e) {
    e.printStackTrace();
    e.printStackTrace(System.out);
    System.exit(0);
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:13,代码来源:Client.java

示例8: load

import org.apache.htrace.core.Tracer; //导入方法依赖的package包/类
/**
 * This method will block if a cache entry doesn't exist, and
 * any subsequent requests for the same user will wait on this
 * request to return. If a user already exists in the cache,
 * and when the key expires, the first call to reload the key
 * will block, but subsequent requests will return the old
 * value until the blocking thread returns.
 * If reloadGroupsInBackground is true, then the thread that
 * needs to refresh an expired key will not block either. Instead
 * it will return the old cache value and schedule a background
 * refresh
 * @param user key of cache
 * @return List of groups belonging to user
 * @throws IOException to prevent caching negative entries
 */
@Override
public List<String> load(String user) throws Exception {
  TraceScope scope = null;
  Tracer tracer = Tracer.curThreadTracer();
  if (tracer != null) {
    scope = tracer.newScope("Groups#fetchGroupList");
    scope.addKVAnnotation("user", user);
  }
  List<String> groups = null;
  try {
    groups = fetchGroupList(user);
  } finally {
    if (scope != null) {
      scope.close();
    }
  }

  if (groups.isEmpty()) {
    if (isNegativeCacheEnabled()) {
      negativeCache.add(user);
    }

    // We throw here to prevent Cache from retaining an empty group
    throw noGroupsForUser(user);
  }

  // return immutable de-duped list
  return Collections.unmodifiableList(
      new ArrayList<>(new LinkedHashSet<>(groups)));
}
 
开发者ID:hopshadoop,项目名称:hops,代码行数:46,代码来源:Groups.java

示例9: initDb

import org.apache.htrace.core.Tracer; //导入方法依赖的package包/类
private static List<ClientThread> initDb(String dbname, Properties props, int threadcount,
                                         double targetperthreadperms, Workload workload, Tracer tracer,
                                         CountDownLatch completeLatch) {
  boolean initFailed = false;
  boolean dotransactions = Boolean.valueOf(props.getProperty(DO_TRANSACTIONS_PROPERTY, String.valueOf(true)));

  final List<ClientThread> clients = new ArrayList<>(threadcount);
  try (final TraceScope span = tracer.newScope(CLIENT_INIT_SPAN)) {
    int opcount;
    if (dotransactions) {
      opcount = Integer.parseInt(props.getProperty(OPERATION_COUNT_PROPERTY, "0"));
    } else {
      if (props.containsKey(INSERT_COUNT_PROPERTY)) {
        opcount = Integer.parseInt(props.getProperty(INSERT_COUNT_PROPERTY, "0"));
      } else {
        opcount = Integer.parseInt(props.getProperty(RECORD_COUNT_PROPERTY, DEFAULT_RECORD_COUNT));
      }
    }

    for (int threadid = 0; threadid < threadcount; threadid++) {
      DB db;
      try {
        db = DBFactory.newDB(dbname, props, tracer);
      } catch (UnknownDBException e) {
        System.out.println("Unknown DB " + dbname);
        initFailed = true;
        break;
      }

      int threadopcount = opcount / threadcount;

      // ensure correct number of operations, in case opcount is not a multiple of threadcount
      if (threadid < opcount % threadcount) {
        ++threadopcount;
      }

      ClientThread t = new ClientThread(db, dotransactions, workload, props, threadopcount, targetperthreadperms,
          completeLatch);

      clients.add(t);
    }

    if (initFailed) {
      System.err.println("Error initializing datastore bindings.");
      System.exit(0);
    }
  }
  return clients;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:50,代码来源:Client.java

示例10: writeWithTracing

import org.apache.htrace.core.Tracer; //导入方法依赖的package包/类
private void writeWithTracing(Tracer tracer) throws Exception {
  long startTime = System.currentTimeMillis();
  TraceScope ts = tracer.newScope("testWriteTraceHooks");
  writeTestFile("testWriteTraceHooks.dat");
  long endTime = System.currentTimeMillis();
  ts.close();

  String[] expectedSpanNames = {
    "testWriteTraceHooks",
    "ClientProtocol#create",
    "ClientNamenodeProtocol#create",
    "ClientProtocol#fsync",
    "ClientNamenodeProtocol#fsync",
    "ClientProtocol#complete",
    "ClientNamenodeProtocol#complete",
    "newStreamForCreate",
    "DFSOutputStream#write",
    "DFSOutputStream#close",
    "dataStreamer",
    "OpWriteBlockProto",
    "ClientProtocol#addBlock",
    "ClientNamenodeProtocol#addBlock"
  };
  SetSpanReceiver.assertSpanNamesFound(expectedSpanNames);

  // The trace should last about the same amount of time as the test
  Map<String, List<Span>> map = SetSpanReceiver.getMap();
  Span s = map.get("testWriteTraceHooks").get(0);
  Assert.assertNotNull(s);
  long spanStart = s.getStartTimeMillis();
  long spanEnd = s.getStopTimeMillis();

  // Spans homed in the top trace shoud have same trace id.
  // Spans having multiple parents (e.g. "dataStreamer" added by HDFS-7054)
  // and children of them are exception.
  String[] spansInTopTrace = {
    "testWriteTraceHooks",
    "ClientProtocol#create",
    "ClientNamenodeProtocol#create",
    "ClientProtocol#fsync",
    "ClientNamenodeProtocol#fsync",
    "ClientProtocol#complete",
    "ClientNamenodeProtocol#complete",
    "newStreamForCreate",
    "DFSOutputStream#write",
    "DFSOutputStream#close",
  };
  for (String desc : spansInTopTrace) {
    for (Span span : map.get(desc)) {
      Assert.assertEquals(ts.getSpan().getSpanId().getHigh(),
                          span.getSpanId().getHigh());
    }
  }

  // test for timeline annotation added by HADOOP-11242
  Assert.assertEquals("called",
      map.get("ClientProtocol#create")
         .get(0).getTimelineAnnotations()
         .get(0).getMessage());

  SetSpanReceiver.clear();
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:63,代码来源:TestTracing.java

示例11: testKafkaTransport

import org.apache.htrace.core.Tracer; //导入方法依赖的package包/类
@Test
public void testKafkaTransport() throws Exception {

  String topic = "zipkin";
  // Kafka setup
  EmbeddedZookeeper zkServer = new EmbeddedZookeeper(TestZKUtils.zookeeperConnect());
  ZkClient zkClient = new ZkClient(zkServer.connectString(), 30000, 30000, ZKStringSerializer$.MODULE$);
  Properties props = TestUtils.createBrokerConfig(0, TestUtils.choosePort(), false);
  KafkaConfig config = new KafkaConfig(props);
  KafkaServer kafkaServer = TestUtils.createServer(config, new MockTime());

  Buffer<KafkaServer> servers = JavaConversions.asScalaBuffer(Collections.singletonList(kafkaServer));
  TestUtils.createTopic(zkClient, topic, 1, 1, servers, new Properties());
  zkClient.close();
  TestUtils.waitUntilMetadataIsPropagated(servers, topic, 0, 5000);

  // HTrace
  HTraceConfiguration hTraceConfiguration = HTraceConfiguration.fromKeyValuePairs(
      "sampler.classes", "AlwaysSampler",
      "span.receiver.classes", ZipkinSpanReceiver.class.getName(),
      "zipkin.kafka.metadata.broker.list", config.advertisedHostName() + ":" + config.advertisedPort(),
      "zipkin.kafka.topic", topic,
      ZipkinSpanReceiver.TRANSPORT_CLASS_KEY, KafkaTransport.class.getName()
  );

  final Tracer tracer = new Tracer.Builder("test-tracer")
      .tracerPool(new TracerPool("test-tracer-pool"))
      .conf(hTraceConfiguration)
      .build();

  String scopeName = "test-kafka-transport-scope";
  TraceScope traceScope = tracer.newScope(scopeName);
  traceScope.close();
  tracer.close();

  // Kafka consumer
  Properties consumerProps = new Properties();
  consumerProps.put("zookeeper.connect", props.getProperty("zookeeper.connect"));
  consumerProps.put(ConsumerConfig.GROUP_ID_CONFIG, "testing.group");
  consumerProps.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "smallest");
  ConsumerConnector connector =
      kafka.consumer.Consumer.createJavaConsumerConnector(new kafka.consumer.ConsumerConfig(consumerProps));
  Map<String, Integer> topicCountMap = new HashMap<>();
  topicCountMap.put(topic, 1);
  Map<String, List<KafkaStream<byte[], byte[]>>> streams = connector.createMessageStreams(topicCountMap);
  ConsumerIterator<byte[], byte[]> it = streams.get(topic).get(0).iterator();

  // Test
  Assert.assertTrue("We should have one message in Kafka", it.hasNext());
  Span span = new Span();
  new TDeserializer(new TBinaryProtocol.Factory()).deserialize(span, it.next().message());
  Assert.assertEquals("The span name should match our scope description", span.getName(), scopeName);

  kafkaServer.shutdown();

}
 
开发者ID:apache,项目名称:incubator-htrace,代码行数:57,代码来源:ITZipkinReceiver.java


注:本文中的org.apache.htrace.core.Tracer.newScope方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。