Skip to content

Commit 3863b97

Browse files
author
Gianluca Arbezzano
committed
feat: Added profefe.com/service annotation
Fixes #19 By default the service name is the pod name. As consequence you have to know it when querying from profefe. It is not always easy to achieve because pod name changes frequently. When specified the annotation `profefe.com/service` override the pod name as service name. Signed-off-by: Gianluca Arbezzano <gianarb92@gmail.com>
1 parent 11475be commit 3863b97

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

pkg/cmd/capture.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ func writeProfiles(ctx context.Context, pClient *profefe.Client, profiles map[pp
177177
// if the profefe client is not null the profile needs to be pushed to
178178
// profefe server, otherwise it is written into a file locally
179179
if pClient != nil {
180-
saved, err := pClient.SavePprof(ctx, profefe.SavePprofRequest{
180+
req := profefe.SavePprofRequest{
181181
Profile: profile,
182182
Service: target.Name,
183183
InstanceID: target.Status.HostIP,
@@ -186,7 +186,12 @@ func writeProfiles(ctx context.Context, pClient *profefe.Client, profiles map[pp
186186
"namespace": target.Namespace,
187187
"from": "kube-profefe",
188188
},
189-
})
189+
}
190+
if serviceName, ok := target.Annotations["profefe.com/service"]; ok && serviceName != "" {
191+
req.Service = serviceName
192+
req.Labels["pod"] = target.Name
193+
}
194+
saved, err := pClient.SavePprof(context.Background(), req)
190195
if err != nil {
191196
println(fmt.Sprintf("%s type=%s profile_type=%s", err.Error(), profefeType, profile.PeriodType.Type))
192197
} else {

pkg/cmd/kprofefe.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ func do(ctx context.Context, l *zap.Logger, pClient *profefe.Client, target core
163163
logger.Warn("Unknown profile type it can not be sent to profefe. Skip this profile")
164164
continue
165165
}
166-
saved, err := pClient.SavePprof(context.Background(), profefe.SavePprofRequest{
166+
req := profefe.SavePprofRequest{
167167
Profile: profile,
168168
Service: target.Name,
169169
InstanceID: target.Status.HostIP,
@@ -172,7 +172,12 @@ func do(ctx context.Context, l *zap.Logger, pClient *profefe.Client, target core
172172
"namespace": target.Namespace,
173173
"from": "kube-profefe",
174174
},
175-
})
175+
}
176+
if serviceName, ok := target.Annotations["profefe.com/service"]; ok && serviceName != "" {
177+
req.Service = serviceName
178+
req.Labels["pod"] = target.Name
179+
}
180+
saved, err := pClient.SavePprof(context.Background(), req)
176181
if err != nil {
177182
logger.Warn("Unknown profile type it can not be sent to profefe. Skip this profile", zap.Error(err))
178183
} else {

0 commit comments

Comments
 (0)