0

我有这些容器在我的本地主机上运行

openzipkin/zipkin | 0.0.0.0:9410->9410/tcp, 0.0.0.0:9412->9411/tcp

obition/opencensus-collector:0.1.9 | 0.0.0.0:1777->1777/tcp, 0.0.0.0:8888->8888/tcp, 0.0.0.0:9411->9411/tcp, 0.0.0.0:32776->55678/tcp, 0.0.0.0:55680- >55679/tcp |

尝试直接使用 opencensus 收集器,我的收集器配置如下所示

#opencensus collector configuration
receivers:
  zipkin:
    address: "127.0.0.1:9411"

exporters:
  zipkin:
    endpoint: "http://127.0.0.1:9412/api/v2/spans"

package main

import (
    "log"
    "math/rand"
    "net/http"
    "strings"
    "time"

    "contrib.go.opencensus.io/exporter/zipkin"
    "go.opencensus.io/plugin/ochttp"
    "go.opencensus.io/stats/view"
    "go.opencensus.io/trace"

    openzipkin "github.com/openzipkin/zipkin-go"
    zipkinHTTP "github.com/openzipkin/zipkin-go/reporter/http"
)


func registerZipkin() {
    localEndpoint, err := openzipkin.NewEndpoint("golangsvc", "<My IP Address>:8080")
    if err != nil {
        log.Fatalf("Failed to create Zipkin exporter: %v", err)
    }
    reporter := zipkinHTTP.NewReporter**("http://localhost:9411/api/v2/spans")**
    exporter := zipkin.NewExporter(reporter, localEndpoint)
    trace.RegisterExporter(exporter)
    trace.ApplyConfig(trace.Config{DefaultSampler: trace.AlwaysSample()})
}

func main() {
    registerZipkin()
    mux := http.NewServeMux()
    mux.HandleFunc("/list", list)

    log.Printf("Server listening! ...")
    log.Fatal(http.ListenAndServe(":8080", h))
}

func list(w http.ResponseWriter, r *http.Request) {
    log.Printf("Serving request: %s", r.URL.Path)
    res := strings.Repeat("o", rand.Intn(99971)+1)
    time.Sleep(time.Duration(rand.Intn(977)+1) * time.Millisecond)
    w.Write([]byte("Hello, w" + res + "rld!"))
}

当我运行这个示例时,收集器日志有很多错误

{"level":"info","ts":1565104219.6790097,"caller":"collector/collector.go:167","msg":"Starting...","NumCPU":2}
{"level":"info","ts":1565104219.6798325,"caller":"pprofserver/pprofserver.go:62","msg":"Starting net/http/pprof server","port":1777}
{"level":"info","ts":1565104219.6800768,"caller":"healthcheck/handler.go:99","msg":"Health Check server started","http-port":13133,"status":"unavailable"}
{"level":"info","ts":1565104219.680858,"caller":"config/config.go:490","msg":"Trace Exporter enabled","exporter":"zipkin"}
{"level":"info","ts":1565104219.6812553,"caller":"collector/collector.go:114","msg":"Running zPages","port":55679}
{"level":"info","ts":1565104220.6819282,"caller":"opencensus/receiver.go:51","msg":"OpenCensus receiver is running.","port":55678}
{"level":"info","ts":1565104220.6824179,"caller":**"zipkin/receiver.go:50","msg":"Zipkin receiver is running.","port":9411}**
{"level":"info","ts":1565104220.6848924,"caller":"collector/telemetry.go:93","msg":"Serving Prometheus metrics","port":8888}
{"level":"info","ts":1565104220.685225,"caller":"healthcheck/handler.go:133","msg":"Health Check state change","status":"ready"}
2019/08/06 15:11:24 failed to send the request: Post http://127.0.0.1:9412/api/v2/spans: dial tcp 127.0.0.1:9412: connect: connection refused
2019/08/06 15:11:25 failed to send the request: Post http://127.0.0.1:9412/api/v2/spans: dial tcp 127.0.0.1:9412: connect: connection refused
2019/08/06 15:11:26 failed to send the request: Post http://127.0.0.1:9412/api/v2/spans: dial tcp 127.0.0.1:9412: connect: connection refused
2019/08/06 15:11:27 failed to send the request: Post http://127.0.0.1:9412/api/v2/spans: dial tcp 127.0.0.1:9412: connect: connection refused

我无法使用收集器将跟踪从 opencensus 收集器发送到 zipkin 后端。

还尝试使用 jaeger 后端从收集器发布跟踪,但我仍然看到相同的错误。

4

1 回答 1

0

我有一个错误的 opencensus 收集器配置。docker 容器网络无法看到端口 9411,因为它在主机网络上。在注意到这个错误配置后,我能够解决这个问题。

于 2019-08-07T14:43:53.413 回答