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

refactor: Organize the observability components of Cloudwego #2

Merged
merged 81 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
b196d00
combine logging for kitex and hertz
smx-Morgan Jul 23, 2024
878aba7
combine logging for kitex and hertz V2
smx-Morgan Jul 23, 2024
e1e40e6
combine logging for kitex and hertz V2
smx-Morgan Jul 23, 2024
ae5509f
combine metrics
smx-Morgan Jul 23, 2024
a0fc887
otel V2
smx-Morgan Jul 27, 2024
446d328
logging down
smx-Morgan Jul 28, 2024
4685ebb
logging V2
smx-Morgan Jul 30, 2024
9e71cff
Merge pull request #1 from smx-Morgan/mainV3
smx-Morgan Jul 30, 2024
b3729e2
propagtor V1
smx-Morgan Jul 31, 2024
6597632
propagtor V2
smx-Morgan Aug 1, 2024
89c2ad3
fix
smx-Morgan Aug 1, 2024
f5b2114
可观测组件整合 V2
smx-Morgan Aug 2, 2024
c55b0a3
抽象otel和promth共性逻辑
smx-Morgan Aug 4, 2024
327a8f9
抽象otel和promth共性逻辑 update
smx-Morgan Aug 4, 2024
af34e39
Merge pull request #2 from smx-Morgan/mainV3
smx-Morgan Aug 4, 2024
55b9056
fix bug
smx-Morgan Aug 4, 2024
830ef57
fix Reference Path
smx-Morgan Aug 4, 2024
a0801d1
add promProvider
smx-Morgan Aug 8, 2024
bd21d3f
add labelControl
smx-Morgan Aug 12, 2024
8b63a53
fix bugs
smx-Morgan Aug 12, 2024
0e8ecb7
fix format
smx-Morgan Aug 12, 2024
458b34a
fix CI
smx-Morgan Aug 15, 2024
446e393
fix labelControl name, fix promProvider,promTracer
smx-Morgan Aug 16, 2024
d5dbc22
fix labelControl name, fix promProvider,promTracer
smx-Morgan Aug 16, 2024
9cfcc20
move Measure build to promProvider
smx-Morgan Aug 17, 2024
7b61315
Unified Label Standard
smx-Morgan Aug 19, 2024
7430b81
fix CI
smx-Morgan Aug 19, 2024
2961603
fix CI bugs
smx-Morgan Aug 19, 2024
29621e2
fix CI bugs
smx-Morgan Aug 19, 2024
611aefc
fix CI bug
smx-Morgan Aug 20, 2024
afa535b
fix remove registry from tracer
smx-Morgan Aug 20, 2024
a406cd2
fix CI gofumpt
smx-Morgan Aug 20, 2024
7770544
fix change name to telemetry
smx-Morgan Aug 20, 2024
bbedf5e
fix remove promtracer
smx-Morgan Aug 21, 2024
991e025
fix tracer
smx-Morgan Aug 26, 2024
f1ad26b
fix file_name
smx-Morgan Aug 26, 2024
a9c2581
remove labelcontrol
smx-Morgan Aug 27, 2024
c3889ae
Standardized code
smx-Morgan Aug 30, 2024
e022803
add recorder for retry
smx-Morgan Aug 30, 2024
5a96cf2
update test
smx-Morgan Sep 2, 2024
57a8f2d
fix Data Race
smx-Morgan Sep 2, 2024
0e50950
fix Data Race
smx-Morgan Sep 2, 2024
95901c1
remove promProvider test add example
smx-Morgan Sep 2, 2024
be0e2ea
fix format
smx-Morgan Sep 2, 2024
2358778
move go.mod to telemetry
smx-Morgan Sep 3, 2024
d6cfb97
update makefile
smx-Morgan Sep 3, 2024
0a83f00
update makefile, update file name
smx-Morgan Sep 3, 2024
3de654b
update makefile,update labels
smx-Morgan Sep 4, 2024
3c59ee5
update measure structure
smx-Morgan Sep 7, 2024
971f968
update measure structure
smx-Morgan Sep 8, 2024
f662adb
update formate
smx-Morgan Sep 9, 2024
ced4246
update TelemetryProvider
smx-Morgan Sep 16, 2024
634b01d
update Code Formatting
smx-Morgan Sep 16, 2024
91f7ee3
update build name func
smx-Morgan Sep 16, 2024
7f07ace
Optimize logical structure
smx-Morgan Sep 17, 2024
54b55b6
Support simultaneous monitoring of HTTP and RPC
smx-Morgan Sep 19, 2024
8d527a0
remove measure form promProvider
smx-Morgan Sep 26, 2024
a3d2728
update labels
smx-Morgan Sep 29, 2024
3ccb78c
otel log component compatible with Kitex
smx-Morgan Sep 30, 2024
bc37466
fix path
smx-Morgan Oct 3, 2024
9d2204d
replace logging to hlog
smx-Morgan Oct 8, 2024
644816b
Replace logging with hlog
smx-Morgan Oct 8, 2024
d311634
fix
smx-Morgan Oct 8, 2024
0ebc361
fix
smx-Morgan Oct 8, 2024
8fa3353
fix log && Optimize promProvider
smx-Morgan Oct 8, 2024
9c72b1b
update example for promProvider
smx-Morgan Oct 8, 2024
1e6d032
update go work and fix CI
smx-Morgan Oct 8, 2024
42937e7
fix log
smx-Morgan Oct 8, 2024
5697728
Fix duplicate naming for prometheus
smx-Morgan Oct 8, 2024
3580afa
fix ci
smx-Morgan Oct 8, 2024
cd07dd7
update server
smx-Morgan Oct 9, 2024
133c326
update to metadata, support shell
smx-Morgan Oct 11, 2024
0e71ce3
update CI
smx-Morgan Oct 11, 2024
278a6e0
add examples and support shell
smx-Morgan Oct 12, 2024
77c616b
fix bugs remove the Local dependencies
smx-Morgan Oct 12, 2024
b935878
fix CI
smx-Morgan Oct 12, 2024
b6d6c17
fix CI
smx-Morgan Oct 12, 2024
6f2a8d2
fix ci & add counter to otelkitex
smx-Morgan Oct 14, 2024
1dba93f
fix unit test ci
smx-Morgan Oct 14, 2024
4631375
fix unit test ci
smx-Morgan Oct 14, 2024
72bfeb2
fix unit test ci
smx-Morgan Oct 14, 2024
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
10 changes: 5 additions & 5 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@
run:
# include `vendor` `third_party` `testdata` `examples` `Godeps` `builtin`
skip-dirs-use-default: true
skip-dirs:
- kitex_gen
skip-files:
- ".*\\.mock\\.go$"
# output configuration options
output:
# Format: colored-line-number|line-number|json|tab|checkstyle|code-climate|junit-xml|github-actions
format: colored-line-number
formats: colored-line-number
# All available settings of specific linters.
# Refer to https://golangci-lint.run/usage/linters
linters-settings:
Expand All @@ -25,6 +21,7 @@ linters-settings:
linters:
enable:
- gofumpt
- goimports
- gofmt
disable:
- errcheck
Expand All @@ -34,3 +31,6 @@ linters:
- staticcheck
issues:
exclude-use-default: true
exclude-files:
- ".*\\.mock\\.go$"
exclude-dirs:
18 changes: 7 additions & 11 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# How to Contribute

