From 3863b97447124ea8533b09edea7c19f67c0330aa Mon Sep 17 00:00:00 2001 From: Gianluca Arbezzano Date: Thu, 2 Jan 2020 15:51:16 +0100 Subject: [PATCH] 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 --- pkg/cmd/capture.go | 9 +++++++-- pkg/cmd/kprofefe.go | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/pkg/cmd/capture.go b/pkg/cmd/capture.go index a142836..e327ab3 100644 --- a/pkg/cmd/capture.go +++ b/pkg/cmd/capture.go @@ -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, @@ -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 { diff --git a/pkg/cmd/kprofefe.go b/pkg/cmd/kprofefe.go index 46e204c..239c874 100644 --- a/pkg/cmd/kprofefe.go +++ b/pkg/cmd/kprofefe.go @@ -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, @@ -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 {