无法使用opencensus收集器将跟踪发布到后端

时间:2019-08-06 16:16:30

标签: opencensus

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

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

omnition / 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后端从收集器发布跟踪,但是我仍然看到相同的错误。

1 个答案:

答案 0 :(得分:0)

我的opencensus收集器配置错误。 码头工人容器网络无法看到端口9411,就像在主机网络上一样。注意到此错误配置后,我得以解决此问题。