forked from keptn/lifecycle-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: fix context information in guides (keptn#2902)
Signed-off-by: RealAnna <[email protected]> Signed-off-by: RealAnna <[email protected]> Co-authored-by: Florian Bacher <[email protected]> Co-authored-by: Meg McRoberts <[email protected]> Co-authored-by: Moritz Wiesinger <[email protected]>
- Loading branch information
1 parent
66ae056
commit 9095a00
Showing
15 changed files
with
334 additions
and
105 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,9 @@ | ||
apiVersion: lifecycle.keptn.sh/v1beta1 | ||
kind: KeptnAppContext | ||
metadata: | ||
name: keptndemoapp | ||
namespace: keptndemo | ||
spec: | ||
metadata: | ||
commit-id: "1234" | ||
author: "myUser" |
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,11 @@ | ||
apiVersion: lifecycle.keptn.sh/v1beta1 | ||
kind: KeptnAppContext | ||
metadata: | ||
name: keptndemoapp | ||
namespace: keptndemo | ||
spec: | ||
metadata: | ||
commit-id: "1234" | ||
author: "myUser" | ||
spanLinks: | ||
- "00-c088f5c586bab8649159ccc39a9862f7-f862289833f1fba3-01" |
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,13 @@ | ||
apiVersion: lifecycle.keptn.sh/v1alpha3 | ||
kind: KeptnTaskDefinition | ||
metadata: | ||
name: dummy-task | ||
namespace: "default" | ||
spec: | ||
function: | ||
secureParameters: | ||
secret: my-secret | ||
inline: | ||
code: | | ||
let secret_text = Deno.env.get("SECURE_DATA"); | ||
// secret_text = "foo" |
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 @@ | ||
apiVersion: batch/v1 | ||
kind: Job | ||
spec: | ||
template: | ||
spec: | ||
containers: | ||
- name: "my-task-container" | ||
env: | ||
- name: KEPTN_CONTEXT | ||
value: '{ | ||
"workloadName":"waiter-waiter", | ||
"appName":"waiter", | ||
"appVersion":"", | ||
"workloadVersion":"0.4", | ||
"taskType":"pre", | ||
"objectType":"Workload", | ||
"metadata":{ | ||
"commit-id":"1234", | ||
"stage":"dev", | ||
"test-metadata":"test-metadata", | ||
"traceparent": "00-traceid-spanid-01" | ||
} | ||
}' | ||
- name: SCRIPT | ||
value: /var/data/function.ts |
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,15 @@ | ||
apiVersion: lifecycle.keptn.sh/v1alpha3 | ||
kind: KeptnTaskDefinition | ||
metadata: | ||
name: dummy-task | ||
namespace: "default" | ||
spec: | ||
function: | ||
secureParameters: | ||
secret: my-secret | ||
inline: | ||
code: | | ||
let secret_text = Deno.env.get("SECURE_DATA"); | ||
let secret_text_obj = JSON.parse(secret_text); | ||
// secret_text_obj["foo"] = "bar" | ||
// secret_text_obj["foo2"] = "bar2" |
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,8 @@ | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: deno-demo-secret | ||
namespace: default | ||
type: Opaque | ||
data: | ||
SECURE_DATA: YmFyCg== # base64 encoded string, e.g. 'bar' |
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,13 @@ | ||
apiVersion: lifecycle.keptn.sh/v1alpha2 | ||
kind: KeptnTaskDefinition | ||
metadata: | ||
name: slack-notification-dev | ||
spec: | ||
function: | ||
functionRef: | ||
name: slack-notification | ||
parameters: | ||
map: | ||
textMessage: "This is my configuration" | ||
secureParameters: | ||
secret: slack-token |
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,16 @@ | ||
apiVersion: lifecycle.keptn.sh/v1alpha3 | ||
kind: KeptnTaskDefinition | ||
metadata: | ||
name: deployment-hello | ||
namespace: "default" | ||
spec: | ||
function: | ||
secureParameters: | ||
secret: deno-demo-secret | ||
inline: | ||
code: | | ||
console.log("Deployment Hello Task has been executed"); | ||
let foo = Deno.env.get('SECURE_DATA'); | ||
console.log(foo); | ||
Deno.exit(0); |
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,124 @@ | ||
--- | ||
comments: true | ||
--- | ||
|
||
# Context metadata | ||
|
||
This guide walks you through the usage of context metadata in Keptn. | ||
|
||
After reading this guide you will be able to: | ||
|
||
- add metadata to applications, workloads | ||
and tasks in two ways | ||
- add metadata information about applications to their traces | ||
|
||
## Introduction | ||
|
||
Context metadata in Keptn is defined as all additional information that can | ||
be added to applications, workloads and tasks. | ||
|
||
Context metadata can be added to your application | ||
in either of the following ways: | ||
|
||
- Use the `keptn.sh/metadata` annotation in any of | ||
your workloads you plan to deploy with Keptn | ||
- Apply a `KeptnAppContext` custom resource | ||
|
||
In the following section we will explore both. | ||
|
||
Common uses of this feature include: | ||
|
||
- adding a commit ID or references related to your GitOps and CI-CD tooling | ||
- referencing different stages and actors | ||
such as: who committed the change, in what repo, for what ticket... | ||
|
||
### Before you start | ||
|
||
1. [Install Keptn](../installation/index.md) | ||
2. Deploy an application, for instance, you can follow | ||
[a demo app installation here](../getting-started/observability.md#step-3-deploy-demo-application) | ||
|
||
To collect traces you will require Jaeger. | ||
To visualise and inspect the traces, you can either use | ||
the Jaeger UI or Grafana. | ||
|
||
1. Install | ||
[Grafana](https://grafana.com/grafana/) | ||
following the instructions in [Grafana Setup](https://grafana.com/docs/grafana/latest/setup-grafana/) | ||
or the visualization tool of your choice. | ||
2. Install | ||
[Jaeger](https://www.jaegertracing.io/) | ||
or a similar tool for traces following the instructions in | ||
[Jaeger Setup](https://www.jaegertracing.io/docs/1.50/getting-started/). | ||
|
||
## Include metadata in workload traces | ||
|
||
To enrich workload traces with custom metadata, use the | ||
`keptn.sh/metadata` annotation in your | ||
[Deployment](https://kubernetes.io/docs/concepts/workloads/controllers/deployment) | ||
resource. | ||
The values specified in the annotation | ||
are added as key-value attributes to the workload trace. | ||
|
||
Modify your workload (for example your YAML file containing a Deployment) | ||
adding an annotation with any metadata you prefer, | ||
for instance, to add information about a stage, you could add: | ||
`keptn.sh/metadata: "stage=dev"`. | ||
|
||
To see the changes Keptn must redeploy: increment the `app.kubernetes.io/version` value | ||
(ex. if you are following our getting started guide, change the version | ||
from `0.0.2` to `0.0.3`) or change the `keptn.sh/version` value | ||
if you used the Keptn specific labels in your deployment YAML file. | ||
|
||
This way, after the re-deployment, the workload trace will contain the `stage=dev` attribute. | ||
|
||
## Include metadata in application traces | ||
|
||
Similar to the previous step, custom metadata can also be added to application traces via the | ||
[KeptnAppContext](../reference/api-reference/lifecycle/v1beta1/index.md#keptnappcontext) CRD. | ||
|
||
`KeptnAppContext` is a custom resource definition in Keptn that allows you to add metadata | ||
and links to traces for a specific application. | ||
This enables you to enrich your Keptn resources and your traces with additional | ||
information, making it easier to understand and analyze | ||
the performance of your applications. | ||
|
||
In the `.spec.metadata` field you can define multiple key-value pairs, which are propagated | ||
to the application trace as attributes in the same manner as for workloads. | ||
|
||
> **Note** The key-value pairs that are added to the application trace are also added | ||
to each workload trace that is part of the application. | ||
If the same key is specified for both | ||
application and workload metadata attributes, | ||
values specified for the workload take precedence. | ||
|
||
A `KeptnAppContext` custom resource looks like the following: | ||
|
||
```yaml | ||
{% include "./assets/metadata/keptn-app-context.yaml" %} | ||
``` | ||
|
||
After applying the `KeptnAppContext` to your cluster, you need to increment the version of your | ||
application by modifying your deployment file and changing the | ||
value of the`app.kubernetes.io/version` field (or `keptn.sh/version` if you used the Keptn specific labels earlier). | ||
(Alternatively you could apply the context resource before or together with the workloads.) | ||
|
||
After deploying the `KeptnAppContext` resource and re-deploying the application, | ||
Keptn triggers another deployment of your application with the new context metadata, | ||
and all traces will contain the new metadata as defined in the above code example. | ||
In other words, you should be able to see the application trace as well as the workload trace | ||
contain the defined metadata as key-value attributes. | ||
|
||
## What's next? | ||
|
||
Congratulations! | ||
You've learned how to use the `KeptnAppContext` CRD to add | ||
metadata to applications and their traces. | ||
This can be valuable for understanding the context of your traces and | ||
establishing connections between | ||
different versions and stages of your application. | ||
|
||
Explore more about [traces on Keptn](./otel.md). | ||
The paragraph on | ||
[linking traces between different application](./otel.md#advanced-tracing-configurations-in-keptn-linking-traces) | ||
also uses KeptnAppContext. |
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
Oops, something went wrong.