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

Add: Webconsole tracing #2304

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
17 changes: 17 additions & 0 deletions bcs-services/bcs-webconsole/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,15 @@ import (
"go-micro.dev/v4/util/cmd"
"golang.org/x/sync/errgroup"
yaml2 "gopkg.in/yaml.v3"
"k8s.io/klog/v2"

gintrace "github.com/Tencent/bk-bcs/bcs-common/pkg/otel/trace/gin"
"github.com/Tencent/bk-bcs/bcs-services/bcs-webconsole/app/options"
"github.com/Tencent/bk-bcs/bcs-services/bcs-webconsole/console/api"
"github.com/Tencent/bk-bcs/bcs-services/bcs-webconsole/console/config"
"github.com/Tencent/bk-bcs/bcs-services/bcs-webconsole/console/i18n"
"github.com/Tencent/bk-bcs/bcs-services/bcs-webconsole/console/podmanager"
"github.com/Tencent/bk-bcs/bcs-services/bcs-webconsole/console/tracing"
"github.com/Tencent/bk-bcs/bcs-services/bcs-webconsole/console/web"
"github.com/Tencent/bk-bcs/bcs-services/bcs-webconsole/route"
)
Expand Down Expand Up @@ -153,6 +156,19 @@ func (c *WebConsoleManager) Init() error {
return err
}

//初始化 Tracer
shutdown, err := tracing.InitTracing(config.G.Tracing)
if err != nil {
klog.Info(err.Error())
}
if shutdown != nil {
defer func() {
if err := shutdown(context.Background()); err != nil {
klog.Infof("failed to shutdown TracerProvider: %s", err.Error())
}
}()
}

return nil
}

Expand Down Expand Up @@ -226,6 +242,7 @@ func (c *WebConsoleManager) initHTTPService() (*gin.Engine, error) {
AllowAllOrigins: true,
}))
router.Use(i18n.Localize())
router.Use(gintrace.Middleware(tracing.ServiceName))
Copy link
Member

@ifooth ifooth Jun 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不仅仅是自身的,第三方调用的也需要加tracing


// 注册模板和静态资源
router.SetHTMLTemplate(web.WebTemplate())
Expand Down
5 changes: 5 additions & 0 deletions bcs-services/bcs-webconsole/console/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type Configurations struct {
WebConsole *WebConsoleConf `yaml:"webconsole"`
Web *WebConf `yaml:"web"`
Etcd *EtcdConf `yaml:"etcd"`
Tracing *TracingConf `yaml:"tracing"`
}

