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 jaeger #590

Merged
merged 37 commits into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
859d06f
feature: add jaeger
LXPWing Apr 25, 2022
277d0b8
feat: add jaeger
LXPWing May 13, 2022
39a4553
feat: add jaeger
LXPWing May 19, 2022
13bf554
feat: add jaeger
LXPWing May 19, 2022
b40267a
feat: add jaeger
LXPWing May 19, 2022
33f3d2e
feat: add jaeger
LXPWing May 20, 2022
aef3b2a
fix: meger main
LXPWing May 20, 2022
dee8a71
fix: code style
LXPWing May 20, 2022
38e29c6
fix: code style
LXPWing May 20, 2022
fa16d47
fix: code style
LXPWing May 20, 2022
f72725b
fix: ut code
LXPWing May 20, 2022
63d080d
fix: ut code
LXPWing May 20, 2022
d141520
fix: ut code
LXPWing May 20, 2022
8fdcdfa
feat: add docs
LXPWing May 20, 2022
54aaf13
fix: docs
LXPWing May 21, 2022
bf06b67
Merge branch 'main' into feature/add_jaeger
LXPWing May 21, 2022
9fb3700
Merge branch 'main' into feature/add_jaeger
LXPWing May 24, 2022
309c56f
Merge branch 'main' into feature/add_jaeger
seeflood May 26, 2022
638fd19
Merge branch 'main' into feature/add_jaeger
seeflood May 26, 2022
dc2470f
Merge branch 'main' into feature/add_jaeger
seeflood May 26, 2022
12029b0
Merge branch 'main' into feature/add_jaeger
LXPWing May 26, 2022
2cd562b
fix: add quickstart
LXPWing May 26, 2022
ecc6c99
Merge remote-tracking branch 'origin/feature/add_jaeger' into feature…
LXPWing May 26, 2022
df4f6fa
fix: go mod
LXPWing May 26, 2022
ab27502
fix: go mod
LXPWing May 26, 2022
110f368
fix: go mod
LXPWing May 26, 2022
f0c71d4
fix: docs
LXPWing May 26, 2022
af79104
fix: docs
LXPWing May 26, 2022
605d364
fix: docs
LXPWing May 26, 2022
390d2ec
fix: json
LXPWing May 26, 2022
73a3145
fix: docs side
LXPWing May 28, 2022
1788ccb
fix: docs png
LXPWing May 28, 2022
e196ba0
Merge branch 'main' into feature/add_jaeger
seeflood Jun 1, 2022
80573ef
Merge branch 'main' into feature/add_jaeger
seeflood Jun 3, 2022
e462ed5
add comments
seeflood Jun 3, 2022
3bba79a
fix: jaeger strategy check
LXPWing Jun 4, 2022
465eeaa
Merge remote-tracking branch 'origin/feature/add_jaeger' into feature…
LXPWing Jun 4, 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
3 changes: 2 additions & 1 deletion cmd/layotto/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ import (
_ "mosn.io/layotto/pkg/wasm"

_ "mosn.io/layotto/diagnostics/exporter_iml"
"mosn.io/layotto/diagnostics/jaeger"
lprotocol "mosn.io/layotto/diagnostics/protocol"
lsky "mosn.io/layotto/diagnostics/skywalking"
)
Expand Down Expand Up @@ -515,7 +516,7 @@ func ExtensionsRegister(_ *cli.Context) {
trace.RegisterTracerBuilder("SOFATracer", protocol.HTTP1, tracehttp.NewTracer)
trace.RegisterTracerBuilder("SOFATracer", lprotocol.Layotto, diagnostics.NewTracer)
trace.RegisterTracerBuilder(skywalking.SkyDriverName, lprotocol.Layotto, lsky.NewGrpcSkyTracer)

trace.RegisterTracerBuilder("Jaeger", lprotocol.Layotto, jaeger.NewGrpcJaegerTracer)
}

