本文整理汇总了Golang中org/apache/htrace/client.Client类的典型用法代码示例。如果您正苦于以下问题:Golang Client类的具体用法?Golang Client怎么用?Golang Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Client类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: testIngestedSpansMetricsImpl
func testIngestedSpansMetricsImpl(t *testing.T, usePacked bool) {
htraceBld := &MiniHTracedBuilder{Name: "TestIngestedSpansMetrics",
DataDirs: make([]string, 2),
}
ht, err := htraceBld.Build()
if err != nil {
t.Fatalf("failed to create datastore: %s", err.Error())
}
defer ht.Close()
var hcl *htrace.Client
hcl, err = htrace.NewClient(ht.ClientConf(), &htrace.TestHooks{
HrpcDisabled: !usePacked,
})
if err != nil {
t.Fatalf("failed to create client: %s", err.Error())
}
NUM_TEST_SPANS := 12
allSpans := createRandomTestSpans(NUM_TEST_SPANS)
err = hcl.WriteSpans(allSpans)
if err != nil {
t.Fatalf("WriteSpans failed: %s\n", err.Error())
}
for {
var stats *common.ServerStats
stats, err = hcl.GetServerStats()
if err != nil {
t.Fatalf("GetServerStats failed: %s\n", err.Error())
}
if stats.IngestedSpans == uint64(NUM_TEST_SPANS) {
break
}
time.Sleep(1 * time.Millisecond)
}
}
示例2: TestClientGetServerConf
func TestClientGetServerConf(t *testing.T) {
htraceBld := &MiniHTracedBuilder{Name: "TestClientGetServerConf",
Cnf: map[string]string{
EXAMPLE_CONF_KEY: EXAMPLE_CONF_VALUE,
},
DataDirs: make([]string, 2)}
ht, err := htraceBld.Build()
if err != nil {
t.Fatalf("failed to create datastore: %s", err.Error())
}
defer ht.Close()
var hcl *htrace.Client
hcl, err = htrace.NewClient(ht.ClientConf(), nil)
if err != nil {
t.Fatalf("failed to create client: %s", err.Error())
}
defer hcl.Close()
serverCnf, err2 := hcl.GetServerConf()
if err2 != nil {
t.Fatalf("failed to call GetServerConf: %s", err2.Error())
}
if serverCnf[EXAMPLE_CONF_KEY] != EXAMPLE_CONF_VALUE {
t.Fatalf("unexpected value for %s: %s",
EXAMPLE_CONF_KEY, EXAMPLE_CONF_VALUE)
}
}
示例3: TestClientGetServerDebugInfo
func TestClientGetServerDebugInfo(t *testing.T) {
htraceBld := &MiniHTracedBuilder{Name: "TestClientGetServerDebugInfo",
DataDirs: make([]string, 2)}
ht, err := htraceBld.Build()
if err != nil {
t.Fatalf("failed to create datastore: %s", err.Error())
}
defer ht.Close()
var hcl *htrace.Client
hcl, err = htrace.NewClient(ht.ClientConf(), nil)
if err != nil {
t.Fatalf("failed to create client: %s", err.Error())
}
defer hcl.Close()
debugInfo, err := hcl.GetServerDebugInfo()
if err != nil {
t.Fatalf("failed to call GetServerDebugInfo: %s", err.Error())
}
if debugInfo.StackTraces == "" {
t.Fatalf(`debugInfo.StackTraces == ""`)
}
if debugInfo.GCStats == "" {
t.Fatalf(`debugInfo.GCStats == ""`)
}
}
示例4: doLoadSpans
func doLoadSpans(hcl *htrace.Client, reader io.Reader) int {
dec := json.NewDecoder(reader)
spans := make([]*common.Span, 0, 32)
var err error
for {
var span common.Span
if err = dec.Decode(&span); err != nil {
if err == io.EOF {
break
}
fmt.Printf("Failed to decode JSON: %s\n", err.Error())
return EXIT_FAILURE
}
spans = append(spans, &span)
}
if *verbose {
fmt.Printf("Writing ")
prefix := ""
for i := range spans {
fmt.Printf("%s%s", prefix, spans[i].ToJson())
prefix = ", "
}
fmt.Printf("\n")
}
err = hcl.WriteSpans(&common.WriteSpansReq{
Spans: spans,
})
if err != nil {
fmt.Println(err.Error())
return EXIT_FAILURE
}
return EXIT_SUCCESS
}
示例5: printServerInfo
// Print information retrieved from an htraced server via /server/info
func printServerInfo(hcl *htrace.Client) int {
info, err := hcl.GetServerInfo()
if err != nil {
fmt.Println(err.Error())
return EXIT_FAILURE
}
fmt.Printf("HTraced server version %s (%s)\n", info.ReleaseVersion, info.GitVersion)
return EXIT_SUCCESS
}
示例6: TestDumpAll
func TestDumpAll(t *testing.T) {
htraceBld := &MiniHTracedBuilder{Name: "TestDumpAll",
DataDirs: make([]string, 2)}
ht, err := htraceBld.Build()
if err != nil {
t.Fatalf("failed to create datastore: %s", err.Error())
}
defer ht.Close()
var hcl *htrace.Client
hcl, err = htrace.NewClient(ht.ClientConf())
if err != nil {
t.Fatalf("failed to create client: %s", err.Error())
}
NUM_TEST_SPANS := 100
allSpans := createRandomTestSpans(NUM_TEST_SPANS)
sort.Sort(allSpans)
err = hcl.WriteSpans(&common.WriteSpansReq{
Spans: allSpans,
})
if err != nil {
t.Fatalf("WriteSpans failed: %s\n", err.Error())
}
out := make(chan *common.Span, 50)
var dumpErr error
go func() {
dumpErr = hcl.DumpAll(3, out)
}()
var numSpans int
nextLogTime := time.Now().Add(time.Millisecond * 5)
for {
span, channelOpen := <-out
if !channelOpen {
break
}
common.ExpectSpansEqual(t, allSpans[numSpans], span)
numSpans++
if testing.Verbose() {
now := time.Now()
if !now.Before(nextLogTime) {
nextLogTime = now
nextLogTime = nextLogTime.Add(time.Millisecond * 5)
fmt.Printf("read back %d span(s)...\n", numSpans)
}
}
}
if numSpans != len(allSpans) {
t.Fatalf("expected to read %d spans... but only read %d\n",
len(allSpans), numSpans)
}
if dumpErr != nil {
t.Fatalf("got dump error %s\n", dumpErr.Error())
}
}
示例7: TestHrpcIoTimeout
// Tests that HRPC I/O timeouts work.
func TestHrpcIoTimeout(t *testing.T) {
htraceBld := &MiniHTracedBuilder{Name: "TestHrpcIoTimeout",
DataDirs: make([]string, 2),
Cnf: map[string]string{
conf.HTRACE_NUM_HRPC_HANDLERS: fmt.Sprintf("%d", TEST_NUM_HRPC_HANDLERS),
conf.HTRACE_HRPC_IO_TIMEOUT_MS: "1",
},
}
ht, err := htraceBld.Build()
if err != nil {
t.Fatalf("failed to create datastore: %s", err.Error())
}
defer ht.Close()
var hcl *htrace.Client
finishClient := make(chan interface{})
defer func() {
// Close the finishClient channel, if it hasn't already been closed.
defer func() { recover() }()
close(finishClient)
}()
testHooks := &htrace.TestHooks{
HandleWriteRequestBody: func() {
<-finishClient
},
}
hcl, err = htrace.NewClient(ht.ClientConf(), testHooks)
if err != nil {
t.Fatalf("failed to create client: %s", err.Error())
}
// Create some random trace spans.
allSpans := createRandomTestSpans(TEST_NUM_WRITESPANS)
var wg sync.WaitGroup
wg.Add(TEST_NUM_WRITESPANS)
for iter := 0; iter < TEST_NUM_WRITESPANS; iter++ {
go func(i int) {
defer wg.Done()
// Ignore the error return because there are internal retries in
// the client which will make this succeed eventually, usually.
// Keep in mind that we only block until we have seen
// TEST_NUM_WRITESPANS I/O errors in the HRPC server-- after that,
// we let requests through so that the test can exit cleanly.
hcl.WriteSpans(allSpans[i : i+1])
}(iter)
}
for {
if ht.Hsv.GetNumIoErrors() >= TEST_NUM_WRITESPANS {
break
}
time.Sleep(1000 * time.Nanosecond)
}
close(finishClient)
wg.Wait()
}
示例8: doDumpAll
// Dump all spans from the htraced daemon.
func doDumpAll(hcl *htrace.Client, outPath string, lim int) error {
file, err := CreateOutputFile(outPath)
if err != nil {
return err
}
w := bufio.NewWriter(file)
defer func() {
if file != nil {
w.Flush()
file.Close()
}
}()
out := make(chan *common.Span, 50)
var dumpErr error
go func() {
dumpErr = hcl.DumpAll(lim, out)
}()
var numSpans int64
nextLogTime := time.Now().Add(time.Second * 5)
for {
span, channelOpen := <-out
if !channelOpen {
break
}
if err == nil {
_, err = fmt.Fprintf(w, "%s\n", span.ToJson())
}
if *verbose {
numSpans++
now := time.Now()
if !now.Before(nextLogTime) {
nextLogTime = now.Add(time.Second * 5)
fmt.Printf("received %d span(s)...\n", numSpans)
}
}
}
if err != nil {
return errors.New(fmt.Sprintf("Write error %s", err.Error()))
}
if dumpErr != nil {
return errors.New(fmt.Sprintf("Dump error %s", dumpErr.Error()))
}
err = w.Flush()
if err != nil {
return err
}
err = file.Close()
file = nil
if err != nil {
return err
}
return nil
}
示例9: TestHrpcAdmissionsControl
// Tests that HRPC limits the number of simultaneous connections being processed.
func TestHrpcAdmissionsControl(t *testing.T) {
var wg sync.WaitGroup
wg.Add(TEST_NUM_WRITESPANS)
var numConcurrentHrpcCalls int32
testHooks := &hrpcTestHooks{
HandleAdmission: func() {
defer wg.Done()
n := atomic.AddInt32(&numConcurrentHrpcCalls, 1)
if n > TEST_NUM_HRPC_HANDLERS {
t.Fatalf("The number of concurrent HRPC calls went above "+
"%d: it's at %d\n", TEST_NUM_HRPC_HANDLERS, n)
}
time.Sleep(1 * time.Millisecond)
n = atomic.AddInt32(&numConcurrentHrpcCalls, -1)
if n >= TEST_NUM_HRPC_HANDLERS {
t.Fatalf("The number of concurrent HRPC calls went above "+
"%d: it was at %d\n", TEST_NUM_HRPC_HANDLERS, n+1)
}
},
}
htraceBld := &MiniHTracedBuilder{Name: "TestHrpcAdmissionsControl",
DataDirs: make([]string, 2),
Cnf: map[string]string{
conf.HTRACE_NUM_HRPC_HANDLERS: fmt.Sprintf("%d", TEST_NUM_HRPC_HANDLERS),
},
WrittenSpans: common.NewSemaphore(0),
HrpcTestHooks: testHooks,
}
ht, err := htraceBld.Build()
if err != nil {
t.Fatalf("failed to create datastore: %s", err.Error())
}
defer ht.Close()
var hcl *htrace.Client
hcl, err = htrace.NewClient(ht.ClientConf(), nil)
if err != nil {
t.Fatalf("failed to create client: %s", err.Error())
}
// Create some random trace spans.
allSpans := createRandomTestSpans(TEST_NUM_WRITESPANS)
for iter := 0; iter < TEST_NUM_WRITESPANS; iter++ {
go func(i int) {
err = hcl.WriteSpans(allSpans[i : i+1])
if err != nil {
t.Fatalf("WriteSpans failed: %s\n", err.Error())
}
}(iter)
}
wg.Wait()
ht.Store.WrittenSpans.Waits(int64(TEST_NUM_WRITESPANS))
}
示例10: printServerDebugInfo
// Print information retrieved from an htraced server via /server/debugInfo
func printServerDebugInfo(hcl *htrace.Client) int {
stats, err := hcl.GetServerDebugInfo()
if err != nil {
fmt.Println(err.Error())
return EXIT_FAILURE
}
fmt.Println("=== GOROUTINE STACKS ===")
fmt.Print(stats.StackTraces)
fmt.Println("=== END GOROUTINE STACKS ===")
fmt.Println("=== GC STATISTICS ===")
fmt.Print(stats.GCStats)
fmt.Println("=== END GC STATISTICS ===")
return EXIT_SUCCESS
}
示例11: printServerStats
// Print information retrieved from an htraced server via /server/info
func printServerStats(hcl *htrace.Client) int {
stats, err := hcl.GetServerStats()
if err != nil {
fmt.Println(err.Error())
return EXIT_FAILURE
}
w := new(tabwriter.Writer)
w.Init(os.Stdout, 0, 8, 0, '\t', 0)
fmt.Fprintf(w, "HTRACED SERVER STATS\n")
fmt.Fprintf(w, "Datastore Start\t%s\n",
common.UnixMsToTime(stats.LastStartMs).Format(time.RFC3339))
fmt.Fprintf(w, "Server Time\t%s\n",
common.UnixMsToTime(stats.CurMs).Format(time.RFC3339))
fmt.Fprintf(w, "Spans reaped\t%d\n", stats.ReapedSpans)
fmt.Fprintf(w, "Spans ingested\t%d\n", stats.IngestedSpans)
fmt.Fprintf(w, "Spans written\t%d\n", stats.WrittenSpans)
fmt.Fprintf(w, "Spans dropped by server\t%d\n", stats.ServerDroppedSpans)
dur := time.Millisecond * time.Duration(stats.AverageWriteSpansLatencyMs)
fmt.Fprintf(w, "Average WriteSpan Latency\t%s\n", dur.String())
dur = time.Millisecond * time.Duration(stats.MaxWriteSpansLatencyMs)
fmt.Fprintf(w, "Maximum WriteSpan Latency\t%s\n", dur.String())
fmt.Fprintf(w, "Number of leveldb directories\t%d\n", len(stats.Dirs))
w.Flush()
fmt.Println("")
for i := range stats.Dirs {
dir := stats.Dirs[i]
fmt.Printf("==== %s ===\n", dir.Path)
fmt.Printf("Approximate number of bytes: %d\n", dir.ApproximateBytes)
stats := strings.Replace(dir.LevelDbStats, "\\n", "\n", -1)
fmt.Printf("%s\n", stats)
}
w = new(tabwriter.Writer)
w.Init(os.Stdout, 0, 8, 0, '\t', 0)
fmt.Fprintf(w, "HOST SPAN METRICS\n")
mtxMap := stats.HostSpanMetrics
keys := make(sort.StringSlice, len(mtxMap))
i := 0
for k, _ := range mtxMap {
keys[i] = k
i++
}
sort.Sort(keys)
for k := range keys {
mtx := mtxMap[keys[k]]
fmt.Fprintf(w, "%s\twritten: %d\tserver dropped: %d\n",
keys[k], mtx.Written, mtx.ServerDropped)
}
w.Flush()
return EXIT_SUCCESS
}
示例12: doFindChildren
// Find information about the children of a span.
func doFindChildren(hcl *htrace.Client, sid common.SpanId, lim int) int {
spanIds, err := hcl.FindChildren(sid, lim)
if err != nil {
fmt.Printf("%s\n", err.Error())
return EXIT_FAILURE
}
pbuf, err := json.MarshalIndent(spanIds, "", " ")
if err != nil {
fmt.Println("Error: error pretty-printing span IDs to JSON: %s", err.Error())
return 1
}
fmt.Printf("%s\n", string(pbuf))
return 0
}
示例13: printServerStatsJson
// Print information retrieved from an htraced server via /server/info as JSON
func printServerStatsJson(hcl *htrace.Client) int {
stats, err := hcl.GetServerStats()
if err != nil {
fmt.Println(err.Error())
return EXIT_FAILURE
}
buf, err := json.MarshalIndent(stats, "", " ")
if err != nil {
fmt.Printf("Error marshalling server stats: %s", err.Error())
return EXIT_FAILURE
}
fmt.Printf("%s\n", string(buf))
return EXIT_SUCCESS
}
示例14: printServerStats
// Print information retrieved from an htraced server via /server/info
func printServerStats(hcl *htrace.Client) int {
stats, err := hcl.GetServerStats()
if err != nil {
fmt.Println(err.Error())
return EXIT_FAILURE
}
fmt.Printf("HTraced server stats:\n")
fmt.Printf("%d leveldb shards.\n", len(stats.Shards))
for i := range stats.Shards {
shard := stats.Shards[i]
fmt.Printf("==== %s ===\n", shard.Path)
fmt.Printf("Approximate number of spans: %d\n", shard.ApproxNumSpans)
stats := strings.Replace(shard.LevelDbStats, "\\n", "\n", -1)
fmt.Printf("%s\n", stats)
}
return EXIT_SUCCESS
}
示例15: verifySuccessfulLoad
func verifySuccessfulLoad(t *testing.T, allSpans common.SpanSlice,
dataDirs []string) {
htraceBld := &MiniHTracedBuilder{
Name: "TestReloadDataStore#verifySuccessfulLoad",
DataDirs: dataDirs,
KeepDataDirsOnClose: true,
}
ht, err := htraceBld.Build()
if err != nil {
t.Fatalf("failed to create datastore: %s", err.Error())
}
defer ht.Close()
var hcl *htrace.Client
hcl, err = htrace.NewClient(ht.ClientConf(), nil)
if err != nil {
t.Fatalf("failed to create client: %s", err.Error())
}
defer hcl.Close()
for i := 0; i < len(allSpans); i++ {
span, err := hcl.FindSpan(allSpans[i].Id)
if err != nil {
t.Fatalf("FindSpan(%d) failed: %s\n", i, err.Error())
}
common.ExpectSpansEqual(t, allSpans[i], span)
}
// Look up the spans we wrote.
var span *common.Span
for i := 0; i < len(allSpans); i++ {
span, err = hcl.FindSpan(allSpans[i].Id)
if err != nil {
t.Fatalf("FindSpan(%d) failed: %s\n", i, err.Error())
}
common.ExpectSpansEqual(t, allSpans[i], span)
}
}