## Your First Pull Request
We use github for our codebase. You can start by reading [How To Pull Request](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests).
We use GitHub for our codebase. You can start by reading [How To Pull Request](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests).

## Branch Organization
We use [git-flow](https://nvie.com/posts/a-successful-git-branching-model/) as our branch organization, as known as [FDD](https://en.wikipedia.org/wiki/Feature-driven_development)

## Bugs
### 1. How to Find Known Issues
We are using [Github Issues](https://github.com/cloudwego/kitex/issues) for our public bugs. We keep a close eye on this and try to make it clear when we have an internal fix in progress. Before filing a new task, try to make sure your problem doesn’t already exist.
We are using [Github Issues](https://github.com/cloudwego/{project_name}/issues) for our public bugs. We keep a close eye on this and try to make it clear when we have an internal fix in progress. Before filing a new task, try to make sure your problem doesn’t already exist.

### 2. Reporting New Issues
Providing a reduced test code is a recommended way for reporting issues. Then can placed in:
Providing a reduced test code is a recommended way for reporting issues. Then can place in:
- Just in issues
- [Golang Playground](https://play.golang.org/)

Expand All @@ -23,9 +23,9 @@ Please do not report the safe disclosure of bugs to public issues. Contact us by

## Submit a Pull Request
Before you submit your Pull Request (PR) consider the following guidelines:
1. Search [GitHub](https://github.com/cloudwego/kitex/pulls) for an open or closed PR that relates to your submission. You don't want to duplicate existing efforts.
1. Search [GitHub](https://github.com/cloudwego/{project_name}/pulls) for an open or closed PR that relates to your submission. You don't want to duplicate existing efforts.
2. Be sure that an issue describes the problem you're fixing, or documents the design for the feature you'd like to add. Discussing the design upfront helps to ensure that we're ready to accept your work.
3. [Fork](https://docs.github.com/en/github/getting-started-with-github/fork-a-repo) the cloudwego/kitex repo.
3. [Fork](https://docs.github.com/en/github/getting-started-with-github/fork-a-repo) the cloudwego {project_name} repo.
4. In your forked repository, make your changes in a new git branch:
```
git checkout -b my-fix-branch develop
Expand All @@ -38,18 +38,14 @@ Before you submit your Pull Request (PR) consider the following guidelines:
```
git push origin my-fix-branch
```
9. In GitHub, send a pull request to `kitex:develop`
9. In GitHub, send a pull request to `{project_name}:develop`

## Contribution Prerequisites
- Our development environment keeps up with [Go Official](https://golang.org/project/).
- You need fully checking with lint tools before submit your pull request. [gofmt](https://golang.org/pkg/cmd/gofmt/) and [golangci-lint](https://github.com/golangci/golangci-lint)
- You are familiar with [Github](https://github.com)
- You are familiar with [GitHub](https://github.com)
- Maybe you need familiar with [Actions](https://github.com/features/actions)(our default workflow tool).

## Code Style Guides
Also see [Pingcap General advice](https://pingcap.github.io/style-guide/general.html).

Good resources:
- [Effective Go](https://golang.org/doc/effective_go)
- [Go Code Review Comments](https://github.com/golang/go/wiki/CodeReviewComments)
- [Uber Go Style Guide](https://github.com/uber-go/guide/blob/master/style.md)
95 changes: 95 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
module github.com/cloudwego-contrib/cwgo-pkg

go 1.21

require (
github.com/apache/thrift v0.16.0 // indirect
github.com/bytedance/gopkg v0.0.0-20230728082804-614d0af6619b
github.com/cloudwego/kitex v0.9.1
github.com/stretchr/testify v1.9.0
go.opentelemetry.io/contrib/instrumentation/runtime v0.45.0
go.opentelemetry.io/contrib/propagators/b3 v1.20.0
go.opentelemetry.io/contrib/propagators/ot v1.20.0
go.opentelemetry.io/otel v1.28.0
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v0.42.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.19.0
go.opentelemetry.io/otel/metric v1.28.0
go.opentelemetry.io/otel/sdk v1.28.0
go.opentelemetry.io/otel/sdk/metric v1.28.0
go.opentelemetry.io/otel/trace v1.28.0
)

require (
github.com/cloudwego/hertz v0.9.2
github.com/prometheus/client_golang v1.19.1
go.opentelemetry.io/otel/exporters/prometheus v0.50.0
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.28.0
gorm.io/gorm v1.25.11
gorm.io/plugin/opentelemetry v0.1.4
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/bytedance/go-tagexpr/v2 v2.9.2 // indirect
github.com/bytedance/sonic v1.11.2 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
github.com/chenzhuoyu/iasm v0.9.1 // indirect
github.com/choleraehyq/pid v0.0.18 // indirect
github.com/cloudwego/configmanager v0.2.0 // indirect
github.com/cloudwego/dynamicgo v0.2.0 // indirect
github.com/cloudwego/fastpb v0.0.4 // indirect
github.com/cloudwego/frugal v0.1.14 // indirect
github.com/cloudwego/localsession v0.0.2 // indirect
github.com/cloudwego/netpoll v0.6.0 // indirect
github.com/cloudwego/thriftgo v0.3.6 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/fatih/structtag v1.2.0 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/pprof v0.0.0-20230509042627-b1315fad0c5a // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0 // indirect
github.com/henrylee2cn/ameda v1.4.10 // indirect
github.com/henrylee2cn/goutil v0.0.0-20210127050712-89660552f6f8 // indirect
github.com/iancoleman/strcase v0.2.0 // indirect
github.com/jhump/protoreflect v1.8.2 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/gls v0.0.0-20220109145502-612d0167dce5 // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/nyaruka/phonenumbers v1.0.55 // indirect
github.com/oleiade/lane v1.0.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/tidwall/gjson v1.14.4 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric v0.42.0 // indirect
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/arch v0.2.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
google.golang.org/genproto v0.0.0-20231012201019-e917dd12ba7a // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231016165738-49dd2c1f3d0b // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b // indirect
google.golang.org/grpc v1.59.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/apache/thrift => github.com/apache/thrift v0.13.0
12 changes: 12 additions & 0 deletions go.work
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
go 1.21

use (
.
./log/logging/logrus
./log/logging/slog
./log/logging/zap
./log/logging/zerolog

)

replace github.com/apache/thrift => github.com/apache/thrift v0.13.0
50 changes: 50 additions & 0 deletions instrumentation/hertzobs/events.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2022 CloudWeGo 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 hertzobs

import (
"github.com/cloudwego/hertz/pkg/common/tracer/stats"
"github.com/cloudwego/hertz/pkg/common/tracer/traceinfo"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
)

var commonEvents = map[string]stats.Event{
"http_start": stats.HTTPStart,
"http_finish": stats.HTTPFinish,
"server_handle_start": stats.ServerHandleStart,
"server_handle_finish": stats.ServerHandleFinish,
"read_header_start": stats.ReadHeaderStart,
"read_header_finish": stats.ReadHeaderFinish,
"read_body_start": stats.ReadBodyStart,
"read_body_finish": stats.ReadBodyFinish,
"write_start": stats.WriteStart,
"write_finish": stats.WriteFinish,
}

func injectStatsEventsToSpan(span trace.Span, st traceinfo.HTTPStats) {
for name, event := range commonEvents {
if gotEvent := st.GetEvent(event); gotEvent != nil {
attrs := []attribute.KeyValue{attribute.Int("event.status", int(gotEvent.Status()))}
if gotEvent.Info() != "" {
attrs = append(attrs, attribute.String("event.info", gotEvent.Info()))
}
span.AddEvent(name,
trace.WithTimestamp(gotEvent.Time()),
trace.WithAttributes(attrs...),
)
}
}
}
70 changes: 70 additions & 0 deletions instrumentation/hertzobs/example_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright 2022 CloudWeGo 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 hertzobs

import (
"context"
"github.com/cloudwego-contrib/cwgo-pkg/instrumentation/hertzobs/oteltracer"
"github.com/cloudwego-contrib/cwgo-pkg/instrumentation/hertzobs/testutil"
"github.com/cloudwego/hertz/pkg/app"
"github.com/cloudwego/hertz/pkg/app/client"
"github.com/cloudwego/hertz/pkg/app/server"
"github.com/cloudwego/hertz/pkg/common/hlog"
"github.com/cloudwego/hertz/pkg/protocol/consts"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/otel"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
"testing"
"time"
)

func TestMetricsExample(t *testing.T) {
// test util
tracerProvider, meterProvider, registry := testutil.OtelTestProvider()
defer func(tracerProvider *sdktrace.TracerProvider, ctx context.Context) {
_ = tracerProvider.Shutdown(ctx)
}(tracerProvider, context.Background())
otel.SetMeterProvider(meterProvider)

// server example
tracer, cfg := oteltracer.NewServerTracer()
h := server.Default(tracer, server.WithHostPorts(":39888"))
h.Use(ServerMiddleware(cfg))
h.GET("/ping", func(c context.Context, ctx *app.RequestContext) {
hlog.CtxDebugf(c, "message received successfully")
ctx.JSON(consts.StatusOK, "pong")
})
go h.Spin()

<-time.After(time.Millisecond * 500)

// client example
c, _ := client.NewClient()
c.Use(ClientMiddleware())
_, body, err := c.Get(context.Background(), nil, "http://localhost:39888/ping?foo=bar")
require.NoError(t, err)
assert.NotNil(t, body)

// test client returns error
_, _, err = c.Get(context.Background(), nil, "http://localhost:39887/ping?foo=bar")
assert.NotNil(t, err)

// diff meter
assert.NoError(t, testutil.GatherAndCompare(
registry, "testdata/hertz_request_metrics.txt",
"http_server_request_count_total", "http_client_request_count_total"),
)
}
Loading
Loading