func main() {
Expand Down
2 changes: 2 additions & 0 deletions cmd/layotto_multiple_api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ import (
"mosn.io/layotto/pkg/runtime"

_ "mosn.io/layotto/diagnostics/exporter_iml"
"mosn.io/layotto/diagnostics/jaeger"
lprotocol "mosn.io/layotto/diagnostics/protocol"
lsky "mosn.io/layotto/diagnostics/skywalking"
)
Expand Down Expand Up @@ -489,6 +490,7 @@ func ExtensionsRegister(_ *cli.Context) {
trace.RegisterTracerBuilder("SOFATracer", protocol.HTTP1, tracehttp.NewTracer)
trace.RegisterTracerBuilder("SOFATracer", "layotto", diagnostics.NewTracer)
trace.RegisterTracerBuilder(skywalking.SkyDriverName, lprotocol.Layotto, lsky.NewGrpcSkyTracer)
trace.RegisterTracerBuilder("Jaeger", lprotocol.Layotto, jaeger.NewGrpcJaegerTracer)

}

Expand Down
82 changes: 82 additions & 0 deletions configs/config_trace_jaeger.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"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": {
"helloworld": {
"hello": "greeting"
}
},
"config_store": {
"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"
}
]
}
]
}
],
"tracing": {
"enable": true,
"driver": "jaeger",
"config": {
"config": {
"service_name": "layotto",
"agent_host": "127.0.0.1:6831",
"strategy": "collector"
}
}
},
"metrics": {
"sinks": [
{
"type": "prometheus",
"config": {
"port": 34903
}
}
]
}
}
188 changes: 188 additions & 0 deletions diagnostics/jaeger/grpc_tracer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
/*
* 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 jaeger

import (
"context"
"os"
"time"

"github.com/opentracing/opentracing-go"
jaegerc "github.com/uber/jaeger-client-go"
"github.com/uber/jaeger-client-go/config"
"mosn.io/api"
"mosn.io/mosn/pkg/log"
"mosn.io/mosn/pkg/trace"
"mosn.io/mosn/pkg/trace/jaeger"
"mosn.io/mosn/pkg/types"

ltrace "mosn.io/layotto/components/trace"
"mosn.io/layotto/diagnostics/grpc"
"mosn.io/layotto/diagnostics/protocol"
)

const (
serviceName = "layotto"
strategy = "strategy"
agentHost = "agent_host"
collectorEndpoint = "collector_endpoint"
defaultServiceName = "layotto"
defaultJaegerAgentHost = "127.0.0.1:6831"
jaegerAgentHostKey = "TRACE"
appIDKey = "APP_ID"
defaultCollectorEndpoint = "http://127.0.0.1:14268/api/traces"
defaultStrategy = "collector"
)

type grpcJaegerTracer struct {
tracer opentracing.Tracer
}

type grpcJaegerSpan struct {
*ltrace.Span
ctx context.Context
trace *grpcJaegerTracer
jaegerSpan opentracing.Span
spanCtx jaegerc.SpanContext
}

func init() {
trace.RegisterTracerBuilder(jaeger.DriverName, protocol.Layotto, NewGrpcJaegerTracer)
seeflood marked this conversation as resolved.
Show resolved Hide resolved
}

func NewGrpcJaegerTracer(traceCfg map[string]interface{}) (api.Tracer, error) {
var reporter *config.ReporterConfig

// Determining whether to start the agent
strategy := getStrategy(traceCfg)

if strategy == defaultStrategy {
reporter = &config.ReporterConfig{
LogSpans: false,
BufferFlushInterval: 1 * time.Second,
CollectorEndpoint: getCollectorEndpoint(traceCfg),
}
} else {
reporter = &config.ReporterConfig{
LogSpans: false,
BufferFlushInterval: 1 * time.Second,
LocalAgentHostPort: getAgentHost(traceCfg),
}
}

cfg := config.Configuration{
Disabled: false,
Sampler: &config.SamplerConfig{
Type: "const",
Param: 1,
},
Reporter: reporter,
}

cfg.ServiceName = getServiceName(traceCfg)
tracer, _, err := cfg.NewTracer()

log.DefaultLogger.Infof("[layotto] [jaeger] [tracer] jaeger agent host:%s, report service name:%s",
getAgentHost(traceCfg), getServiceName(traceCfg))

if err != nil {
log.DefaultLogger.Errorf("[jaeger] [tracer] [layotto] cannot initialize Jaeger Tracer")
return nil, err
}

return &grpcJaegerTracer{
tracer: tracer,
}, nil
}

func getAgentHost(traceCfg map[string]interface{}) string {
if agentHost, ok := traceCfg[agentHost]; ok {
return agentHost.(string)
}

//if TRACE is not set, get it from the env variable
if host := os.Getenv(jaegerAgentHostKey); host != "" {
return host
}

return defaultJaegerAgentHost
}

func getStrategy(traceCfg map[string]interface{}) string {
if strategy, ok := traceCfg[strategy]; ok {
return strategy.(string)
LXPWing marked this conversation as resolved.
Show resolved Hide resolved
}

return defaultStrategy
}

func getCollectorEndpoint(traceCfg map[string]interface{}) string {
if collectorEndpoint, ok := traceCfg[collectorEndpoint]; ok {
return collectorEndpoint.(string)
}

return defaultCollectorEndpoint
}

func getServiceName(traceCfg map[string]interface{}) string {
if service, ok := traceCfg[serviceName]; ok {
return service.(string)
}

//if service_name is not set, get it from the env variable
if appID := os.Getenv(appIDKey); appID != "" {
return appID + "_sidecar"
}

return defaultServiceName
}

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

//create entry span (downstream)
sp, _ := opentracing.StartSpanFromContextWithTracer(ctx, t.tracer, header.FullMethod)

//renew span context
newSpanCtx, _ := sp.Context().(jaegerc.SpanContext)

return &grpcJaegerSpan{
trace: t,
ctx: ctx,
Span: &ltrace.Span{},
spanCtx: newSpanCtx,
jaegerSpan: sp,
}
}

func (s *grpcJaegerSpan) TraceId() string {
return s.spanCtx.TraceID().String()
}

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

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

func (s *grpcJaegerSpan) FinishSpan() {
s.jaegerSpan.Finish()
}
29 changes: 29 additions & 0 deletions diagnostics/jaeger/jaeger-docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#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:
jaegertracing-all-in-one:
image: jaegertracing/all-in-one:latest
ports:
- "5775:5775/udp"
- "16686:16686"
- "14250:14250"
- "14268:14268"
- "6831:6831"




Binary file added docs/img/trace/jaeger.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading