Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add zipkin #642

Merged
merged 40 commits into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
b0b32c3
feat:add zipkin
LXPWing May 26, 2022
af1449c
Merge branch 'main' into feature/add_zipkin
LXPWing May 30, 2022
64ac2de
feat: add zipkin
LXPWing Jun 4, 2022
90b188a
feat: add zipkin
LXPWing Jun 9, 2022
ed53e22
feat: add zipkin
LXPWing Jun 10, 2022
b7f8eed
Merge branch 'main' into feature/add_zipkin
LXPWing Jun 10, 2022
1b4a8cd
feat: add jaeger
LXPWing Jun 10, 2022
6654a78
feat: add jaeger
LXPWing Jun 11, 2022
7f22f02
feat: add zipkin
LXPWing Jun 12, 2022
df5470e
fix: zipkin json style
LXPWing Jun 12, 2022
b4136f0
fix: zipkin code
LXPWing Jun 12, 2022
1d35623
fix: zipkin code
LXPWing Jun 13, 2022
eb7064c
Merge remote-tracking branch 'origin/main' into feature/add_zipkin
LXPWing Jun 13, 2022
dc4da91
fix: zipkin code
LXPWing Jun 13, 2022
0d83f25
fix: zipkin code
LXPWing Jun 13, 2022
4d87b74
Merge branch 'main' into feature/add_zipkin
Xunzhuo Jun 17, 2022
bc2178c
fix: zipkin docs
LXPWing Jun 18, 2022
7de5bdc
Merge remote-tracking branch 'origin/feature/add_zipkin' into feature…
LXPWing Jun 18, 2022
d324071
fix: zipkin go mod
LXPWing Jun 18, 2022
927c47f
fix: zipkin go mod
LXPWing Jun 18, 2022
84651fd
fix: zipkin go mod
LXPWing Jun 18, 2022
3cd6cfe
fix: zipkin go mod
LXPWing Jun 18, 2022
0203a53
fix: zipkin quickstart
LXPWing Jun 18, 2022
a37049f
fix: zipkin go mod
LXPWing Jun 18, 2022
c249d0d
fix: zipkin go mod
LXPWing Jun 18, 2022
00827ca
fix: zipkin go mod
LXPWing Jun 18, 2022
358918d
fix: zipkin go mod
LXPWing Jun 18, 2022
a6f4858
fix: zipkin docs
LXPWing Jun 18, 2022
0e4f572
Merge branch 'main' into feature/add_zipkin
seeflood Jun 20, 2022
ffe852d
fix: zipkin json
LXPWing Jun 20, 2022
28523f8
Update config_trace_zipkin.json
LXPWing Jun 20, 2022
5079626
fix: zipkin json
LXPWing Jun 21, 2022
387f742
Merge remote-tracking branch 'origin/feature/add_zipkin' into feature…
LXPWing Jun 21, 2022
2178e6a
fix: zipkin docs
LXPWing Jun 21, 2022
91b57d4
Merge branch 'main' into feature/add_zipkin
LXPWing Jun 21, 2022
0c064b5
fix: zipkin docs
LXPWing Jun 21, 2022
efb6abf
Merge remote-tracking branch 'origin/feature/add_zipkin' into feature…
LXPWing Jun 21, 2022
4dcc937
fix: zipkin docs
LXPWing Jun 21, 2022
6669503
fix: zipkin docs
LXPWing Jun 21, 2022
18502fe
upload img to cdn
seeflood Jun 21, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cmd/layotto/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ import (
"strconv"
"time"

mosn_zipkin "mosn.io/mosn/pkg/trace/zipkin"

"mosn.io/layotto/diagnostics/zipkin"

mosn_jaeger "mosn.io/mosn/pkg/trace/jaeger"

"github.com/dapr/components-contrib/secretstores"
Expand Down Expand Up @@ -519,6 +523,7 @@ func ExtensionsRegister(_ *cli.Context) {
trace.RegisterTracerBuilder("SOFATracer", lprotocol.Layotto, diagnostics.NewTracer)
trace.RegisterTracerBuilder(skywalking.SkyDriverName, lprotocol.Layotto, lsky.NewGrpcSkyTracer)
trace.RegisterTracerBuilder(mosn_jaeger.DriverName, lprotocol.Layotto, jaeger.NewGrpcJaegerTracer)
trace.RegisterTracerBuilder(mosn_zipkin.DriverName, lprotocol.Layotto, zipkin.NewGrpcZipTracer)
}

func main() {
Expand Down
3 changes: 3 additions & 0 deletions cmd/layotto_multiple_api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
secretstore_env "github.com/dapr/components-contrib/secretstores/local/env"
secretstore_file "github.com/dapr/components-contrib/secretstores/local/file"
mosn_jaeger "mosn.io/mosn/pkg/trace/jaeger"
mosn_zipkin "mosn.io/mosn/pkg/trace/zipkin"

secretstores_loader "mosn.io/layotto/pkg/runtime/secretstores"

Expand Down Expand Up @@ -179,6 +180,7 @@ import (
"mosn.io/layotto/diagnostics/jaeger"
lprotocol "mosn.io/layotto/diagnostics/protocol"
lsky "mosn.io/layotto/diagnostics/skywalking"
"mosn.io/layotto/diagnostics/zipkin"
)

// loggerForDaprComp is constructed for reusing dapr's components.
Expand Down Expand Up @@ -531,6 +533,7 @@ func ExtensionsRegister(_ *cli.Context) {
trace.RegisterTracerBuilder("SOFATracer", "layotto", diagnostics.NewTracer)
trace.RegisterTracerBuilder(skywalking.SkyDriverName, lprotocol.Layotto, lsky.NewGrpcSkyTracer)
trace.RegisterTracerBuilder(mosn_jaeger.DriverName, lprotocol.Layotto, jaeger.NewGrpcJaegerTracer)
trace.RegisterTracerBuilder(mosn_zipkin.DriverName, lprotocol.Layotto, zipkin.NewGrpcZipTracer)
}

func main() {
Expand Down
83 changes: 83 additions & 0 deletions configs/config_trace_zipkin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{
"servers": [
{
"default_log_path": "stdout",
"default_log_level": "INFO",
"listeners": [
{
"name": "grpc",
"address": "0.0.0.0:34904",
"bind_port": true,
"filter_chains": [
{
"filters": [
{
"type": "grpc",
"config": {
"server_name": "runtime",
"grpc_config": {
"hellos": {
"quick_start_demo": {
"type": "helloworld",
"hello": "greeting"
}
},
"config_store": {
"config_demo": {
"type": "etcd",
"address": [
"127.0.0.1:2379"
],
"timeout": "10"
}
}
}
}
}
]
}
],
"stream_filters": [
{
"type": "flowControlFilter",
"config": {
"global_switch": true,
"limit_key_type": "PATH",
"rules": [
{
"resource": "/spec.proto.runtime.v1.Runtime/SayHello",
"grade": 1,
"threshold": 5
}
]
}
},
{
"type": "grpc_metric"
}
]
}
]
}
],
"tracing": {
"enable": true,
"driver": "Zipkin",
"config": {
"service_name": "layotto",
"reporter_endpoint": "http://127.0.0.1:9411/api/v2/spans",
"recorder_host_post": "127.0.0.1:34904"
}
},
"metrics": {
"sinks": [
{
"type": "prometheus",
"config": {
"port": 34903
}
}
]
}
}

143 changes: 143 additions & 0 deletions diagnostics/zipkin/grpc_tracer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
/*
* Copyright 2021 Layotto Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package zipkin

import (
"context"
"fmt"
"time"

"mosn.io/layotto/diagnostics/grpc"

"github.com/openzipkin/zipkin-go"
reporterhttp "github.com/openzipkin/zipkin-go/reporter/http"
"mosn.io/api"
"mosn.io/mosn/pkg/types"
"mosn.io/pkg/log"

ltrace "mosn.io/layotto/components/trace"
)

const (
service_name = "service_name"
reporter_endpoint = "reporter_endpoint"
recorder_host_post = "recorder_host_post"
)

type grpcZipTracer struct {
*zipkin.Tracer
}

type grpcZipSpan struct {
*ltrace.Span
tracer *grpcZipTracer
ctx context.Context
span zipkin.Span
}

func NewGrpcZipTracer(traceCfg map[string]interface{}) (api.Tracer, error) {
point, err := getReporterEndpoint(traceCfg)
if err != nil {
return nil, err
}

reporter := reporterhttp.NewReporter(point)

name, err := getServerName(traceCfg)
if err != nil {
return nil, err
}

host_post, err := getRecorderHostPort(traceCfg)
if err != nil {
return nil, err
}

endpoint, err := zipkin.NewEndpoint(name, host_post)
if err != nil {
log.DefaultLogger.Errorf("[layotto] [zipkin] [tracer] unable to create zipkin reporter endpoint")
return nil, err
}

tracer, err := zipkin.NewTracer(reporter, zipkin.WithLocalEndpoint(endpoint), zipkin.WithTraceID128Bit(true))
if err != nil {
log.DefaultLogger.Errorf("[layotto] [zipkin] [tracer] cannot initialize zipkin Tracer")
return nil, err
}

log.DefaultLogger.Infof("[layotto] [zipkin] [tracer] create success")

return &grpcZipTracer{
tracer,
}, nil
}

func getRecorderHostPort(traceCfg map[string]interface{}) (string, error) {
if recorder, ok := traceCfg[recorder_host_post]; ok {
return recorder.(string), nil
}

return "", fmt.Errorf("[layotto] [zipkin] [tracer] no config zipkin server host and port")
}

func getReporterEndpoint(traceCfg map[string]interface{}) (string, error) {
if point, ok := traceCfg[reporter_endpoint]; ok {
return point.(string), nil
}

return "", fmt.Errorf("[layotto] [zipkin] [tracer] no config zipkin reporter endpoint")
}

func getServerName(traceCfg map[string]interface{}) (string, error) {
if name, ok := traceCfg[service_name]; ok {
return name.(string), nil
}

return "", fmt.Errorf("[layotto] [zipkin] [tracer] no config zipkin server name")
}

func (t *grpcZipTracer) Start(ctx context.Context, request interface{}, _ time.Time) api.Span {
info, ok := request.(*grpc.RequestInfo)
if !ok {
log.DefaultLogger.Debugf("[layotto] [zipkin] [tracer] unable to get request header, downstream trace ignored")
return nil
}

// start span
span := t.StartSpan(info.FullMethod)

return &grpcZipSpan{
tracer: t,
ctx: ctx,
Span: &ltrace.Span{},
span: span,
}
}

func (s *grpcZipSpan) TraceId() string {
return s.span.Context().TraceID.String()
}

func (s *grpcZipSpan) InjectContext(requestHeaders types.HeaderMap, requestInfo api.RequestInfo) {
}

func (s *grpcZipSpan) SetRequestInfo(requestInfo api.RequestInfo) {
}

func (s *grpcZipSpan) FinishSpan() {
s.span.Finish()
}
23 changes: 23 additions & 0 deletions diagnostics/zipkin/zipkin-docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#Licensed to the Apache Software Foundation (ASF) under one or more
#contributor license agreements. See the NOTICE file distributed with
#this work for additional information regarding copyright ownership.
#The ASF licenses this file to You under the Apache License, Version 2.0
#(the "License"); you may not use this file except in compliance with
#the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#limitations under the License.

version: '3.3'
services:
zipkin:
image: openzipkin/zipkin:latest
container_name: zipkin
restart: always
ports:
- "9411:9411"
1 change: 1 addition & 0 deletions docs/zh/_sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
- 可观测性
- [Trace, Metrics](zh/start/trace/trace.md)
- [Trace 接入 Skywalking](zh/start/trace/skywalking.md)
- [Trace 接入 Zipkin](zh/start/trace/zipkin.md)
- [Trace 接入 Jaeger](zh/start/trace/jaeger.md)
- [Metrics 接入 Prometheus](zh/start/trace/prometheus.md)
- [将业务逻辑通过 WASM 下沉进sidecar](zh/start/wasm/start.md)
Expand Down
Loading