Skip to content

Commit 6504311

Browse files
metrics: support pyroscope for continous profile (#8958)
close #8957 Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
1 parent a5c1101 commit 6504311

File tree

8 files changed

+47
-0
lines changed

8 files changed

+47
-0
lines changed

cmd/pd-server/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ func start(cmd *cobra.Command, args []string, services ...string) {
227227
grpcprometheus.EnableHandlingTimeHistogram()
228228

229229
metricutil.Push(&cfg.Metric)
230+
metricutil.EnablePyroscope()
230231

231232
err = join.PrepareJoinCluster(cfg)
232233
if err != nil {

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ require (
2727
github.com/gogo/protobuf v1.3.2
2828
github.com/google/btree v1.1.2
2929
github.com/gorilla/mux v1.7.4
30+
github.com/grafana/pyroscope-go v1.2.0
3031
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
3132
github.com/joho/godotenv v1.4.0
3233
github.com/mailru/easyjson v0.7.6
@@ -126,6 +127,7 @@ require (
126127
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
127128
github.com/google/uuid v1.6.0 // indirect
128129
github.com/gorilla/websocket v1.5.1 // indirect
130+
github.com/grafana/pyroscope-go/godeltaprof v0.1.8 // indirect
129131
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
130132
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
131133
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,10 @@ github.com/gorilla/mux v1.7.4/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB7
245245
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
246246
github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY=
247247
github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY=
248+
github.com/grafana/pyroscope-go v1.2.0 h1:aILLKjTj8CS8f/24OPMGPewQSYlhmdQMBmol1d3KGj8=
249+
github.com/grafana/pyroscope-go v1.2.0/go.mod h1:2GHr28Nr05bg2pElS+dDsc98f3JTUh2f6Fz1hWXrqwk=
250+
github.com/grafana/pyroscope-go/godeltaprof v0.1.8 h1:iwOtYXeeVSAeYefJNaxDytgjKtUuKQbJqgAIjlnicKg=
251+
github.com/grafana/pyroscope-go/godeltaprof v0.1.8/go.mod h1:2+l7K7twW49Ct4wFluZD3tZ6e0SjanjcUUBPVD/UuGU=
248252
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 h1:UH//fgunKIs4JdUbpDl1VZCDaL56wXCB/5+wF6uHfaI=
249253
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0/go.mod h1:g5qyo/la0ALbONm6Vbp88Yd8NsDy6rZz+RcrMPxvld8=
250254
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92BcuyuQ/YW4NSIpoGtfXNho=

pkg/utils/metricutil/metricutil.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@ package metricutil
1616

1717
import (
1818
"os"
19+
"runtime"
1920
"time"
2021
"unicode"
2122

23+
"github.com/grafana/pyroscope-go"
2224
"github.com/prometheus/client_golang/prometheus"
2325
"github.com/prometheus/client_golang/prometheus/push"
26+
"go.uber.org/zap"
2427

2528
"github.com/pingcap/log"
2629

@@ -102,3 +105,28 @@ func instanceName() string {
102105
}
103106
return hostname
104107
}
108+
109+
// EnablePyroscope enables pyroscope if pyroscope is enabled.
110+
func EnablePyroscope() {
111+
if os.Getenv("PYROSCOPE_SERVER_ADDRESS") != "" {
112+
runtime.SetMutexProfileFraction(5)
113+
runtime.SetBlockProfileRate(5)
114+
_, err := pyroscope.Start(pyroscope.Config{
115+
ApplicationName: "pd",
116+
ServerAddress: os.Getenv("PYROSCOPE_SERVER_ADDRESS"),
117+
Logger: pyroscope.StandardLogger,
118+
AuthToken: os.Getenv("PYROSCOPE_AUTH_TOKEN"),
119+
TenantID: os.Getenv("PYROSCOPE_TENANT_ID"),
120+
BasicAuthUser: os.Getenv("PYROSCOPE_BASIC_AUTH_USER"),
121+
BasicAuthPassword: os.Getenv("PYROSCOPE_BASIC_AUTH_PASSWORD"),
122+
ProfileTypes: []pyroscope.ProfileType{
123+
pyroscope.ProfileCPU,
124+
pyroscope.ProfileAllocSpace,
125+
},
126+
UploadRate: 30 * time.Second,
127+
})
128+
if err != nil {
129+
log.Fatal("fail to start pyroscope", zap.Error(err))
130+
}
131+
}
132+
}

tests/integrations/go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ require (
101101
github.com/google/uuid v1.6.0 // indirect
102102
github.com/gorilla/mux v1.7.4 // indirect
103103
github.com/gorilla/websocket v1.5.1 // indirect
104+
github.com/grafana/pyroscope-go v1.2.0 // indirect
105+
github.com/grafana/pyroscope-go/godeltaprof v0.1.8 // indirect
104106
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
105107
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
106108
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect

tests/integrations/go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,10 @@ github.com/gorilla/mux v1.7.4/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB7
237237
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
238238
github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY=
239239
github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY=
240+
github.com/grafana/pyroscope-go v1.2.0 h1:aILLKjTj8CS8f/24OPMGPewQSYlhmdQMBmol1d3KGj8=
241+
github.com/grafana/pyroscope-go v1.2.0/go.mod h1:2GHr28Nr05bg2pElS+dDsc98f3JTUh2f6Fz1hWXrqwk=
242+
github.com/grafana/pyroscope-go/godeltaprof v0.1.8 h1:iwOtYXeeVSAeYefJNaxDytgjKtUuKQbJqgAIjlnicKg=
243+
github.com/grafana/pyroscope-go/godeltaprof v0.1.8/go.mod h1:2+l7K7twW49Ct4wFluZD3tZ6e0SjanjcUUBPVD/UuGU=
240244
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 h1:UH//fgunKIs4JdUbpDl1VZCDaL56wXCB/5+wF6uHfaI=
241245
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0/go.mod h1:g5qyo/la0ALbONm6Vbp88Yd8NsDy6rZz+RcrMPxvld8=
242246
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92BcuyuQ/YW4NSIpoGtfXNho=

tools/go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ require (
106106
github.com/google/uuid v1.6.0 // indirect
107107
github.com/gorilla/mux v1.7.4 // indirect
108108
github.com/gorilla/websocket v1.5.1 // indirect
109+
github.com/grafana/pyroscope-go v1.2.0 // indirect
110+
github.com/grafana/pyroscope-go/godeltaprof v0.1.8 // indirect
109111
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
110112
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
111113
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect

tools/go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,10 @@ github.com/gorilla/mux v1.7.4/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB7
236236
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
237237
github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY=
238238
github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY=
239+
github.com/grafana/pyroscope-go v1.2.0 h1:aILLKjTj8CS8f/24OPMGPewQSYlhmdQMBmol1d3KGj8=
240+
github.com/grafana/pyroscope-go v1.2.0/go.mod h1:2GHr28Nr05bg2pElS+dDsc98f3JTUh2f6Fz1hWXrqwk=
241+
github.com/grafana/pyroscope-go/godeltaprof v0.1.8 h1:iwOtYXeeVSAeYefJNaxDytgjKtUuKQbJqgAIjlnicKg=
242+
github.com/grafana/pyroscope-go/godeltaprof v0.1.8/go.mod h1:2+l7K7twW49Ct4wFluZD3tZ6e0SjanjcUUBPVD/UuGU=
239243
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 h1:UH//fgunKIs4JdUbpDl1VZCDaL56wXCB/5+wF6uHfaI=
240244
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0/go.mod h1:g5qyo/la0ALbONm6Vbp88Yd8NsDy6rZz+RcrMPxvld8=
241245
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92BcuyuQ/YW4NSIpoGtfXNho=

0 commit comments

Comments
 (0)