Skip to content

Commit

Permalink
feat: Added profefe.com/service annotation
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Gianluca Arbezzano committed Jan 2, 2020
1 parent 11475be commit 3863b97
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
9 changes: 7 additions & 2 deletions pkg/cmd/capture.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func writeProfiles(ctx context.Context, pClient *profefe.Client, profiles map[pp
// if the profefe client is not null the profile needs to be pushed to
// profefe server, otherwise it is written into a file locally
if pClient != nil {
saved, err := pClient.SavePprof(ctx, profefe.SavePprofRequest{
req := profefe.SavePprofRequest{
Profile: profile,
Service: target.Name,
InstanceID: target.Status.HostIP,
Expand All @@ -186,7 +186,12 @@ func writeProfiles(ctx context.Context, pClient *profefe.Client, profiles map[pp
"namespace": target.Namespace,
"from": "kube-profefe",
},
})
}
if serviceName, ok := target.Annotations["profefe.com/service"]; ok && serviceName != "" {
req.Service = serviceName
req.Labels["pod"] = target.Name
}
saved, err := pClient.SavePprof(context.Background(), req)
if err != nil {
println(fmt.Sprintf("%s type=%s profile_type=%s", err.Error(), profefeType, profile.PeriodType.Type))
} else {
Expand Down
9 changes: 7 additions & 2 deletions pkg/cmd/kprofefe.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func do(ctx context.Context, l *zap.Logger, pClient *profefe.Client, target core
logger.Warn("Unknown profile type it can not be sent to profefe. Skip this profile")
continue
}
saved, err := pClient.SavePprof(context.Background(), profefe.SavePprofRequest{
req := profefe.SavePprofRequest{
Profile: profile,
Service: target.Name,
InstanceID: target.Status.HostIP,
Expand All @@ -172,7 +172,12 @@ func do(ctx context.Context, l *zap.Logger, pClient *profefe.Client, target core
"namespace": target.Namespace,
"from": "kube-profefe",
},
})
}
if serviceName, ok := target.Annotations["profefe.com/service"]; ok && serviceName != "" {
req.Service = serviceName
req.Labels["pod"] = target.Name
}
saved, err := pClient.SavePprof(context.Background(), req)
if err != nil {
logger.Warn("Unknown profile type it can not be sent to profefe. Skip this profile", zap.Error(err))
} else {
Expand Down

0 comments on commit 3863b97

Please sign in to comment.