-
Notifications
You must be signed in to change notification settings - Fork 107
feat(add trace profile for go agent) #229
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
Merged
Merged
Changes from all commits
Commits
Show all changes
124 commits
Select commit
Hold shift + click to select a range
fcc3bca
feat(add profilefetchinterval)
cqhasy 34c055f
feat(add fetchhandle,print task success)
cqhasy 9178edd
fix(mod)
cqhasy 0b7ddd6
feat(try get trace id in middleware and add profilemanager)
cqhasy 48cbdaf
feat(add profile manager into repoter)
cqhasy c0d41c3
feat(add toProfile)
cqhasy f227ebb
feat(add profiling success and chunc splice,plan to report)
cqhasy ac8175a
fix(add some profile tools)
cqhasy 1d56153
fix(pretend report,add end profile when trace end )
cqhasy 325ec79
feat(try to add spanId label)
cqhasy e60dc3a
fix(add span label success)
cqhasy efaefe9
fix(before devide routinue)
cqhasy 25e219e
fix(change ctx,delete stop span,enable routinues profile)
cqhasy 6c43a54
fix(add currentTask struct)
cqhasy de4b252
fix(Translate the comments from Chinese into English,test final with …
cqhasy 5568022
Merge branch 'main' into main
mrproliu 85f6f20
fix(move the task cache to report)
cqhasy 6e095d0
fix(devide no related method from repoter)
cqhasy 8a2d862
Devide no related method from repoter Merge branch 'main' of github.c…
cqhasy 2534de1
fix(solve the memory buffer to weight problem)
cqhasy 9579f9f
feat(add owen add profile labels logic)
cqhasy 8eabad6
fix(change profile test name,use to profile.go)
cqhasy 4d0538d
change profile location
cqhasy ee2e86b
feat(add profile invoke logic)
cqhasy 6492822
feat(update plugins/go.mod goapi to latest)
cqhasy aa8e811
fix(add license headers to core and pprof plugins)
cqhasy 98c6867
fix (change go.work version)
cqhasy ce99dd7
fix(add NewProfileManager for test_base)
cqhasy a87b28b
chore(change grpc version from 1.73 to 1.55,delete slices,use sort)
cqhasy 8f6739c
fix(keep the go.mod go.work original format)
cqhasy 7447e53
fix(delete duplicated method in pprof_labels)
cqhasy 1cc674a
feat(add log for profileManager)
cqhasy 90ec5cb
fix(Separate profiling from specific traces)
cqhasy e4c9e6b
feat(add data collect proto in go agent)
cqhasy a6952b6
Lock skywalking-data-collect-protocol to specific version
cqhasy 151cadd
fix(change pull-proto.sh to adapt git submodule)
cqhasy 4e1e9aa
feat(add generate-proto in workflows)
cqhasy 595a35b
fix (remove git submodule update in pull-proto.sh)
cqhasy d317ecf
feat(add license in file and check if install protoc in make proto)
cqhasy 14eade2
fix(solve tar protoc no power in CI)
cqhasy 1645ab7
fix(lower protoc-gen-go-grpc version in CI,fix expoter for protoc)
cqhasy 95219ac
fix(keep pull-proto.sh protoc path same with user download)
cqhasy f111ad4
feat(ignore tools/protocols/temp)
cqhasy 2ca045c
fix(add goPROXY,add unzip process info)
cqhasy f9c18e5
fix(lower /protoc-gen-go-grpc /protoc-gen-go version, install dos2uni…
cqhasy 2f1a379
fix(back golang.org/x/net, add go version in pull-proto)
cqhasy 4ccf44f
fix(ignore protocols license,lower go mod to adapt go 1.19)
cqhasy 2efd447
fix(ignore proto license,add make proto for test,extend wait time )
cqhasy 2a0ae41
fix(change protocol import path to access lint,add some log info in h…
cqhasy 301beb8
fix(adapt to lint,add GOPONXY in kafka E2E,extend sleep time in wsl-s…
cqhasy 3e11a49
fix(force e2e test use 1.19,add generate proto in build)
cqhasy 111f712
fix(change infra-e2e version,devide zip install in windows and linux)
cqhasy 8f25978
fix(change infra-e2e)
cqhasy 8fe61bf
fix(advance install docker)
cqhasy dac5c6c
fix(add env /bin/bash)
cqhasy 4942066
fix(add PATH user/bin)
cqhasy bc6a8a5
fix(add go-version)
cqhasy 062c4f8
fix(force go-version)
cqhasy d6486ab
roll back
cqhasy 0ff9580
use 1.24 to adapt apache/skywalking-infra-e2e
cqhasy 64f08f0
fix(fix e2e.yaml)
cqhasy 865b4c1
role back to pull request
cqhasy f6725df
fix(merge dev2 and dev3)
cqhasy 6d6bbc3
fix(add some DNS log for wsl-scenarios)
cqhasy 1b5839e
fix(change HTTP_HOST from service to 127.0.0.1)
cqhasy 2bbb8d6
fix(delete Chinese notes in pull-proto.sh)
cqhasy f32a8d5
fix(role back)
cqhasy 3f1100a
fix(try print container status)
cqhasy 26047d2
fix(try print container status)
cqhasy b9f4146
fix(try print container status)
cqhasy e6b4628
fix(try print container status)
cqhasy 3818324
fix(try print container status)
cqhasy 2625ba0
fix(try print container status)
cqhasy d90f993
role back action on
cqhasy a4ce676
chang windows host
cqhasy d190906
role back windows host
cqhasy 61a7727
select could use windows host
cqhasy ab84e58
add more log info,extend curl time
cqhasy abcf0d2
roll workflows on
cqhasy 3cfa652
test
cqhasy 7a3c2aa
add resolv info
cqhasy 6f8fc85
roll workflows on
cqhasy 8deff0d
dont use resolv.conf
cqhasy 8983f85
fix(add full log when get ip in windows)
cqhasy a849a09
roll back workflows on
cqhasy 35035fa
delete generate proto in e2e
cqhasy 4c9ec42
fix(delete generate proto in CI)
cqhasy 941a29d
fix(rename pull-proto.sh,delete no use shell in pull-proto.sh,add cha…
cqhasy 328a144
fix(mov changes from doc to feature,delete some common)
cqhasy d697977
fix(delete make generate proto in publish docker)
cqhasy 5595008
feat(add delete temp in generate.sh)
cqhasy eee3bfe
before merge dev2
cqhasy 03196b5
after merge
cqhasy c337161
fix(remove runtime/pprof.runtime_getProfLabel to avoid version error)
cqhasy ec7f548
fix(fix lint error)
cqhasy c94385a
feat(add no getProfileTask RPC err log)
cqhasy 075831a
fix(fix zap log order error)
cqhasy dd21590
feat(add GetProfileTask grpc err in logrus)
cqhasy 78834f6
fix(fix excepted.yml)
cqhasy 12b283e
test
cqhasy ab908d9
test
cqhasy 45f276b
test
cqhasy b441ce3
fix(update skywalking-agent-test-tool)
cqhasy e9d4c25
roll back ci
cqhasy 12626e8
Merge branch 'main' into main
cqhasy 45fab22
fix(delete unnecessary newline,fix command.pd taskID to taskId,Adjust…
cqhasy c2b9f1a
fix(enable setting labels for goroutines, optimize label storage, and…
cqhasy b6be276
test(test ci)
cqhasy a470a19
fix(add license in share.go)
cqhasy f7b89fe
fix(roll back)
cqhasy d59ab2e
fix(change TraceProfileTask to impl,delete the no using instrument)
cqhasy c73a289
test ci
cqhasy ea9a467
fix ci
cqhasy c2f646e
before merge origin
cqhasy 91c5a33
merge(merge the go trace profile func)
cqhasy 6af1c4c
fix(ci log error)
cqhasy efd26aa
roll back ci
cqhasy 9bf7a23
fix(use regexp not string to compare version,use own set function not…
cqhasy 67252e5
fix(delete no use counter,rename event manager,fix ci)
cqhasy 0470716
feat(add pprof plugins test)
cqhasy 09ddf95
fix(replace kafka docker image to bitnamilegacy)
cqhasy 76a7f4a
fix(fix lint error)
cqhasy 633e15c
roll back ci
cqhasy bb371a8
fix(use profile task quece not singleton,use timefunc to start profile)
cqhasy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| // Licensed to 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. Apache Software Foundation (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 profile | ||
|
|
||
| import ( | ||
| //go:nolint | ||
| _ "bytes" | ||
| _ "context" | ||
| _ "fmt" | ||
| _ "runtime/pprof" | ||
| _ "strconv" | ||
| _ "strings" | ||
| _ "sync" | ||
| _ "sync/atomic" | ||
| _ "time" | ||
| _ "unsafe" | ||
|
|
||
| //go:nolint | ||
| _ "github.com/pkg/errors" | ||
|
|
||
| //go:nolint | ||
| _ "github.com/apache/skywalking-go/agent/core/operator" | ||
|
|
||
| //go:nolint | ||
| _ "github.com/apache/skywalking-go/agent/reporter" | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. | ||
|
|
||
| package operator | ||
|
|
||
| type ProfileOperator interface { | ||
| // GetNowLabels get skywalking internal labels from goroutine,avoid covered by user | ||
| GetNowLabels() interface{} | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,221 @@ | ||
| // 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 core | ||
|
|
||
| import ( | ||
| "context" | ||
| "regexp" | ||
| "runtime" | ||
| "runtime/pprof" | ||
| "sort" | ||
| "strconv" | ||
| "unsafe" | ||
| ) | ||
|
|
||
| type label struct { | ||
| key string | ||
| value string | ||
| } | ||
|
|
||
| type LabelSet struct { | ||
| list []label | ||
| } | ||
|
|
||
| type labelMap struct { | ||
| LabelSet | ||
| } | ||
|
|
||
| type labelMap19 map[string]string | ||
|
|
||
| type labelContextKey struct{} | ||
|
|
||
| //go:linkname runtimeGetProfLabel runtime/pprof.runtime_getProfLabel | ||
| func runtimeGetProfLabel() unsafe.Pointer | ||
|
|
||
| //go:linkname runtimeSetProfLabel runtime/pprof.runtime_setProfLabel | ||
| func runtimeSetProfLabel(label unsafe.Pointer) | ||
|
|
||
| func setGoroutineLabelsInternal(ctx context.Context) { | ||
| if isGoVersionLMoreThan120(runtime.Version()) { | ||
| ctxLabels, _ := ctx.Value(labelContextKey{}).(*labelMap) | ||
| runtimeSetProfLabel(unsafe.Pointer(ctxLabels)) | ||
| return | ||
| } | ||
| ctxLabels, _ := ctx.Value(labelContextKey{}).(*labelMap19) | ||
| runtimeSetProfLabel(unsafe.Pointer(ctxLabels)) | ||
| } | ||
|
|
||
| func labelValue(ctx context.Context) labelMap19 { | ||
| labels, _ := ctx.Value(labelContextKey{}).(*labelMap19) | ||
| if labels == nil { | ||
| return labelMap19(nil) | ||
| } | ||
| return *labels | ||
| } | ||
|
|
||
| func WithLabels(ctx context.Context, s LabelSet) context.Context { | ||
| if isGoVersionLMoreThan120(runtime.Version()) { | ||
| ctx = context.WithValue(ctx, labelContextKey{}, &labelMap{s}) | ||
| return ctx | ||
| } | ||
| return withLabels19(ctx, s) | ||
| } | ||
|
|
||
| func withLabels19(ctx context.Context, labels LabelSet) context.Context { | ||
| childLabels := make(labelMap19) | ||
| parentLabels := labelValue(ctx) | ||
| for k, v := range parentLabels { | ||
| childLabels[k] = v | ||
| } | ||
| for _, label := range labels.list { | ||
| childLabels[label.key] = label.value | ||
| } | ||
| return context.WithValue(ctx, labelContextKey{}, &childLabels) | ||
| } | ||
|
|
||
| func GetNowLabelSet() LabelSet { | ||
| pl := LabelSet{ | ||
| list: make([]label, 0), | ||
| } | ||
| p := runtimeGetProfLabel() | ||
| if p != nil { | ||
| version := runtime.Version() | ||
| if !isGoVersionLMoreThan120(version) { | ||
| // Go1.19:map[string]string -> []label | ||
| m := *(*labelMap19)(p) | ||
| pl.list = make([]label, 0, len(m)) | ||
| for k, v := range m { | ||
| pl.list = append(pl.list, label{key: k, value: v}) | ||
| } | ||
| } else { | ||
| lm := (*labelMap)(p) | ||
| pl.list = lm.list | ||
| } | ||
| } | ||
| return pl | ||
| } | ||
|
|
||
| // isGoVersionLMoreThan120 parses version strings like "go1.19.8" | ||
| func isGoVersionLMoreThan120(version string) bool { | ||
| re := regexp.MustCompile(`go(\d+)\.(\d+)`) | ||
| sub := re.FindStringSubmatch(version) | ||
| if len(sub) != 3 { | ||
| return false | ||
| } | ||
| major, err1 := strconv.Atoi(sub[1]) | ||
| minor, err2 := strconv.Atoi(sub[2]) | ||
| if err1 != nil || err2 != nil { | ||
| return false | ||
| } | ||
| if major < 1 { | ||
| return false | ||
| } | ||
| if major > 1 { | ||
| return true | ||
| } | ||
| return minor >= 20 | ||
| } | ||
|
|
||
| func (m *ProfileManager) AddSkyLabels(traceID, segmentID string, spanID int32) interface{} { | ||
| pl := GetNowLabelSet() | ||
| re := UpdateTraceLabels(pl, TraceLabel, traceID, SegmentLabel, segmentID, SpanLabel, parseString(spanID)) | ||
| return &re | ||
| } | ||
|
|
||
| func (m *ProfileManager) TurnToPprofLabel(l *LabelSet) pprof.LabelSet { | ||
| li := l.List() | ||
| if len(li) == 0 { | ||
| return pprof.LabelSet{} | ||
| } | ||
| re := pprof.Labels(li...) | ||
| return re | ||
| } | ||
|
|
||
| func UpdateTraceLabels(s LabelSet, args ...string) LabelSet { | ||
| if len(args)%2 != 0 { | ||
| panic("uneven number of arguments to profile.UpdateTraceLabels") | ||
| } | ||
|
|
||
| // add first | ||
| for i := 0; i < len(args); i += 2 { | ||
| s.list = append(s.list, label{key: args[i], value: args[i+1]}) | ||
| } | ||
|
|
||
| // sort | ||
| sort.SliceStable(s.list, func(i, j int) bool { | ||
| return s.list[i].key < s.list[j].key | ||
| }) | ||
|
|
||
| // remove duplicates | ||
| deduped := make([]label, 0, len(s.list)) | ||
| for i, lbl := range s.list { | ||
| if i == 0 || lbl.key != s.list[i-1].key { | ||
| deduped = append(deduped, lbl) | ||
| } else { | ||
| deduped[len(deduped)-1] = lbl | ||
| } | ||
| } | ||
| s.list = deduped | ||
|
|
||
| return s | ||
| } | ||
|
|
||
| func (s *LabelSet) List() []string { | ||
| var ret []string | ||
| for _, v := range s.list { | ||
| ret = append(ret, v.key, v.value) | ||
| } | ||
| return ret | ||
| } | ||
|
|
||
| func SetGoroutineLabels(s *LabelSet) { | ||
| if s.IsEmpty() { | ||
| var c = context.Background() | ||
| setGoroutineLabelsInternal(c) | ||
| return | ||
| } | ||
| var c = context.Background() | ||
| l := *s | ||
| c = WithLabels(c, l) | ||
| setGoroutineLabelsInternal(c) | ||
| } | ||
|
|
||
| func extractSkyInternalLabels(s LabelSet) LabelSet { | ||
| re := LabelSet{list: make([]label, 0)} | ||
| for _, l := range s.list { | ||
| if l.key == SpanLabel || l.key == SegmentLabel || l.key == TraceLabel || l.key == MinDurationLabel { | ||
| re.list = append(re.list, l) | ||
| } | ||
| } | ||
| return re | ||
| } | ||
|
|
||
| // GetNowLabels Expose to operator | ||
| func (m *ProfileManager) GetNowLabels() interface{} { | ||
| row := GetNowLabelSet() | ||
| filter := extractSkyInternalLabels(row) | ||
| re := m.TurnToPprofLabel(&filter) | ||
| return re | ||
| } | ||
|
|
||
| func (s *LabelSet) IsEmpty() bool { | ||
| if s == nil || s.list == nil { | ||
| return true | ||
| } | ||
| return len(s.list) == 0 | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.