-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(scheduler): Add tracing support (#129)
- Loading branch information
Showing
6 changed files
with
145 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,25 @@ | ||
package tracing | ||
|
||
import "fmt" | ||
|
||
// KeptnCarrier carries the TraceContext | ||
type KeptnCarrier map[string]interface{} | ||
|
||
// Get returns the value associated with the passed key. | ||
func (kc KeptnCarrier) Get(key string) string { | ||
return fmt.Sprintf("%v", kc[key]) | ||
} | ||
|
||
// Set stores the key-value pair. | ||
func (kc KeptnCarrier) Set(key string, value string) { | ||
kc[key] = value | ||
} | ||
|
||
// Keys lists the keys stored in this carrier. | ||
func (kc KeptnCarrier) Keys() []string { | ||
keys := make([]string, 0, len(kc)) | ||
for k := range kc { | ||
keys = append(keys, k) | ||
} | ||
return keys | ||
} |
This file contains 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 @@ | ||
package tracing | ||
|
||
import ( | ||
"context" | ||
"go.opentelemetry.io/otel" | ||
"go.opentelemetry.io/otel/attribute" | ||
"go.opentelemetry.io/otel/trace" | ||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
) | ||
|
||
const ( | ||
ApplicationName attribute.Key = attribute.Key("keptn.deployment.app_name") | ||
Workload attribute.Key = attribute.Key("keptn.deployment.workload") | ||
Version attribute.Key = attribute.Key("keptn.deployment.version") | ||
Namespace attribute.Key = attribute.Key("keptn.deployment.namespace") | ||
Status attribute.Key = attribute.Key("keptn.deployment.status") | ||
) | ||
|
||
func CreateSpan(ctx context.Context, crd *unstructured.Unstructured, t trace.Tracer, ns string) (context.Context, trace.Span) { | ||
// search for annotations | ||
annotations, found, _ := unstructured.NestedMap(crd.UnstructuredContent(), "metadata", "annotations") | ||
if found { | ||
ctx = otel.GetTextMapPropagator().Extract(ctx, KeptnCarrier(annotations)) | ||
} | ||
ctx, span := t.Start(ctx, "schedule") | ||
|
||
appName, found, _ := unstructured.NestedString(crd.UnstructuredContent(), "spec", "app") | ||
if found { | ||
span.SetAttributes(ApplicationName.String(appName)) | ||
} | ||
workload, found, _ := unstructured.NestedString(crd.UnstructuredContent(), "spec", "workloadName") | ||
if found { | ||
span.SetAttributes(Workload.String(workload)) | ||
} | ||
version, found, _ := unstructured.NestedString(crd.UnstructuredContent(), "spec", "version") | ||
if found { | ||
span.SetAttributes(Version.String(version)) | ||
} | ||
span.SetAttributes(Namespace.String(ns)) | ||
return ctx, span | ||
} |