// newConfigurations 新增配置
Expand Down Expand Up @@ -67,6 +68,10 @@ func newConfigurations() (*Configurations, error) {
c.Etcd = &EtcdConf{}
c.Etcd.Init()

// Tracing Config
c.Tracing = &TracingConf{}
c.Tracing.Init()

c.Credentials = map[string][]*Credential{}

c.Web = defaultWebConf()
Expand Down
30 changes: 30 additions & 0 deletions bcs-services/bcs-webconsole/console/config/tracing.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Tencent is pleased to support the open source community by making Blueking Container Service available.
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* Licensed under the MIT License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
* http://opensource.org/licenses/MIT
* 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 config

// TracingConf tracing config
type TracingConf struct {
Enabled bool `yaml:"enabled"`
Endpoint string `yaml:"endpoint"`
Token string `yaml:"token"`
ResourceAttrs map[string]string `yaml:"resource_attrs"`
}

// Init : tracing init
func (c *TracingConf) Init() {
c.Enabled = false
c.Token = ""
c.Endpoint = ""
c.ResourceAttrs = nil
}
21 changes: 21 additions & 0 deletions bcs-services/bcs-webconsole/console/tracing/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Tencent is pleased to support the open source community by making Blueking Container Service available.
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* Licensed under the MIT License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
* http://opensource.org/licenses/MIT
* 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 tracing

const (
ServiceName = "bcs-webconsole"
RequestIDKey = "requestID"
TracerName = "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
RequestIDHeaderKey = "X-Request-Id"
)
64 changes: 64 additions & 0 deletions bcs-services/bcs-webconsole/console/tracing/init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Tencent is pleased to support the open source community by making Blueking Container Service available.
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* Licensed under the MIT License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
* http://opensource.org/licenses/MIT
* 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 tracing

import (
"context"

"go.opentelemetry.io/otel/attribute"

"github.com/Tencent/bk-bcs/bcs-common/pkg/otel/trace"
configTracing "github.com/Tencent/bk-bcs/bcs-services/bcs-webconsole/console/config"
)

// InitTracing init tracing
func InitTracing(op *configTracing.TracingConf) (func(context.Context) error, error) {
if !op.Enabled {
return nil, nil
}
var opts []trace.Option

if op.Endpoint != "" {
opts = append(
opts,
trace.OTLPEndpoint(op.Endpoint),
)
}
attrs := make([]attribute.KeyValue, 0)

if op.Token != "" {
attrs = append(attrs, attribute.String("bk.data.token", op.Token))
}

if op.ResourceAttrs != nil {
attrs = append(attrs, newResource(op.ResourceAttrs)...)
}

opts = append(opts, trace.ResourceAttrs(attrs))

tracer, err := trace.InitTracingProvider(ServiceName, opts...)
if err != nil {
return nil, err
}

return tracer, nil
}

func newResource(attrs map[string]string) []attribute.KeyValue {
attrValues := make([]attribute.KeyValue, 0)
for k, v := range attrs {
attrValues = append(attrValues, attribute.String(k, v))
}
return attrValues
}
8 changes: 8 additions & 0 deletions bcs-services/bcs-webconsole/etc/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,11 @@ etcd:
ca: ""
cert: ""
key: ""

tracing:
enabled: false
endpoint: ""
token: ""
resource_attrs:
k1: ""
k2: ""
99 changes: 66 additions & 33 deletions bcs-services/bcs-webconsole/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ module github.com/Tencent/bk-bcs/bcs-services/bcs-webconsole
go 1.17

require (
github.com/Tencent/bk-bcs/bcs-common v0.0.0-20230607093333-1f5cd2719e19

github.com/Tencent/bk-bcs/bcs-common v0.0.0-20230612113959-ee7959290ae2
github.com/Tencent/bk-bcs/bcs-common/pkg/otel v0.0.0-20230612113959-ee7959290ae2

github.com/Tencent/bk-bcs/bcs-services/pkg v0.0.0-20220926153300-4e631deaebe4
github.com/TencentBlueKing/iam-go-sdk v0.0.8
github.com/dustin/go-humanize v1.0.0
github.com/gin-contrib/cors v1.3.1
github.com/gin-contrib/i18n v0.0.1
github.com/gin-gonic/gin v1.8.1
github.com/gin-gonic/gin v1.9.0
github.com/go-chi/chi/v5 v5.0.8
github.com/go-micro/plugins/v4/config/encoder/yaml v1.1.0
github.com/go-micro/plugins/v4/registry/etcd v1.1.0
github.com/go-micro/plugins/v4/server/http v1.1.1
Expand All @@ -23,63 +27,77 @@ require (
github.com/nicksnyder/go-i18n/v2 v2.2.0
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.11.0
github.com/prometheus/client_golang v1.11.1
github.com/prometheus/prometheus v1.8.2-0.20200811193703-869f1bc587e6
github.com/stretchr/testify v1.7.1
github.com/stretchr/testify v1.8.2
github.com/urfave/cli/v2 v2.3.0
go-micro.dev/v4 v4.8.1
golang.org/x/sync v0.0.0-20220907140024-f12130a52804
golang.org/x/text v0.3.7
google.golang.org/grpc v1.46.0

go-micro.dev/v4 v4.10.2
go.opentelemetry.io/otel v1.14.0
go.opentelemetry.io/otel/metric v0.26.0
go.opentelemetry.io/otel/trace v1.14.0
golang.org/x/sync v0.1.0
golang.org/x/text v0.8.0
google.golang.org/grpc v1.53.0

gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1
k8s.io/api v0.23.1
k8s.io/apimachinery v0.23.1
k8s.io/client-go v0.23.1
k8s.io/klog/v2 v2.30.0
k8s.io/klog/v2 v2.90.1
sigs.k8s.io/yaml v1.2.0
)

require (
github.com/BurntSushi/toml v1.1.0 // indirect
github.com/Microsoft/go-winio v0.5.2 // indirect
github.com/Microsoft/go-winio v0.6.0 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20220824120805-4b6e5c587895 // indirect
github.com/acomagu/bufpipe v1.0.3 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bitly/go-simplejson v0.5.0 // indirect
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect
github.com/bytedance/sonic v1.8.0 // indirect
github.com/cenkalti/backoff/v4 v4.2.0 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/cloudflare/circl v1.2.0 // indirect
github.com/coreos/go-semver v0.3.0 // indirect
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-git/gcfg v1.5.0 // indirect
github.com/go-git/go-billy/v5 v5.3.1 // indirect
github.com/go-git/go-git/v5 v5.4.2 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-playground/locales v0.14.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/go-playground/validator/v10 v10.10.0 // indirect
github.com/goccy/go-json v0.9.7 // indirect

github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.11.2 // indirect
github.com/goccy/go-json v0.10.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.7 // indirect
github.com/google/go-cmp v0.5.9 // indirect

github.com/google/gofuzz v1.2.0 // indirect
github.com/googleapis/gnostic v0.5.5 // indirect
github.com/gosimple/unidecode v1.0.1 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3 // indirect
github.com/imdario/mergo v0.3.13 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/miekg/dns v1.1.50 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/hashstructure v1.1.0 // indirect
Expand All @@ -88,37 +106,52 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/nxadm/tail v1.4.8 // indirect
github.com/openzipkin/zipkin-go v0.3.0 // indirect
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c // indirect
github.com/parnurzeal/gorequest v0.2.16 // indirect
github.com/pelletier/go-toml/v2 v2.0.1 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.26.0 // indirect
github.com/prometheus/procfs v0.6.0 // indirect
github.com/prometheus/common v0.30.0 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sergi/go-diff v1.2.0 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/ugorji/go/codec v1.2.7 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.9 // indirect
github.com/xanzy/ssh-agent v0.3.2 // indirect
go.etcd.io/etcd/api/v3 v3.5.2 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.2 // indirect
go.etcd.io/etcd/client/v3 v3.5.2 // indirect
go.opentelemetry.io/otel/exporters/jaeger v1.3.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.14.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.14.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.14.0 // indirect
go.opentelemetry.io/otel/exporters/zipkin v1.3.0 // indirect
go.opentelemetry.io/otel/internal/metric v0.26.0 // indirect
go.opentelemetry.io/otel/sdk v1.14.0 // indirect
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/goleak v1.1.12 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.17.0 // indirect
golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90 // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/net v0.0.0-20220909164309-bea034e7d591 // indirect
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
golang.org/x/sys v0.0.0-20220909162455-aba9fc2a8ff2 // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect

golang.org/x/arch v0.0.0-20210923205945-b76863e36670 // indirect
golang.org/x/crypto v0.5.0 // indirect
golang.org/x/mod v0.9.0 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/oauth2 v0.4.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/term v0.6.0 // indirect

golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
golang.org/x/tools v0.1.12 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
golang.org/x/tools v0.7.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20211118181313-81c1377c94b1 // indirect

google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4 // indirect
google.golang.org/grpc/examples v0.0.0-20221019203156-f51d21267df5 // indirect

google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
Expand Down
Loading