This is an automated email from the ASF dual-hosted git repository.
chia7712 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/yunikorn-core.git
The following commit(s) were added to refs/heads/master by this push:
new e664cc7c [YUNIKORN-2395] Remove Jaeger dependencies and cleanup
outdated traces implementation (#805)
e664cc7c is described below
commit e664cc7cbaaf0ce381e4439e180f18552127ba2f
Author: Yu-Lin Chen <[email protected]>
AuthorDate: Tue Feb 20 01:11:28 2024 +0800
[YUNIKORN-2395] Remove Jaeger dependencies and cleanup outdated traces
implementation (#805)
Closes: #805
Signed-off-by: Chia-Ping Tsai <[email protected]>
---
go.mod | 7 -
go.sum | 36 ---
pkg/scheduler/trace_utils.go | 91 -------
pkg/scheduler/trace_utils_test.go | 125 ----------
pkg/trace/scheduler_trace_context.go | 199 ---------------
pkg/trace/scheduler_trace_context_test.go | 401 ------------------------------
pkg/trace/scheduler_tracer.go | 127 ----------
pkg/trace/scheduler_tracer_test.go | 102 --------
pkg/trace/utils.go | 79 ------
9 files changed, 1167 deletions(-)
diff --git a/go.mod b/go.mod
index 68e2315d..3b99820f 100644
--- a/go.mod
+++ b/go.mod
@@ -28,12 +28,9 @@ require (
github.com/google/uuid v1.6.0
github.com/julienschmidt/httprouter v1.3.0
github.com/looplab/fsm v1.0.1
- github.com/opentracing/opentracing-go v1.2.0
github.com/prometheus/client_golang v1.18.0
github.com/prometheus/client_model v0.5.0
github.com/prometheus/common v0.45.0
- github.com/uber/jaeger-client-go v2.25.0+incompatible
- github.com/uber/jaeger-lib v2.4.0+incompatible
go.uber.org/zap v1.26.0
golang.org/x/net v0.21.0
golang.org/x/time v0.5.0
@@ -43,16 +40,12 @@ require (
)
require (
- github.com/HdrHistogram/hdrhistogram-go v1.0.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
- github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
- github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
- go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.10.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect
diff --git a/go.sum b/go.sum
index 9a302e55..ad64fdce 100644
--- a/go.sum
+++ b/go.sum
@@ -1,23 +1,16 @@
-github.com/HdrHistogram/hdrhistogram-go v1.0.1
h1:GX8GAYDuhlFQnI2fRDHQhTlkHMz8bEn0jTI6LJU0mpw=
-github.com/HdrHistogram/hdrhistogram-go v1.0.1/go.mod
h1:BWJ+nMSHY3L41Zj7CA3uXnloDp7xxV0YvstAE7nKTaM=
github.com/apache/yunikorn-scheduler-interface
v0.0.0-20240213122907-834ff5c1f36c
h1:u4ckUfYqKfrRGUyvGcyS5lMu1eVOsiMQZafjCcE/tNw=
github.com/apache/yunikorn-scheduler-interface
v0.0.0-20240213122907-834ff5c1f36c/go.mod
h1:Ga7qJusiW9E/dRokVGB50sUycR9Oc/yooixJWS0K7ZY=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod
h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/cespare/xxhash/v2 v2.2.0
h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cespare/xxhash/v2 v2.2.0/go.mod
h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
-github.com/creack/pty v1.1.9/go.mod
h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
-github.com/davecgh/go-spew v1.1.0/go.mod
h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1
h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod
h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
-github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
-github.com/golang/mock v1.6.0/go.mod
h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
github.com/golang/protobuf v1.5.0/go.mod
h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.3
h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod
h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/btree v1.1.2 h1:xf4v41cLI2Z6FxbKm+8Bu+m8ifhj15JuZ9sa0jZCMUU=
github.com/google/btree v1.1.2/go.mod
h1:qOPhT0dTNdNzV6Z/lhRX0YXUafgPLFUh+gZMl761Gm4=
-github.com/google/go-cmp v0.5.2/go.mod
h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod
h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod
h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
@@ -27,19 +20,12 @@ github.com/julienschmidt/httprouter v1.3.0
h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4d
github.com/julienschmidt/httprouter v1.3.0/go.mod
h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod
h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
-github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
-github.com/kr/text v0.1.0/go.mod
h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod
h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/looplab/fsm v1.0.1 h1:OEW0ORrIx095N/6lgoGkFkotqH6s7vaFPsgjLAaF5QU=
github.com/looplab/fsm v1.0.1/go.mod
h1:PmD3fFvQEIsjMEfvZdrCDZ6y8VwKTwWNjlpEr6IKPO4=
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0
h1:jWpvCLoY8Z/e3VKvlsiIGKtc+UG6U5vzxaoagmhXfyg=
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0/go.mod
h1:QUyp042oQthUoa9bqDv0ER0wrtXnBruoNd7aNjkbP+k=
-github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod
h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
-github.com/opentracing/opentracing-go v1.2.0
h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs=
-github.com/opentracing/opentracing-go v1.2.0/go.mod
h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
-github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
-github.com/pkg/errors v0.9.1/go.mod
h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0
h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod
h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_golang v1.18.0
h1:HzFfmkOzH5Q8L8G+kSJKUx5dtG87sewO+FoDDqP5Tbk=
@@ -52,43 +38,23 @@ github.com/prometheus/procfs v0.12.0
h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k
github.com/prometheus/procfs v0.12.0/go.mod
h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo=
github.com/rogpeppe/go-internal v1.10.0
h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
github.com/rogpeppe/go-internal v1.10.0/go.mod
h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
-github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
-github.com/stretchr/objx v0.1.0/go.mod
h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
-github.com/stretchr/testify v1.3.0/go.mod
h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
-github.com/stretchr/testify v1.6.1/go.mod
h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.1
h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod
h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
-github.com/uber/jaeger-client-go v2.25.0+incompatible
h1:IxcNZ7WRY1Y3G4poYlx24szfsn/3LvK9QHCq9oQw8+U=
-github.com/uber/jaeger-client-go v2.25.0+incompatible/go.mod
h1:WVhlPFC8FDjOFMMWRy2pZqQJSXxYSwNYOkTr/Z6d3Kk=
-github.com/uber/jaeger-lib v2.4.0+incompatible
h1:fY7QsGQWiCt8pajv4r7JEvmATdCVaWxXbjwyYwsNaLQ=
-github.com/uber/jaeger-lib v2.4.0+incompatible/go.mod
h1:ComeNDZlWwrWnDv8aPp0Ba6+uUTzImX/AauajbLI56U=
-github.com/yuin/goldmark v1.4.13/go.mod
h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
-go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
-go.uber.org/atomic v1.7.0/go.mod
h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/goleak v1.2.0 h1:xqgm/S+aQvhWFTtR0XK3Jvg7z8kGV8P4X14IzwN3Eqk=
go.uber.org/goleak v1.2.0/go.mod
h1:XJYK+MuIchqpmGmUSAzotztawfKvYLUIgg7guXrwVUo=
go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ=
go.uber.org/multierr v1.10.0/go.mod
h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo=
go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so=
-golang.org/x/crypto v0.18.0/go.mod
h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
-golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
-golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
-golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo=
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
-golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
-golang.org/x/term v0.16.0/go.mod
h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod
h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=
golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
-golang.org/x/tools v0.17.0/go.mod
h1:xsh6VxdV005rRVaS6SSAf9oiAqljS7UZUacMZ8Bnsps=
-golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod
h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod
h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
-golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod
h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98
h1:bVf09lpb+OJbByTj913DRJioFFAjf/ZGxEz7MajTp2U=
google.golang.org/genproto/googleapis/rpc
v0.0.0-20230711160842-782d3b101e98/go.mod
h1:TUfxEVdsvPg18p6AslUXFoLdpED4oBnGwyqk3dV1XzM=
google.golang.org/grpc v1.58.3 h1:BjnpXut1btbtgN/6sp+brB2Kbm2LjNXnidYujAVbSoQ=
@@ -98,10 +64,8 @@ google.golang.org/protobuf v1.26.0/go.mod
h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ
google.golang.org/protobuf v1.31.0
h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.31.0/go.mod
h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod
h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
-gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod
h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c
h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod
h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
-gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod
h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU=
diff --git a/pkg/scheduler/trace_utils.go b/pkg/scheduler/trace_utils.go
deleted file mode 100644
index 8536e91f..00000000
--- a/pkg/scheduler/trace_utils.go
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- 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.
-*/
-
-package scheduler
-
-import (
- "fmt"
-
- "github.com/opentracing/opentracing-go"
-
- "github.com/apache/yunikorn-core/pkg/trace"
-)
-
-const (
- LevelKey = "level"
- PhaseKey = "phase"
- NameKey = "name"
- StateKey = "state"
- InfoKey = "info"
-)
-
-// startSpanWrapper simplifies span starting process by integrating general
tags' setting.
-// The level tag is required, nonempty and logs span's scheduling level.
(root, partition, queue, ...)
-// The phase tag is optional and logs span's calling phase. (reservedAllocate,
tryAllocate, allocate, ...)
-// The name tag is optional and logs span's related object's identity.
(resources' name or ID)
-// These tags can be decided when starting the span because they don't depend
on the calling result.
-// Logs or special tags can be set with the returned span object.
-// It shares the restriction on trace.SchedulerTraceContext that we should
start and finish span in pairs, like this:
-// span, _ := startSpanWrapper(ctx, "root", "", "")
-// defer finishActiveSpanWrapper(ctx)
-// ...
-// span.SetTag("foo", "bar") // if we have irregular tags to set
-// ...
-func startSpanWrapper(ctx trace.SchedulerTraceContext, level, phase, name
string) (opentracing.Span, error) {
- if ctx == nil {
- return opentracing.NoopTracer{}.StartSpan(""), nil
- }
- if level == "" {
- return opentracing.NoopTracer{}.StartSpan(""),
- fmt.Errorf("level field cannot be empty")
- }
-
- span, err := ctx.StartSpan(fmt.Sprintf("[%v]%v", level, phase))
- if err == nil {
- span.SetTag(LevelKey, level)
- if phase != "" {
- span.SetTag(PhaseKey, phase)
- }
- if name != "" {
- span.SetTag(NameKey, name)
- }
- }
- return span, err
-}
-
-// finishActiveSpanWrapper simplifies span finishing process by integrating
result tags' setting.
-// The state tag is optional and logs span's calling result. (skip, allocated,
reserved, ...)
-// The info tag is optional and logs span's result message. (errors or hints
for the state)
-// These general tags depend on the calling result so they can be integrated
with the finishing process
-func finishActiveSpanWrapper(ctx trace.SchedulerTraceContext, state, info
string) error {
- if ctx == nil {
- return nil
- }
-
- span, err := ctx.ActiveSpan()
- if err == nil {
- if state != "" {
- span.SetTag(StateKey, state)
- }
- if info != "" {
- span.SetTag(InfoKey, info)
- }
- return ctx.FinishActiveSpan()
- }
- return err
-}
diff --git a/pkg/scheduler/trace_utils_test.go
b/pkg/scheduler/trace_utils_test.go
deleted file mode 100644
index 976bdb6e..00000000
--- a/pkg/scheduler/trace_utils_test.go
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- 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.
-*/
-
-package scheduler
-
-import (
- "testing"
-
- "github.com/opentracing/opentracing-go"
- "gotest.tools/v3/assert"
-
- "github.com/apache/yunikorn-core/pkg/trace"
-)
-
-func Test_startSpanWrapper(t *testing.T) {
- tracer, closer, err := trace.NewConstTracer("open-tracer", true)
- assert.NilError(t, err)
- defer closer.Close()
-
- type args struct {
- ctx trace.SchedulerTraceContext
- level string
- phase string
- name string
- }
- tests := []struct {
- name string
- args args
- wantErr bool
- }{
- {
- name: "NilContext",
- args: args{
- ctx: nil,
- level: "foobar",
- phase: "",
- name: "",
- },
- wantErr: false,
- },
- {
- name: "EmptyLevel",
- args: args{
- ctx: &trace.SchedulerTraceContextImpl{
- Tracer: tracer,
- SpanStack: []opentracing.Span{},
- },
- level: "",
- phase: "",
- name: "",
- },
- wantErr: true,
- },
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- _, err := startSpanWrapper(tt.args.ctx, tt.args.level,
tt.args.phase, tt.args.name)
- if (err != nil) != tt.wantErr {
- t.Errorf("startSpanWrapper() error = %v,
wantErr %v", err, tt.wantErr)
- return
- }
- })
- }
-}
-
-func Test_finishActiveSpanWrapper(t *testing.T) {
- tracer, closer, err := trace.NewConstTracer("open-tracer", true)
- assert.NilError(t, err)
- defer closer.Close()
-
- type args struct {
- ctx trace.SchedulerTraceContext
- state string
- info string
- }
- tests := []struct {
- name string
- args args
- wantErr bool
- }{
- {
- name: "NilContext",
- args: args{
- ctx: nil,
- state: "",
- info: "",
- },
- wantErr: false,
- },
- {
- name: "EmptyContext",
- args: args{
- ctx: &trace.SchedulerTraceContextImpl{
- Tracer: tracer,
- SpanStack: []opentracing.Span{},
- },
- state: "",
- info: "",
- },
- wantErr: true,
- },
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- if err := finishActiveSpanWrapper(tt.args.ctx,
tt.args.state, tt.args.info); (err != nil) != tt.wantErr {
- t.Errorf("finishActiveSpanWrapper() error = %v,
wantErr %v", err, tt.wantErr)
- }
- })
- }
-}
diff --git a/pkg/trace/scheduler_trace_context.go
b/pkg/trace/scheduler_trace_context.go
deleted file mode 100644
index 54a17476..00000000
--- a/pkg/trace/scheduler_trace_context.go
+++ /dev/null
@@ -1,199 +0,0 @@
-/*
- 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.
-*/
-
-package trace
-
-import (
- "fmt"
- "time"
-
- "github.com/opentracing/opentracing-go"
- "github.com/opentracing/opentracing-go/ext"
- "github.com/uber/jaeger-client-go"
-)
-
-// SchedulerTraceContext manages spans for one trace.
-// It only designs for the scheduling process so we keeps the interface simple.
-// We have to call StartSpan and FinishActiveSpan in pairs, like this:
-// span, _ := ctx.StartSpan("op")
-// defer ctx.FinishActiveSpan()
-// ...
-// span.SetTag("foo", "bar")
-// ...
-// We should not call span.Finish or span.FinishWithOptions
-// because they won't change the structure in the trace context.
-// We should be careful if functions that might cause panic are involved in
the procedure when tracing,
-// which is similar to resource opening and closing.
-type SchedulerTraceContext interface {
- // ActiveSpan returns current active (latest unfinished) span in this
context object.
- // Error returns if there doesn't exist an unfinished span.
- ActiveSpan() (opentracing.Span, error)
-
- // StartSpan creates and starts a new span based on the context state
with the operationName parameter.
- // The new span is the child of current active span if it exists.
- // Or the new span will become the root span of this trace.
- StartSpan(operationName string) (opentracing.Span, error)
-
- // FinishActiveSpan finishes current active span and set its parent as
active if exists.
- // Error returns if there doesn't exist an unfinished span.
- FinishActiveSpan() error
-}
-
-var _ SchedulerTraceContext = &SchedulerTraceContextImpl{}
-
-// SchedulerTraceContextImpl reports the spans to tracer once they are
finished.
-// Root span's "sampling.priority" tag will be set to 1 to force reporting all
spans if OnDemandFlag is true.
-type SchedulerTraceContextImpl struct {
- Tracer opentracing.Tracer
- SpanStack []opentracing.Span
- OnDemandFlag bool
-}
-
-func (s *SchedulerTraceContextImpl) ActiveSpan() (opentracing.Span, error) {
- if len(s.SpanStack) == 0 {
- return nil, fmt.Errorf("active span is not found")
- }
- return s.SpanStack[len(s.SpanStack)-1], nil
-}
-
-func (s *SchedulerTraceContextImpl) StartSpan(operationName string)
(opentracing.Span, error) {
- var newSpan opentracing.Span
- if span, err := s.ActiveSpan(); err != nil {
- newSpan = s.Tracer.StartSpan(operationName)
- if s.OnDemandFlag {
- ext.SamplingPriority.Set(newSpan, 1)
- }
- } else {
- newSpan = s.Tracer.StartSpan(operationName,
opentracing.ChildOf(span.Context()))
- }
- s.SpanStack = append(s.SpanStack, newSpan)
- return newSpan, nil
-}
-
-func (s *SchedulerTraceContextImpl) FinishActiveSpan() error {
- span, err := s.ActiveSpan()
- if err != nil {
- return err
- }
- span.Finish()
- s.SpanStack = s.SpanStack[:len(s.SpanStack)-1]
- return nil
-}
-
-var _ opentracing.Span = &DelaySpan{}
-
-// DelaySpan implements the opentracing.Span interface.
-// It will set the FinishTime field and delay reporting when finished.
-type DelaySpan struct {
- opentracing.Span
- FinishTime time.Time
-}
-
-// Finish implements the opentracing.Span interface and panics when calling.
-func (d *DelaySpan) Finish() {
- panic("should not call it")
-}
-
-// FinishWithOptions implements the opentracing.Span interface and panics when
calling.
-func (d *DelaySpan) FinishWithOptions(opentracing.FinishOptions) {
- panic("should not call it")
-}
-
-var _ SchedulerTraceContext = &DelaySchedulerTraceContextImpl{}
-
-// DelaySchedulerTraceContextImpl delays reporting spans
-// and chooses whether to report based on FilterTags when the entire trace is
collected.
-type DelaySchedulerTraceContextImpl struct {
- Tracer opentracing.Tracer
- Spans []*DelaySpan
- StackLen int
- FilterTags map[string]interface{}
-}
-
-func (d *DelaySchedulerTraceContextImpl) ActiveSpan() (opentracing.Span,
error) {
- if d.StackLen == 0 {
- return nil, fmt.Errorf("active span is not found")
- }
- return d.Spans[d.StackLen-1], nil
-}
-
-func (d *DelaySchedulerTraceContextImpl) StartSpan(operationName string)
(opentracing.Span, error) {
- var newSpan *DelaySpan
- if span, err := d.ActiveSpan(); err != nil {
- newSpan = &DelaySpan{
- Span: d.Tracer.StartSpan(operationName),
- }
- ext.SamplingPriority.Set(newSpan, 1)
- } else {
- newSpan = &DelaySpan{
- Span: d.Tracer.StartSpan(operationName,
opentracing.ChildOf(span.Context())),
- }
- }
- d.Spans = append(d.Spans, newSpan)
- if d.StackLen != len(d.Spans)-1 {
- d.Spans[d.StackLen], d.Spans[len(d.Spans)-1] =
d.Spans[len(d.Spans)-1], d.Spans[d.StackLen]
- }
- d.StackLen++
- return newSpan, nil
-}
-
-// FinishActiveSpan finishes current active span by setting its FinishTime
-// and pop it from the unfinished span stack.
-func (d *DelaySchedulerTraceContextImpl) FinishActiveSpan() error {
- if _, err := d.ActiveSpan(); err != nil {
- return err
- }
- span := d.Spans[d.StackLen-1]
- span.FinishTime = time.Now()
- d.StackLen--
-
- if d.StackLen == 0 {
- if d.isMatch() {
- for _, span := range d.Spans {
-
span.Span.FinishWithOptions(opentracing.FinishOptions{
- FinishTime: span.FinishTime,
- })
- }
- }
- d.Spans = []*DelaySpan{}
- }
-
- return nil
-}
-
-// isMatch checks whether there is a span in the trace that matches the
FilterTags.
-func (d *DelaySchedulerTraceContextImpl) isMatch() bool {
- // matches if no filter tag condition exists
- if len(d.FilterTags) == 0 {
- return true
- }
- for _, span := range d.Spans {
- tags := span.Span.(*jaeger.Span).Tags()
- MatchFlag := true
- for k, v := range d.FilterTags {
- if tag, ok := tags[k]; !ok || tag != v {
- MatchFlag = false
- break
- }
- }
- if MatchFlag {
- return true
- }
- }
- return false
-}
diff --git a/pkg/trace/scheduler_trace_context_test.go
b/pkg/trace/scheduler_trace_context_test.go
deleted file mode 100644
index 26a2edc4..00000000
--- a/pkg/trace/scheduler_trace_context_test.go
+++ /dev/null
@@ -1,401 +0,0 @@
-/*
- 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.
-*/
-
-package trace
-
-import (
- "testing"
- "time"
-
- "github.com/opentracing/opentracing-go"
- "github.com/uber/jaeger-client-go"
- "gotest.tools/v3/assert"
-)
-
-func TestSchedulerTraceContextImpl(t *testing.T) {
- closeTracer, closer1, err := NewConstTracer("close-tracer", false)
- assert.NilError(t, err)
- defer closer1.Close()
- openTracer, closer2, err := NewConstTracer("open-tracer", true)
- assert.NilError(t, err)
- defer closer2.Close()
-
- type fields struct {
- Tracer opentracing.Tracer
- SpanStack []opentracing.Span
- OnDemandFlag bool
- }
-
- tests := []struct {
- name string
- fields fields
- wantDebugFlag bool
- wantSampleFlag bool
- }{
- {
- name: "Sampling_Open",
- fields: fields{
- Tracer: openTracer,
- SpanStack: []opentracing.Span{},
- OnDemandFlag: false,
- },
- wantDebugFlag: false,
- wantSampleFlag: true,
- },
- {
- name: "Sampling_Close",
- fields: fields{
- Tracer: closeTracer,
- SpanStack: []opentracing.Span{},
- OnDemandFlag: false,
- },
- wantDebugFlag: false,
- wantSampleFlag: false,
- },
- {
- name: "OnDemand_Open",
- fields: fields{
- Tracer: openTracer,
- SpanStack: []opentracing.Span{},
- OnDemandFlag: true,
- },
- wantDebugFlag: true,
- wantSampleFlag: true,
- },
- {
- name: "OnDemand_Close",
- fields: fields{
- Tracer: closeTracer,
- SpanStack: []opentracing.Span{},
- OnDemandFlag: true,
- },
- wantDebugFlag: true,
- wantSampleFlag: true,
- },
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- s := &SchedulerTraceContextImpl{
- Tracer: tt.fields.Tracer,
- SpanStack: tt.fields.SpanStack,
- OnDemandFlag: tt.fields.OnDemandFlag,
- }
- rootSpan, err := s.StartSpan("root")
- assert.Equal(t,
rootSpan.(*jaeger.Span).SpanContext().IsDebug(), tt.wantDebugFlag)
- assert.NilError(t, err)
- _, err = s.StartSpan("child")
- assert.NilError(t, err)
- assert.Equal(t, len(s.SpanStack), 2)
- span, err := s.ActiveSpan()
- assert.NilError(t, err)
- assert.Equal(t, span.(*jaeger.Span).OperationName(),
"child")
- err = s.FinishActiveSpan()
- assert.NilError(t, err)
- span, err = s.ActiveSpan()
- assert.NilError(t, err)
- assert.Equal(t, span.(*jaeger.Span).OperationName(),
"root")
- err = s.FinishActiveSpan()
- assert.NilError(t, err)
- err = s.FinishActiveSpan()
- assert.Assert(t, err != nil)
- })
- }
-}
-
-func TestDelaySpan_ForbiddenFunctions(t *testing.T) {
- type fields struct {
- Span opentracing.Span
- FinishTime time.Time
- }
- tests := []struct {
- name string
- fields fields
- }{
- {
- name: "panic",
- fields: struct {
- Span opentracing.Span
- FinishTime time.Time
- }{
- Span: nil,
- FinishTime: time.Time{},
- },
- },
- }
-
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- defer func() {
- if r := recover(); r == nil {
- t.Fatalf("don't cause a panic")
- }
- }()
- d := &DelaySpan{
- Span: tt.fields.Span,
- FinishTime: tt.fields.FinishTime,
- }
- d.Finish()
- })
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- defer func() {
- if r := recover(); r == nil {
- t.Fatalf("don't cause a panic")
- }
- }()
- d := &DelaySpan{
- Span: tt.fields.Span,
- FinishTime: tt.fields.FinishTime,
- }
- d.FinishWithOptions(opentracing.FinishOptions{})
- })
- }
-}
-
-func TestDelaySchedulerTraceContextImpl(t *testing.T) {
- tracer, closer, err := NewConstTracer("test-tracer", true)
- assert.NilError(t, err)
- defer closer.Close()
-
- type fields struct {
- Tracer opentracing.Tracer
- Spans []*DelaySpan
- FilterTags map[string]interface{}
- }
-
- tests := []struct {
- name string
- fields fields
- wantDebugFlag bool
- wantSampleFlag bool
- }{
- {
- name: "Match",
- fields: fields{
- Tracer: tracer,
- Spans: []*DelaySpan{},
- FilterTags: map[string]interface{}{
- "organ": "stem",
- },
- },
- },
- {
- name: "NotMatch",
- fields: fields{
- Tracer: tracer,
- Spans: []*DelaySpan{},
- FilterTags: map[string]interface{}{
- "organ": "root",
- "color": "green",
- },
- },
- },
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- d := &DelaySchedulerTraceContextImpl{
- Tracer: tt.fields.Tracer,
- Spans: tt.fields.Spans,
- FilterTags: tt.fields.FilterTags,
- }
- // foobar root in
- span, err := d.StartSpan("foobar")
- assert.NilError(t, err)
- span.SetTag("organ", "root").
- SetTag("color", "black").
- SetTag("depth", 0)
- assert.Equal(t, d.StackLen, 1)
- assert.Equal(t, len(d.Spans), 1)
-
- // foo stem in
- span, err = d.StartSpan("foo")
- assert.NilError(t, err)
- span.SetTag("organ", "stem").
- SetTag("color", "green").
- SetTag("depth", 1)
- assert.Equal(t, d.StackLen, 2)
- assert.Equal(t, len(d.Spans), 2)
-
- // foo stem out
- err = d.FinishActiveSpan()
- assert.NilError(t, err)
- assert.Equal(t, d.StackLen, 1)
- assert.Equal(t, len(d.Spans), 2)
-
- // bar stem in
- span, err = d.StartSpan("bar")
- assert.NilError(t, err)
- span.SetTag("organ", "stem").
- SetTag("color", "brown").
- SetTag("depth", 1)
- assert.Equal(t, d.StackLen, 2)
- assert.Equal(t, len(d.Spans), 3)
-
- // b leaf in
- span, err = d.StartSpan("b")
- assert.NilError(t, err)
- span.SetTag("organ", "leaf").
- SetTag("color", "green").
- SetTag("depth", 2)
- assert.Equal(t, d.StackLen, 3)
- assert.Equal(t, len(d.Spans), 4)
-
- // b leaf out
- err = d.FinishActiveSpan()
- assert.NilError(t, err)
- assert.Equal(t, d.StackLen, 2)
- assert.Equal(t, len(d.Spans), 4)
-
- // bar stem out
- err = d.FinishActiveSpan()
- assert.NilError(t, err)
- assert.Equal(t, d.StackLen, 1)
- assert.Equal(t, len(d.Spans), 4)
-
- // foobar root out
- err = d.FinishActiveSpan()
- assert.NilError(t, err)
- assert.Equal(t, d.StackLen, 0)
- assert.Equal(t, len(d.Spans), 0)
-
- // err finish
- err = d.FinishActiveSpan()
- assert.Assert(t, err != nil)
- })
- }
-}
-
-func TestDelaySchedulerTraceContextImpl_isMatch(t *testing.T) {
- closeTracer, closer1, err := NewConstTracer("close-tracer", false)
- assert.NilError(t, err)
- defer closer1.Close()
- openTracer, closer2, err := NewConstTracer("open-tracer", true)
- assert.NilError(t, err)
- defer closer2.Close()
-
- closeSpans := []*DelaySpan{
- {Span: closeTracer.StartSpan("foobar",
- opentracing.Tag{Key: "organ", Value: "root"},
- opentracing.Tag{Key: "color", Value: "black"},
- opentracing.Tag{Key: "depth", Value: "0"})},
- {Span: closeTracer.StartSpan("foo",
- opentracing.Tag{Key: "organ", Value: "stem"},
- opentracing.Tag{Key: "color", Value: "green"},
- opentracing.Tag{Key: "depth", Value: "1"})},
- {Span: closeTracer.StartSpan("bar",
- opentracing.Tag{Key: "organ", Value: "stem"},
- opentracing.Tag{Key: "color", Value: "brown"},
- opentracing.Tag{Key: "depth", Value: "1"})},
- {Span: closeTracer.StartSpan("b",
- opentracing.Tag{Key: "organ", Value: "leaf"},
- opentracing.Tag{Key: "color", Value: "green"},
- opentracing.Tag{Key: "depth", Value: "2"})},
- {Span: closeTracer.StartSpan("a",
- opentracing.Tag{Key: "organ", Value: "leaf"},
- opentracing.Tag{Key: "color", Value: "yellow"},
- opentracing.Tag{Key: "depth", Value: "2"})},
- {Span: closeTracer.StartSpan("r",
- opentracing.Tag{Key: "organ", Value: "leaf"},
- opentracing.Tag{Key: "color", Value: "green"},
- opentracing.Tag{Key: "depth", Value: "2"})},
- }
- openSpans := []*DelaySpan{
- {Span: openTracer.StartSpan("foobar",
- opentracing.Tag{Key: "organ", Value: "root"},
- opentracing.Tag{Key: "color", Value: "black"})},
- {Span: openTracer.StartSpan("foo",
- opentracing.Tag{Key: "organ", Value: "stem"},
- opentracing.Tag{Key: "color", Value: "green"})},
- {Span: openTracer.StartSpan("bar",
- opentracing.Tag{Key: "organ", Value: "stem"},
- opentracing.Tag{Key: "color", Value: "brown"})},
- {Span: openTracer.StartSpan("b",
- opentracing.Tag{Key: "organ", Value: "leaf"},
- opentracing.Tag{Key: "color", Value: "green"})},
- {Span: openTracer.StartSpan("a",
- opentracing.Tag{Key: "organ", Value: "leaf"},
- opentracing.Tag{Key: "color", Value: "yellow"})},
- {Span: openTracer.StartSpan("r",
- opentracing.Tag{Key: "organ", Value: "leaf"},
- opentracing.Tag{Key: "color", Value: "green"})},
- }
-
- type fields struct {
- Tracer opentracing.Tracer
- Spans []*DelaySpan
- FilterTags map[string]interface{}
- }
- tests := []struct {
- name string
- fields fields
- want bool
- }{
- {
- name: "EmptyFilterTags",
- fields: fields{
- Spans: openSpans,
- FilterTags: map[string]interface{}{},
- },
- want: true,
- },
- {
- name: "NotWritable",
- fields: fields{
- Spans: closeSpans,
- FilterTags: map[string]interface{}{
- "color": "yellow",
- },
- },
- want: false,
- },
- {
- name: "Match",
- fields: fields{
- Spans: openSpans,
- FilterTags: map[string]interface{}{
- "color": "yellow",
- },
- },
- want: true,
- },
- {
- name: "NotMatch",
- fields: fields{
- Spans: openSpans,
- FilterTags: map[string]interface{}{
- "color": "yellow",
- "organ": "stem",
- },
- },
- want: false,
- },
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- d := &DelaySchedulerTraceContextImpl{
- Tracer: tt.fields.Tracer,
- Spans: tt.fields.Spans,
- FilterTags: tt.fields.FilterTags,
- }
- if got := d.isMatch(); got != tt.want {
- t.Errorf("isMatch() = %v, want %v", got,
tt.want)
- }
- })
- }
-}
diff --git a/pkg/trace/scheduler_tracer.go b/pkg/trace/scheduler_tracer.go
deleted file mode 100644
index 84933e1c..00000000
--- a/pkg/trace/scheduler_tracer.go
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- 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.
-*/
-
-package trace
-
-import (
- "io"
- "sync"
-
- "github.com/opentracing/opentracing-go"
-
- "github.com/apache/yunikorn-core/pkg/log"
-)
-
-// SchedulerTracer defines minimum interface for tracing
-type SchedulerTracer interface {
- NewTraceContext() SchedulerTraceContext
- Close()
-}
-
-var _ SchedulerTracer = &SchedulerTracerImpl{}
-
-type SchedulerTracerImpl struct {
- Tracer opentracing.Tracer
- Closer io.Closer
- sync.RWMutex
- *SchedulerTracerImplParams
-}
-
-type SchedulerTracerImplParams struct {
- Mode string
- FilterTags map[string]interface{}
-}
-
-const (
- Sampling = "Sampling"
- Debug = "Debug"
- DebugWithFilter = "DebugWithFilter"
-)
-
-var DefaultSchedulerTracerImplParams = &SchedulerTracerImplParams{
- Mode: Sampling,
- FilterTags: nil,
-}
-
-// SetParams set runtime parameter for tracer
-func (s *SchedulerTracerImpl) SetParams(params *SchedulerTracerImplParams) {
- if params == nil {
- return
- }
- if params.Mode == DebugWithFilter && len(params.FilterTags) == 0 {
- log.Log(log.OpenTracing).Warn("FilterTags is empty while trying
to run in DebugWithFilter mode." +
- " Please use Debug mode instead.")
- }
- s.Lock()
- defer s.Unlock()
- s.SchedulerTracerImplParams = params
-}
-
-// NewTraceContext create SchedulerTraceContext based on parameter settings
-func (s *SchedulerTracerImpl) NewTraceContext() SchedulerTraceContext {
- s.RLock()
- defer s.RUnlock()
- switch s.Mode {
- case Sampling:
- return &SchedulerTraceContextImpl{
- Tracer: s.Tracer,
- SpanStack: []opentracing.Span{},
- OnDemandFlag: false,
- }
- case Debug:
- return &SchedulerTraceContextImpl{
- Tracer: s.Tracer,
- SpanStack: []opentracing.Span{},
- OnDemandFlag: true,
- }
- case DebugWithFilter:
- return &DelaySchedulerTraceContextImpl{
- Tracer: s.Tracer,
- Spans: []*DelaySpan{},
- FilterTags: s.FilterTags,
- }
- default:
- return nil
- }
-}
-
-// Close calls tracer's closer if exists
-func (s *SchedulerTracerImpl) Close() {
- if s.Closer != nil {
- s.Closer.Close()
- }
-}
-
-// NewSchedulerTracer creates new tracer instance with params
-// params is set to default sampling mode if it is nil
-func NewSchedulerTracer(params *SchedulerTracerImplParams) (SchedulerTracer,
error) {
- if params == nil {
- params = DefaultSchedulerTracerImplParams
- }
-
- tracer, closer, err := NewTracerFromEnv("yunikorn-core-scheduler")
- if err != nil {
- return nil, err
- }
-
- return &SchedulerTracerImpl{
- Tracer: tracer,
- Closer: closer,
- SchedulerTracerImplParams: params,
- }, nil
-}
diff --git a/pkg/trace/scheduler_tracer_test.go
b/pkg/trace/scheduler_tracer_test.go
deleted file mode 100644
index 3c3ba8ec..00000000
--- a/pkg/trace/scheduler_tracer_test.go
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- 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.
-*/
-
-package trace
-
-import (
- "testing"
-
- "gotest.tools/v3/assert"
-)
-
-// TestSchedulerTracerImpl tests SetParams and NewTraceContext
-func TestSchedulerTracerImpl(t *testing.T) {
- type fields struct {
- SchedulerTracerImplParams *SchedulerTracerImplParams
- }
- tests := []struct {
- name string
- fields fields
- wantType int
- wantOnDemand bool
- }{
- {
- name: "Default",
- fields: fields{
- SchedulerTracerImplParams: nil,
- },
- wantType: 0,
- wantOnDemand: false,
- },
- {
- name: "Sampling",
- fields: fields{
- SchedulerTracerImplParams:
&SchedulerTracerImplParams{
- Mode: Sampling,
- FilterTags: nil,
- },
- },
- wantType: 0,
- wantOnDemand: false,
- },
- {
- name: "Debug",
- fields: fields{
- SchedulerTracerImplParams:
&SchedulerTracerImplParams{
- Mode: Debug,
- FilterTags: nil,
- },
- },
- wantType: 0,
- wantOnDemand: true,
- },
- {
- name: "DebugWithFilter",
- fields: fields{
- SchedulerTracerImplParams:
&SchedulerTracerImplParams{
- Mode: DebugWithFilter,
- FilterTags: map[string]interface{}{
- "foo": "bar",
- },
- },
- },
- wantType: 1,
- wantOnDemand: false,
- },
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- tracer, err := NewSchedulerTracer(nil)
- assert.NilError(t, err)
- defer tracer.Close()
-
tracer.(*SchedulerTracerImpl).SetParams(tt.fields.SchedulerTracerImplParams)
- ctx := tracer.NewTraceContext()
- switch typeInfo := ctx.(type) {
- case nil:
- t.Errorf("Nil context object, type: %T",
typeInfo)
- case *SchedulerTraceContextImpl:
- assert.Equal(t, tt.wantType, 0)
- assert.Equal(t, tt.wantOnDemand,
ctx.(*SchedulerTraceContextImpl).OnDemandFlag)
- case *DelaySchedulerTraceContextImpl:
- assert.Equal(t, tt.wantType, 1)
- default:
- t.Errorf("Unknown type: %T", typeInfo)
- }
- })
- }
-}
diff --git a/pkg/trace/utils.go b/pkg/trace/utils.go
deleted file mode 100644
index 327a73fb..00000000
--- a/pkg/trace/utils.go
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- 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.
-*/
-
-// Package trace provides functions and constants for tracing.
-package trace
-
-import (
- "fmt"
- "io"
-
- "github.com/opentracing/opentracing-go"
- "github.com/uber/jaeger-client-go"
- jaegercfg "github.com/uber/jaeger-client-go/config"
- "github.com/uber/jaeger-client-go/log/zap"
- "github.com/uber/jaeger-lib/metrics"
-
- "github.com/apache/yunikorn-core/pkg/log"
-)
-
-// NewConstTracer returns an instance of Jaeger Tracer that samples 100% or 0%
of traces for test.
-func NewConstTracer(serviceName string, collect bool) (opentracing.Tracer,
io.Closer, error) {
- if serviceName == "" {
- return nil, nil, fmt.Errorf("service name is empty")
- }
- param := 0.0
- if collect {
- param = 1.0
- }
- // Sample configuration for testing. Use constant sampling to sample
every trace
- // and enable LogSpan to log every span via configured Logger.
- cfg := jaegercfg.Configuration{
- ServiceName: serviceName,
- Sampler: &jaegercfg.SamplerConfig{
- Type: jaeger.SamplerTypeConst,
- Param: param,
- },
- Reporter: &jaegercfg.ReporterConfig{
- LogSpans: true,
- },
- }
- return cfg.NewTracer(
-
jaegercfg.Logger(zap.NewLogger(log.Log(log.OpenTracing).Named(serviceName))),
- jaegercfg.Metrics(metrics.NullFactory),
- )
-}
-
-// NewTracerFromEnv returns an instance of Jaeger Tracer that get sampling
strategy from env settings.
-func NewTracerFromEnv(serviceName string) (opentracing.Tracer, io.Closer,
error) {
- cfg, err := jaegercfg.FromEnv()
- if err != nil {
- return nil, nil, err
- }
- if serviceName != "" {
- cfg.ServiceName = serviceName
- }
- // Example logger and metrics factory. Use
github.com/uber/jaeger-client-go/log
- // and github.com/uber/jaeger-lib/metrics respectively to bind to real
logging and metrics
- // frameworks.
- // Initialize tracer with a logger and a metrics factory
- return cfg.NewTracer(
-
jaegercfg.Logger(zap.NewLogger(log.Log(log.OpenTracing).Named(cfg.ServiceName))),
- jaegercfg.Metrics(metrics.NullFactory),
- )
-}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]