diff --git a/CODEOWNERS b/CODEOWNERS index b2430d07..a9e255c3 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -17,19 +17,17 @@ /incluster_eventing/ @m00g3n @pPrecel @dbadura @kwiatekus @cortey # Custom function runtime image example -/custom-serverless-runtime-image/ @m00g3n @pPrecel @dbadura @kwiatekus @cortey +/custom-serverless-runtime-image/ @kyma-project/otters # Observability /jaeger/ @kyma-project/observability /kiali/ @kyma-project/observability /loki/ @kyma-project/observability -/metrics-otlp/ @kyma-project/observability /prometheus/ @kyma-project/observability /trace-demo/ @kyma-project/observability -/tracing/ @kyma-project/observability # Scaling functions to zero with KEDA -/scale-to-zero-with-keda @m00g3n @pPrecel @dbadura @kwiatekus @cortey @anoipm @MichalKalke +/scale-to-zero-with-keda @kyma-project/otters # All .md files -*.md @mmitoraj @NHingerl @grego952 @IwonaLanger @nataliasitko +*.md @kyma-project/technical-writers diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index fa1a2df9..be47ae8e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -84,10 +84,6 @@ All examples are deployable in the cloud. Follow these rules to achieve this and A CI/CD configuration file accompanies each example to ensure its validity as part of the automation pipeline. -### Acceptance tests - -For details on acceptance tests for examples, see the [`acceptance-tests`](tests/README.md) document. - ### Releases Each example is independently releasable by creating a `tag` in the repository with the `{example-name}/{version}` format. This triggers a release for the given example from its CI/CD configuration. Push released example Docker images to the `example` folder in the Kyma repository, under `eu.gcr.io/kyma-project/example`. diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 12477ce7..00000000 --- a/Dockerfile +++ /dev/null @@ -1,19 +0,0 @@ -FROM alpine:3.8 - -LABEL source="git@github.com:kyma-project/examples.git" - -ENV KUBECTL_VERSION=v1.11.1 -ENV HELM_VERSION=v2.8.2 -ENV KUBELESS_VERSION=v1.0.0-alpha.7 - -RUN apk add --no-cache curl tar gzip - -RUN curl -Lo /usr/bin/kubectl https://storage.googleapis.com/kubernetes-release/release/${KUBECTL_VERSION}/bin/linux/amd64/kubectl && chmod +x /usr/bin/kubectl - -RUN curl -Lo /tmp/kubeless.zip https://github.com/kubeless/kubeless/releases/download/${KUBELESS_VERSION}/kubeless_linux-amd64.zip && unzip -q /tmp/kubeless.zip -d /tmp/ && mv /tmp/bundles/kubeless_linux-amd64/kubeless /usr/bin/ && rm -r /tmp/kubeless.zip /tmp/bundles && chmod +x /usr/bin/kubeless - -RUN curl -L https://storage.googleapis.com/kubernetes-helm/helm-${HELM_VERSION}-linux-amd64.tar.gz | tar xz && mv linux-amd64/helm /bin/helm && rm -rf linux-amd64 - -RUN mkdir -p /root/.kube && touch /root/.kube/config - -ADD . / \ No newline at end of file diff --git a/README.md b/README.md index 71a1e83f..c09d19cc 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,6 @@ The summary of the documentation in the `examples` repository lists all availabl | [Gateway](gateway/README.md) | Expose APIs for functions or services. | Kubeless | | [Service Binding](service-binding/lambda/README.md) | Bind a Redis service to a lambda function. | Kubeless, Redis, NodeJS | | [Event Email Service](event-email-service/README.md) | Send an automated email upon receiving an Event. | NodeJS | -| [Tracing](tracing/README.md) | Configure tracing for a service in Kyma. | Go | | [Custom serverless runtime image](custom-serverless-runtime-image/README.md) | Build custom runtime image. | Python | | [Kiali](kiali/README.md) | Deploy Kiali to Kyma. | Kiali, Istio, Prometheus | | [Prometheus](prometheus/README.md) | Deploy a Prometheus stack to monitor custom metrics. | Prometheus, Grafana | diff --git a/examples-chart/Chart.yaml b/examples-chart/Chart.yaml deleted file mode 100644 index a518e6fd..00000000 --- a/examples-chart/Chart.yaml +++ /dev/null @@ -1,6 +0,0 @@ -name: examples-chart -version: 0.0.1 -description: Deploy & Test Examples -keywords: - - test - - examples diff --git a/examples-chart/README.md b/examples-chart/README.md deleted file mode 100644 index 69bbecac..00000000 --- a/examples-chart/README.md +++ /dev/null @@ -1,49 +0,0 @@ -# Example Chart - -## Overview - -This chart provides an easy way to deploy and test the examples. - -## Prerequisites - -- Kubernetes 1.10+ -- Kyma as the target deployment environment. - - -## Details - -### Installation - -Configure these options in the [`values.yaml`](values.yaml) file: - -| Parameter | Description | -|--------------------------------- | -----------: | -| examples.image | Image for the examples | -| examples.httpDBService.deploy | Deploy the [HTTP DB Service](../http-db-service) example. | -| examples.httpDBService.deploymentImage | Deployment image for the HTTP DB Service. | -| examples.httpDBService.testImage | Test image for the HTTP DB Service. | -| examples.eventEmailService.deploy | Deploy the [Event Email Service](../event-email-service) example. | -| examples.eventEmailService.deploymentImage | Deployment image for the Event Email Service example. | -| rbac.enabled | Enable RBAC. | - -Deploy the examples: - -``` -helm install -f values.yaml --name examples --namespace . -``` - -### Testing - -Deploy the test Pods defined under [`templates/tests`](templates/tests): -``` -helm test --cleanup examples -``` -The output of this command shows whether the tests passed or failed. - -### Cleanup - -Clean up the Namespace: -``` -helm delete --purge examples -kubectl delete ns -``` diff --git a/examples-chart/templates/deployments/event-email-service/Pod.yaml b/examples-chart/templates/deployments/event-email-service/Pod.yaml deleted file mode 100644 index 14c8d2c1..00000000 --- a/examples-chart/templates/deployments/event-email-service/Pod.yaml +++ /dev/null @@ -1,39 +0,0 @@ -{{ if .Values.examples.eventEmailService.deploy }} ---- -apiVersion: v1 -kind: Pod -metadata: - name: "{{ .Release.Name }}-event-email-service-deploy-{{ randAlphaNum 5 | lower }}" - labels: - example: event-email-service - app: event-email-service-test - chart: examples -spec: - serviceAccountName: {{ .Release.Name }}-examples-service-account - containers: - - name: event-email-service-deploy - image: {{ .Values.examples.image }} - command: ['sh', '-c'] - args: [" - {{ if .Values.examples.eventEmailService.deploymentImage }} - sed -i 's~^ - image: .*$~ - image: {{ .Values.examples.eventEmailService.deploymentImage }}~' event-email-service/deployment/deployment.yaml || (touch /tmp/healthy && sleep 600) && - {{ end }} - kubectl apply -f event-email-service/deployment -n {{ .Release.Namespace }} || (touch /tmp/healthy && sleep 600) && - kubectl wait --for=condition=available --timeout=60s deployment/event-email-service -n {{ .Release.Namespace }} || (touch /tmp/healthy && sleep 600) && - touch /tmp/healthy && sleep 600 - "] - readinessProbe: - exec: - command: - - cat - - /tmp/healthy - initialDelaySeconds: 5 - periodSeconds: 5 - resources: - limits: - memory: 100Mi - requests: - memory: 32Mi - restartPolicy: Never ---- -{{ end }} \ No newline at end of file diff --git a/examples-chart/templates/deployments/http-db-service/Pod.yaml b/examples-chart/templates/deployments/http-db-service/Pod.yaml deleted file mode 100644 index c0c2f830..00000000 --- a/examples-chart/templates/deployments/http-db-service/Pod.yaml +++ /dev/null @@ -1,34 +0,0 @@ -{{ if .Values.examples.httpDBService.deploy }} ---- -apiVersion: v1 -kind: Pod -metadata: - name: "{{ .Release.Name }}-http-db-service-deploy-{{ randAlphaNum 5 | lower }}" - labels: - example: http-db-service - app: http-db-service-test - chart: examples -spec: - serviceAccountName: {{ .Release.Name }}-examples-service-account - containers: - - name: http-db-service-deploy - image: {{ .Values.examples.image }} - command: ['sh', '-c'] - args: [" - {{ if .Values.examples.httpDBService.deploymentImage }} - sed -i 's~^ - image: .*$~ - image: {{ .Values.examples.httpDBService.deploymentImage }}~' http-db-service/deployment/deployment.yaml || (touch /tmp/healthy && sleep 600) && - {{ end }} - kubectl apply -f http-db-service/deployment -n {{ .Release.Namespace }} || (touch /tmp/healthy && sleep 600) && - kubectl wait --for=condition=available --timeout=60s deployment/http-db-service -n {{ .Release.Namespace }} || (touch /tmp/healthy && sleep 600) && - touch /tmp/healthy && sleep 600 - "] - readinessProbe: - exec: - command: - - cat - - /tmp/healthy - initialDelaySeconds: 5 - periodSeconds: 5 - restartPolicy: Never ---- -{{ end }} \ No newline at end of file diff --git a/examples-chart/templates/deployments/pre-install-rbac.yaml b/examples-chart/templates/deployments/pre-install-rbac.yaml deleted file mode 100644 index a88366ac..00000000 --- a/examples-chart/templates/deployments/pre-install-rbac.yaml +++ /dev/null @@ -1,57 +0,0 @@ -{{ if .Values.rbac.enabled }} ---- -apiVersion: v1 -kind: ServiceAccount -metadata: - name: {{ .Release.Name }}-examples-service-account - namespace: {{ .Release.Namespace }} ---- -kind: ClusterRole -apiVersion: rbac.authorization.k8s.io/v1beta1 -metadata: - name: {{ .Release.Name }}-examples-role - namespace: {{ .Release.Namespace }} -rules: - - apiGroups: ["extensions", "apps"] - resources: ["deployments"] - verbs: ["get", "watch", "list", "create", "update", "patch", "delete"] - - apiGroups: [""] - resources: ["pods", "services", "configmaps", "pods/exec", "pods/log"] - verbs: ["get", "watch", "list", "create", "update", "patch", "delete"] - - apiGroups: [""] - resources: ["services/proxy"] - verbs: ["get", "list"] - - apiGroups: ["apiextensions.k8s.io"] - resources: ["customresourcedefinitions"] - verbs: ["get", "watch", "list", "create", "update", "patch", "delete"] - - apiGroups: ["kubeless.io"] - resources: ["functions"] - verbs: ["get", "watch", "list", "create", "update", "patch", "delete"] - - apiGroups: ["config.istio.io"] - resources: ["rules", "deniers", "checknothings", "egressrules"] - verbs: ["get", "watch", "list", "create", "update", "patch", "delete"] - - apiGroups: ["kubeless.io"] - resources: ["functions"] - verbs: ["create", "delete", "get", "list"] - - apiGroups: ["servicecatalog.k8s.io"] - resources: ["serviceinstances", "servicebindings"] - verbs: ["create", "delete", "get", "list"] - - apiGroups: ["servicecatalog.kyma-project.io"] - resources: ["servicebindingusages"] - verbs: ["create", "delete", "get", "list"] ---- -kind: ClusterRoleBinding -apiVersion: rbac.authorization.k8s.io/v1beta1 -metadata: - name: {{ .Release.Name }}-examples-role-binding - namespace: {{ .Release.Namespace }} -subjects: - - kind: ServiceAccount - name: {{ .Release.Name }}-examples-service-account - namespace: {{ .Release.Namespace }} -roleRef: - apiGroup: rbac.authorization.k8s.io - kind: ClusterRole - name: {{ .Release.Name }}-examples-role ---- -{{ end }} diff --git a/examples-chart/templates/deployments/service-binding/lambda/Pod.yaml b/examples-chart/templates/deployments/service-binding/lambda/Pod.yaml deleted file mode 100644 index 103f6c81..00000000 --- a/examples-chart/templates/deployments/service-binding/lambda/Pod.yaml +++ /dev/null @@ -1,38 +0,0 @@ -{{ if .Values.examples.serviceBinding.lambda.deploy }} ---- -apiVersion: v1 -kind: Pod -metadata: - name: "{{ .Release.Name }}-service-binding-lambda-deploy-{{ randAlphaNum 5 | lower }}" - labels: - example: service-binding-lambda - app: service-binding-lambda-test - chart: examples -spec: - serviceAccountName: {{ .Release.Name }}-examples-service-account - containers: - - name: service-binding-lambda-deploy - image: {{ .Values.examples.image }} - command: ['sh', '-c'] - args: - - export KYMA_EXAMPLE_ENV="{{ .Release.Namespace }}" || (touch /tmp/healthy && sleep 600) && - cd service-binding/lambda || (touch /tmp/healthy && sleep 600) && - kubectl apply -f deployment/redis-instance.yaml,deployment/redis-instance-binding.yaml -n $KYMA_EXAMPLE_ENV || (touch /tmp/healthy && sleep 600) && - kubectl apply -f deployment/lambda-function.yaml -n $KYMA_EXAMPLE_ENV || (touch /tmp/healthy && sleep 600) && - kubectl apply -f deployment/service-binding-usage.yaml -n $KYMA_EXAMPLE_ENV || (touch /tmp/healthy && sleep 600) && - touch /tmp/healthy && sleep 600 - readinessProbe: - exec: - command: - - cat - - /tmp/healthy - initialDelaySeconds: 5 - periodSeconds: 5 - resources: - limits: - memory: 100Mi - requests: - memory: 32Mi - restartPolicy: Never ---- -{{ end }} \ No newline at end of file diff --git a/examples-chart/templates/tests/event-email-service/Pod.yaml b/examples-chart/templates/tests/event-email-service/Pod.yaml deleted file mode 100644 index 7d109e82..00000000 --- a/examples-chart/templates/tests/event-email-service/Pod.yaml +++ /dev/null @@ -1,36 +0,0 @@ -{{ if .Values.examples.eventEmailService.deploy }} ---- -apiVersion: v1 -kind: Pod -metadata: - name: "{{ .Release.Name }}-event-email-service-tests-{{ randAlphaNum 5 | lower }}" - labels: - example: event-email-service - app: event-email-service-test - chart: examples-tests - annotations: - "helm.sh/hook": test-success -spec: - serviceAccountName: {{ .Release.Name }}-examples-service-account - containers: - - name: event-email-service-tests - image: {{ .Values.examples.image }} - command: ['sh', '-c'] - args: [' - for i in $(seq 1 5); do - curl -H "Content-Type: application/json" -d ''{"event":{"customer":{"customerID": "1234", "uid": "rick.sanchez@mail.com"}}}'' http://event-email-service.{{ .Release.Namespace }}:3000/v1/events/register - && s=0 && break || - s=$?; - echo "Retrying in 15 seconds.."; - sleep 15; - done; - exit $s - '] - resources: - limits: - memory: 100Mi - requests: - memory: 32Mi - restartPolicy: Never ---- -{{ end }} diff --git a/examples-chart/templates/tests/http-db-service/Pod.yaml b/examples-chart/templates/tests/http-db-service/Pod.yaml deleted file mode 100644 index b775810d..00000000 --- a/examples-chart/templates/tests/http-db-service/Pod.yaml +++ /dev/null @@ -1,44 +0,0 @@ -{{ if .Values.examples.httpDBService.deploy }} ---- -apiVersion: v1 -kind: Pod -metadata: - name: "{{ .Release.Name }}-http-db-service-tests-{{ randAlphaNum 5 | lower }}" - labels: - example: http-db-service - app: http-db-service-test - chart: examples-tests - annotations: - "helm.sh/hook": test-success -spec: - serviceAccountName: {{ .Release.Name }}-examples-service-account - containers: - - image: {{ .Values.examples.image }} - name: http-db-service-tests - command: ['sh', '-c'] - args: [" - {{ if .Values.examples.httpDBService.testImage }} - sed -i 's~^ - image: .*$~ - image: {{ .Values.examples.httpDBService.testImage }}~' tests/http-db-service/deployment/pod.yaml - {{ end }} - for i in $(seq 1 5); do - [ $i -gt 1 ] && sleep 15; - kubectl apply -f tests/http-db-service/deployment -n {{ .Release.Namespace }} && - kubectl wait --for=condition=Ready --timeout=60s pod/http-db-service-acceptance-tests -n {{ .Release.Namespace }} && - sleep 10 && - kubectl logs http-db-service-acceptance-tests -n {{ .Release.Namespace }} | grep -q 'PASS' && - s=0 && break || - s=$?; - echo 'Retrying in 15 seconds..'; - kubectl delete -f tests/http-db-service/deployment -n {{ .Release.Namespace }}; - done; - exit $s - "] - resources: - limits: - memory: 100Mi - requests: - memory: 32Mi - restartPolicy: Never ---- -{{ end }} - diff --git a/examples-chart/templates/tests/service-binding/lambda/Pod.yaml b/examples-chart/templates/tests/service-binding/lambda/Pod.yaml deleted file mode 100644 index 834cd1b8..00000000 --- a/examples-chart/templates/tests/service-binding/lambda/Pod.yaml +++ /dev/null @@ -1,34 +0,0 @@ -{{ if .Values.examples.serviceBinding.lambda.deploy }} ---- -apiVersion: v1 -kind: Pod -metadata: - name: "{{ .Release.Name }}-service-binding-lambda-test-{{ randAlphaNum 5 | lower }}" - labels: - example: service-binding-lambda - app: service-binding-lambda-test - chart: examples-tests - annotations: - "helm.sh/hook": test-success -spec: - serviceAccountName: {{ .Release.Name }}-examples-service-account - containers: - - name: service-binding-lambda-test - image: {{ .Values.examples.image }} - command: ['sh', '-c'] - args: [' - export KYMA_EXAMPLE_ENV="{{ .Release.Namespace }}" && - kubectl wait --for condition=Ready --timeout=60s -n $KYMA_EXAMPLE_ENV pod -l function=redis-client && - sleep 60 && - kubeless function call redis-client -n $KYMA_EXAMPLE_ENV && - sleep 10 && - kubectl logs -l function=redis-client -n $KYMA_EXAMPLE_ENV -c redis-client | grep -q "redis_version" - '] - resources: - limits: - memory: 100Mi - requests: - memory: 32Mi - restartPolicy: Never ---- -{{ end }} \ No newline at end of file diff --git a/examples-chart/values.yaml b/examples-chart/values.yaml deleted file mode 100644 index 44d62ba3..00000000 --- a/examples-chart/values.yaml +++ /dev/null @@ -1,11 +0,0 @@ -examples: - image: eu.gcr.io/kyma-project/examples:0.1.70 - httpDBService: - deploy: false - eventEmailService: - deploy: false - serviceBinding: - lambda: - deploy: false -rbac: - enabled: true diff --git a/metrics-otlp/README.md b/metrics-otlp/README.md deleted file mode 100644 index 2caf4738..00000000 --- a/metrics-otlp/README.md +++ /dev/null @@ -1,158 +0,0 @@ -# Install an OTLP-based metrics collector - -## Overview - -The following instructions demonstrate how to install [OpenTelemetry Collector](https://github.com/open-telemetry/opentelemetry-collector)s on a Kyma cluster using the official [Helm chart](https://github.com/open-telemetry/opentelemetry-helm-charts/tree/main/charts/opentelemetry-collector) with the goal to collect and ship workload metrics to an OTLP endpoint. For a fully Prometheus-based approach, have a look at the [Prometheus](./../prometheus/README.md) tutorial instead. - -The setup brings an OpenTelemetry Collector Deployment acting as gateway, to which all the cluster-wide metrics should be ingested. Then, the gateway enriches the metrics with missing resource attributes and ships them to a target backend. - -Furthermore, the setup brings an OpenTelemetry Collector DaemonSet acting as agent running on each node. Here, node-specific metrics relevant for your workload are determined. This is also where an annotation-based workload scraper is running, which scrapes all containers running on the related node. -## Architecture - -[Architecture](./assets/overview.drawio.svg) - -## Prerequisites - -- Kyma Open Source 2.10.x or higher -- kubectl version 1.22.x or higher -- Helm 3.x - -## Preparation - -1. Export your Namespace as a variable. Replace the `{namespace}` placeholder in the following command and run it: - - ```bash - export K8S_NAMESPACE="{namespace}" - ``` - -1. If you haven't created a Namespace yet, do it now: - ```bash - kubectl create namespace $K8S_NAMESPACE - ``` - -1. Update your Helm installation with the required Helm repository: - - ```bash - helm repo add open-telemetry https://open-telemetry.github.io/opentelemetry-helm-charts - helm repo update - ``` - -## Deploy the gateway - -1. Deploy an Otel Collector using the upstream Helm chart with a prepared [values.yaml](./metrics-gateway-values.yaml) file. - - The values file defines a pipeline for receiving OTLP metrics, enriches them with resource attributes that fulfil the Kubernetes semantic conventions, and then exports them to a custom OTLP backend. - - The previous instructions don't provide any backend, so you must set the backend configuration. - If you don't want to use a Secret, use the following command, and adjust the placeholders `myEndpoint` and `myToken` to your needs: - - ```bash - helm upgrade metrics-gateway open-telemetry/opentelemetry-collector --version 0.62.2 --install --namespace $K8S_NAMESPACE \ - -f https://raw.githubusercontent.com/kyma-project/examples/main/metrics-otlp/metrics-gateway-values.yaml \ - --set config.exporters.otlp.endpoint="{myEndpoint}" \ - --set config.exporters.otlp.headers.Authorization="Bearer {myToken}" - ``` - - - > **TIP:** It's recommended that you provide tokens using a Secret. To achieve that, you can mount the relevant attributes of your secret via the `extraEnvs` parameter and use placeholders for referencing the actual environment values. Take a look at the provided sample [secret-values.yaml](./secret-values.yaml) file, adjust it to your Secret, and run: - ```bash - helm upgrade metrics-gateway open-telemetry/opentelemetry-collector --version 0.62.2 --install --namespace $K8S_NAMESPACE \ - -f https://raw.githubusercontent.com/kyma-project/examples/main/metrics-otlp/metrics-gateway-values.yaml \ - -f secret-values.yaml - ``` - -1. Verify the deployment. - Check that the related Pod has been created in the Namespace and is in the `Running` state: - ```bash - kubectl -n $K8S_NAMESPACE rollout status deploy metrics-gateway - ``` - -## Install the agent - -1. Deploy the agent. - - The gateway deployed in the previous step can be used to _push_ metrics via OTLP. If you prefer to use the Prometheus _pull_ approach, you need a dedicated instance to scrape your workload. Furthermore, to retrieve node-specific metrics, you need an agent as a DaemonSet. - - Deploy an Otel Collector using the upstream Helm chart with a prepared [values](./metrics-agent-values.yaml). The values file defines a metrics pipeline for scraping workload by annotation and pushing them to the gateway. It also defines a second metrics pipeline determining node-specific metrics for your workload from the nodes kubelet and the nodes filesystem itself. - - ```bash - helm upgrade metrics-agent open-telemetry/opentelemetry-collector --version 0.62.2 --install --namespace $K8S_NAMESPACE \ - -f https://raw.githubusercontent.com/kyma-project/examples/main/metrics-otlp/metrics-agent-values.yaml \ - --set config.exporters.otlp.endpoint=metrics-gateway.$K8S_NAMESPACE:4317 - ``` - -1. Verify the deployment. - Check that the related Pod has been created in the Namespace and is in the `Running` state: - ```bash - kubectl -n $K8S_NAMESPACE rollout status daemonset metrics-agent - ``` - -## Result - -Now, you have a setup in place as outlined in the [architecture diagram](#architecture), with a gateway and an agent. By default, the node-specific metrics are automatically ingested by the agent, and pushed via the gateway to the configured backend. Furthermore, metrics for the gateway and agent instances are exported. - - -## Usage - -To add metrics ingestion for your custom workload, you have the following options: - -### Prometheus pull-based, with annotations - -This approach assumes that you instrumented your application using a library like the [prometheus client library](https://prometheus.io/docs/instrumenting/clientlibs/), having a port in your workload exposed serving a typical Prometheus metrics endpoint. - -The agent is configured with a generic scrape configuration, which uses annotations to specify the endpoints to scrape in the cluster. -Having the annotations in place is everything you need for metrics ingestion to start automatically. - -Put the following annotations either to a service that resolves your metrics port, or directly to the pod: - -```yaml -prometheus.io/scrape: "true" # mandatory to enable automatic scraping -prometheus.io/scheme: https # optional, default is "http" if no Istio sidecar is used. When using a sidecar (Pod has label `security.istio.io/tlsMode=istio`), the default is "https". Use "https" to scrape workloads using Istio client certificates. -prometheus.io/port: "1234" # optional, configure the port under which the metrics are exposed -prometheus.io/path: /myMetrics # optional, configure the path under which the metrics are exposed -``` - - -> **NOTE:** The agent can scrape endpoints even if the workload uses Istio and accepts only mTLS communication. Because the agent itself should not be part of the Service Mesh in order to observe the Service Mesh, the agent uses a sidecar but has no traffic interception enabled. Instead, it mounts the client certificate and uses the certificate natively for the communication. That is a [recommended approach](https://istio.io/latest/docs/ops/integrations/prometheus/#tls-settings) by Istio. - -To try it out, you can install the demo app taken from the tutorial [Expose Custom Metrics in Kyma](https://github.com/kyma-project/examples/tree/main/prometheus/monitoring-custom-metrics) and annotate the workload with the annotations mentioned above. - -```bash -kubectl apply -n $K8S_NAMESPACE -f https://raw.githubusercontent.com/kyma-project/examples/main/prometheus/monitoring-custom-metrics/deployment/deployment.yaml -kubectl -n $K8S_NAMESPACE annotate service sample-metrics prometheus.io/scrape=true -kubectl -n $K8S_NAMESPACE annotate service sample-metrics prometheus.io/port=8080 -``` - -The workload exposes the metric `cpu_temperature_celsius` at port `8080`, which is then automatically ingested to your configured backend. - -### OpenTelemetry push-based - -This approach assumes that you instrumented your workload using the [OpenTelemetry SDK](https://opentelemetry.io/docs/instrumentation/). Here, you only need to tell your workload to which target it should push the metrics. By using the deployed gateway, the application configuration does not need to be aware of any target backend, it only needs to get the static endpoint of the gateway. To achieve this, configure the SDK-specific [environment variables](https://opentelemetry.io/docs/reference/specification/protocol/exporter/). Also, if not done yet as part of your instrumentation, it's strongly recommended that you configure a service name. - -```yaml -apiVersion: apps/v1 -kind: Deployment -metadata: - name MyDeployment -spec: - template: - spec: - containers: - - env: - - name: OTEL_EXPORTER_OTLP_METRICS_ENDPOINT - value: http://metrics-gateway.$K8S_NAMESPACE:4317 - - name: OTEL_SERVICE_NAME - valueFrom: - fieldRef: - apiVersion: v1 - fieldPath: metadata.labels['app.kubernetes.io/name'] -``` - -## Cleanup - -When you're done, you can remove the example and all its resources from the cluster by calling Helm: - -```bash -helm delete -n $K8S_NAMESPACE metrics-gateway -helm delete -n $K8S_NAMESPACE metrics-agent -``` diff --git a/metrics-otlp/assets/overview.drawio.svg b/metrics-otlp/assets/overview.drawio.svg deleted file mode 100644 index fba1bcd1..00000000 --- a/metrics-otlp/assets/overview.drawio.svg +++ /dev/null @@ -1,391 +0,0 @@ - - - - - - - - - -
-
-
- custom namespace -
-
-
-
- - custom namespace - -
-
- - - - -
-
-
- example-namespace -
-
-
-
- - example-namespace - -
-
- - - - -
-
-
- Kyma Cluster -
-
-
-
- - Kyma Cluster - -
-
- - - - - -
-
-
- <<DaemonSet>> -
- otel-collector-metric-agent -
-
-
-
- - <<DaemonSet>>... - -
-
- - - - -
-
-
- <<Deployment>> -
- otel-collector-metric-gateway -
-
-
-
- - <<Deployment>>... - -
-
- - - - - -
-
-
- External Environment -
-
-
-
- - External Environment - -
-
- - - - -
-
-
- Observability Backend -
-
-
-
- - Observability Backend - -
-
- - - - -
-
-
- metrics -
-
-
-
- - metrics - -
-
- - - - -
-
-
- - custom pod -
- @prometheus.io/scrape -
-
-
-
-
-
- - custom pod... - -
-
- - - - -
-
-
- - app container - -
-
-
-
- - app container - -
-
- - - - -
-
-
- - istio-proxy container - -
-
-
-
- - istio-proxy contai... - -
-
- - - - - -
-
-
- pull-based -
-
-
-
- - pull-based - -
-
- - - - - - - - R - - - - - - - -
-
-
- OTLP -
-
-
-
- - OTLP - -
-
- - - - R - - - - - - - -
-
-
- OTLP -
-
-
-
- - OTLP - -
-
- - - - R - - - - - - - -
-
-
- HTTP -
-
-
-
- - HTTP - -
-
- - - - -
-
-
- or -
- push-based -
-
-
-
- - or... - -
-
- - - - R - - - - - - - -
-
-
- OTLP -
-
-
-
- - OTLP - -
-
- - - - -
-
-
- Node -
-
-
-
- - Node - -
-
- - - - -
-
-
- Node -
-
-
-
- - Node - -
-
- - - -
- - - - - Text is not SVG - cannot display - - - -
\ No newline at end of file diff --git a/metrics-otlp/metrics-agent-values.yaml b/metrics-otlp/metrics-agent-values.yaml deleted file mode 100644 index 17d99822..00000000 --- a/metrics-otlp/metrics-agent-values.yaml +++ /dev/null @@ -1,370 +0,0 @@ -# possible values are documented here: https://github.com/open-telemetry/opentelemetry-helm-charts/blob/main/charts/opentelemetry-collector/values.yaml - -# Have a nicer name for the resources -fullnameOverride: metrics-agent - -# Run as agent on every node -mode: daemonset - -# actual otel controller configuration -config: - receivers: - # Configures collection of kublet metrics - kubeletstats: - collection_interval: 30s - # Configures collection of node metrics - hostmetrics: - collection_interval: 30s - # Configures scraping of prometheus metrics of collector itself - prometheus/self: - config: - scrape_configs: - - job_name: metrics-agent - scrape_interval: 10s - static_configs: - - targets: - - ${MY_POD_IP}:8888 - # Configures scraping of prometheus metrics from istio sidecar - prometheus/istio: - config: - scrape_configs: - - job_name: "istio-proxy" - metrics_path: /stats/prometheus - kubernetes_sd_configs: - - role: endpoints - relabel_configs: - - source_labels: - - __meta_kubernetes_endpoint_node_name - action: keep - regex: $NODE_NAME - - source_labels: - - __meta_kubernetes_namespace - action: drop - regex: kyma-system|kube-system - - source_labels: - - __meta_kubernetes_pod_label_security_istio_io_tlsMode - action: keep - regex: (istio) - - source_labels: - - __meta_kubernetes_pod_container_port_name - action: keep - regex: .*-envoy-prom - - source_labels: - - __meta_kubernetes_namespace - action: replace - target_label: namespace - - source_labels: - - __meta_kubernetes_service_name - action: replace - target_label: service - - source_labels: - - __meta_kubernetes_pod_name - action: replace - target_label: pod - - source_labels: - - __meta_kubernetes_pod_node_name - action: replace - target_label: node - metric_relabel_configs: - - source_labels: [ __name__ ] - regex: "istio_.*" - action: keep - # Configures scraping of prometheus metrics from annotated services - prometheus/app-services: - config: - scrape_configs: - - job_name: "app-services" - kubernetes_sd_configs: - - role: endpoints - relabel_configs: - - source_labels: [__meta_kubernetes_endpoint_node_name] - action: keep - regex: $NODE_NAME - - source_labels: [__meta_kubernetes_namespace] - action: drop - regex: (kyma-system|kube-system) - - source_labels: [__meta_kubernetes_service_annotation_prometheus_io_scrape] - action: keep - regex: true - - source_labels: [__meta_kubernetes_pod_label_security_istio_io_tlsMode] - action: replace - target_label: __scheme__ - replacement: https - regex: (istio) - - source_labels: [__meta_kubernetes_service_annotation_prometheus_io_scheme] - action: replace - target_label: __scheme__ - regex: (https?) - - source_labels: [__meta_kubernetes_service_annotation_prometheus_io_path] - action: replace - target_label: __metrics_path__ - regex: (.+) - - source_labels: [__address__,__meta_kubernetes_service_annotation_prometheus_io_port] - action: replace - target_label: __address__ - regex: ([^:]+)(?::\d+)?;(\d+) - replacement: $$1:$$2 - - source_labels: [__meta_kubernetes_namespace] - action: replace - target_label: namespace - - source_labels: [__meta_kubernetes_service_name] - action: replace - target_label: service - - source_labels: [__meta_kubernetes_pod_name] - target_label: pod - action: replace - - source_labels: [__meta_kubernetes_pod_node_name] - action: replace - target_label: node - tls_config: - ca_file: /etc/istio-output-certs/root-cert.pem - cert_file: /etc/istio-output-certs/cert-chain.pem - insecure_skip_verify: true - key_file: /etc/istio-output-certs/key.pem - # Configures scraping of prometheus metrics from annotated pods - prometheus/app-pods: - config: - scrape_configs: - - job_name: "app-pods" - kubernetes_sd_configs: - - role: pod - relabel_configs: - - source_labels: [__meta_kubernetes_pod_node_name] - action: keep - regex: $NODE_NAME - - source_labels: [__meta_kubernetes_namespace] - action: drop - regex: (kyma-system|kube-system) - - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape] - action: keep - regex: true - - source_labels: [__meta_kubernetes_pod_label_security_istio_io_tlsMode] - action: replace - target_label: __scheme__ - replacement: https - regex: (istio) - - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scheme] - action: replace - target_label: __scheme__ - regex: (https?) - - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path] - action: replace - target_label: __metrics_path__ - regex: (.+) - - source_labels: [__address__, __meta_kubernetes_pod_annotation_prometheus_io_port] - action: replace - regex: ([^:]+)(?::\d+)?;(\d+) - replacement: $$1:$$2 - target_label: __address__ - - source_labels: [__meta_kubernetes_namespace] - action: replace - target_label: namespace - - source_labels: [__meta_kubernetes_pod_name] - action: replace - target_label: pod - - source_labels: [__meta_kubernetes_pod_node_name] - action: replace - target_label: node - tls_config: - ca_file: /etc/istio-output-certs/root-cert.pem - cert_file: /etc/istio-output-certs/cert-chain.pem - insecure_skip_verify: true - key_file: /etc/istio-output-certs/key.pem - extensions: - memory_ballast: - size_mib: "400" - processors: - # Configure batching of signals being exported - batch: - send_batch_max_size: 512 - send_batch_size: 512 - timeout: 1s - # Configure memory limits at which new signals should get rejected to not crash - memory_limiter: - check_interval: 1s - limit_mib: 750 - spike_limit_mib: 100 - # Configure to enrich prometheus metrics with a service name taken from the actual metric.service attribute - transform/copy-service: - metric_statements: - - context: datapoint - statements: - - set(resource.attributes["service.name"], attributes["service"]) - # Configure to enrich host metrics with service name of the collector itself - resource/insert-host-service: - attributes: - - action: insert - key: service.name - value: metrics-agent-host - # Configure to enrich kubelet metrics with service name of the collector itself - resource/insert-kublet-service: - attributes: - - action: insert - key: service.name - value: metrics-agent-kubelet - # filter out kubelet metrics of system namespaces - filter: - metrics: - datapoint: - - 'resource.attributes["k8s.namespace.name"] == "compass-system"' - - 'resource.attributes["k8s.namespace.name"] == "kyma-system"' - - 'resource.attributes["k8s.namespace.name"] == "istio-system"' - - 'resource.attributes["k8s.namespace.name"] == "kube-system"' - - exporters: - otlp: - # Provided via command line arguments - # --------- - #endpoint: metrics-gateway.$K8S_NAMESPACE:4317 - tls: - insecure: true - retry_on_failure: - enabled: true - initial_interval: 5s - max_elapsed_time: 300s - max_interval: 30s - sending_queue: - enabled: true - queue_size: 512 - # Configure an additional stdout logger. The verbosity level can be increased for troubleshooting - logging/kubelet: - verbosity: normal # basic | normal | detailed - logging/host: - verbosity: normal # basic | normal | detailed - logging/prometheus: - verbosity: normal # basic | normal | detailed - - service: - # The actual pipelines - pipelines: - # Disable log ingestion - logs: null - # Disable trace ingestion - traces: null - # Enable a pipeline for kubelet metrics - metrics: - receivers: - - kubeletstats - processors: - - memory_limiter - - filter - - resource/insert-kublet-service - - batch - exporters: - - otlp - - logging/kubelet - # Enable a pipeline for host metrics - metrics/1: - receivers: - - hostmetrics - processors: - - memory_limiter - - resource/insert-host-service - - filter - - batch - exporters: - - otlp - - logging/host - # Enable a pipeline for metrics scraping - metrics/2: - receivers: - - prometheus/self - - prometheus/istio - - prometheus/app-services - - prometheus/app-pods - processors: - - memory_limiter - - transform/copy-service - - batch - exporters: - - otlp - - logging/prometheus - telemetry: - # Configures the log level for the collector itself - logs: - level: info # info | debug - -# Inject the node name to scrape metrics belonging to the node only -extraEnvs: - - name: NODE_NAME - valueFrom: - fieldRef: - fieldPath: spec.nodeName - -# Disabled trace specific ports coming with the helm chart -ports: - jaeger-compact: - enabled: false - jaeger-thrift: - enabled: false - jaeger-grpc: - enabled: false - zipkin: - enabled: false - -# Adjust the resource settings to the batch and memory-limiter settings -resources: - limits: - cpu: "1" - memory: 1Gi - requests: - cpu: 15m - memory: 50Mi - -# Tell the helm chart to pre-configure the host and kublet receiver with the typical defaults -presets: - hostMetrics: - enabled: true - kubeletMetrics: - enabled: true - -# ServiceAccount needed for prometheus endpoint discovery -serviceAccount: - create: true -clusterRole: - create: true - rules: - - apiGroups: - - "" - resources: - - nodes - - nodes/metrics - - services - - endpoints - - pods - verbs: - - get - - list - - watch - - apiGroups: - - networking.k8s.io - resources: - - ingresses - verbs: - - get - - list - - watch - - nonResourceURLs: - - /metrics - - /metrics/cadvisor - verbs: - - get - -# annotations and mounts for scraping mTLS targets -podLabels: - sidecar.istio.io/inject: "true" -podAnnotations: - proxy.istio.io/config: | - # configure an env variable `OUTPUT_CERTS` to write certificates to the given folder - proxyMetadata: - OUTPUT_CERTS: /etc/istio-output-certs - sidecar.istio.io/userVolumeMount: '[{"name": "istio-certs", "mountPath": "/etc/istio-output-certs"}]' - traffic.sidecar.istio.io/includeInboundPorts: "" - traffic.sidecar.istio.io/includeOutboundIPRanges: "" -extraVolumeMounts: - - mountPath: /etc/istio-output-certs - name: istio-certs - readOnly: true -extraVolumes: - - name: istio-certs - emptyDir: {} \ No newline at end of file diff --git a/metrics-otlp/metrics-gateway-values.yaml b/metrics-otlp/metrics-gateway-values.yaml deleted file mode 100644 index c351a7b9..00000000 --- a/metrics-otlp/metrics-gateway-values.yaml +++ /dev/null @@ -1,143 +0,0 @@ -# possible values are documented here: https://github.com/open-telemetry/opentelemetry-helm-charts/blob/main/charts/opentelemetry-collector/values.yaml - -# Run as gateway -mode: deployment - -# Have a nicer name for the resources -fullnameOverride: "metrics-gateway" - -# actual otel controller configuration -config: - receivers: - # Configure receiver for OTLP signals - otlp: - protocols: - grpc: {} - http: {} - # Configure scraping of the collector itself for monitoring - prometheus/self: - config: - scrape_configs: - - job_name: metrics-gateway - scrape_interval: 10s - static_configs: - - targets: - - ${MY_POD_IP}:8888 - extensions: - memory_ballast: - size_mib: "400" - processors: - # Configure batching of signals being exported - batch: - send_batch_max_size: 512 - send_batch_size: 512 - timeout: 1s - # Configure memory limits at which new signals should get rejected to not crash - memory_limiter: - check_interval: 1s - limit_percentage: 75 - spike_limit_percentage: 10 - # Configure to enrich metrics with typical resource attributes if not present yet - k8sattributes: - extract: - metadata: - - k8s.pod.name - - k8s.node.name - - k8s.namespace.name - - k8s.deployment.name - - k8s.statefulset.name - - k8s.daemonset.name - - k8s.cronjob.name - - k8s.job.name - # Configure to enrich metrics with a cluster name if not present yet - resource/insert-cluster: - attributes: - - action: insert - key: k8s.cluster.name - value: ${KUBERNETES_SERVICE_HOST} - exporters: - # Configure the actual OTLP exporter - otlp: - # Provided via command line arguments - # --------- - # endpoint: :4317 - # headers: - # Authorization: Bearer myToken - timeout: 5s - retry_on_failure: - enabled: true - initial_interval: 5s - max_elapsed_time: 300s - max_interval: 30s - sending_queue: - enabled: true - queue_size: 512 - # Configure an additional stdout logger. The verbosity level can be increased for troubleshooting - logging: - verbosity: normal # basic | normal | detailed - service: - # The actual pipelines - pipelines: - # Disable log ingestion - logs: null - # Disable traces ingestion - traces: null - # Enable a pipeline for metrics - # - receiving OTLP metrics and self-scraped metrics - # - enriching the metrics with resource attributes - # - exporting them batched with in-memory buffering and retry loop - metrics: - receivers: - - otlp - - prometheus/self - processors: - - memory_limiter - - k8sattributes - - resource/insert-cluster - - batch - exporters: - - otlp - - logging - # Configures the log level for the collector itself - telemetry: - logs: - level: info #info | debug - -# ServiceAccount required for k8s-attribute-processor -serviceAccount: - create: true -clusterRole: - create: true - rules: - - apiGroups: [""] - resources: ["pods", "namespaces"] - verbs: ["get", "watch", "list"] - -# Disabled istio sidecar injection -podLabels: - sidecar.istio.io/inject: "false" - -# Disabled trace specific ports coming with the helm chart -ports: - jaeger-compact: - enabled: false - jaeger-thrift: - enabled: false - jaeger-grpc: - enabled: false - zipkin: - enabled: false - -# Adjust the resource settings to the batch and memory-limiter settings -resources: - limits: - cpu: "1" - memory: 1Gi - requests: - cpu: 15m - memory: 50Mi - -# Tell the helm chart to pre-configure the attribute processor with the typical defaults -presets: - kubernetesAttributes: - enabled: true diff --git a/metrics-otlp/secret-values.yaml b/metrics-otlp/secret-values.yaml deleted file mode 100644 index ff81c289..00000000 --- a/metrics-otlp/secret-values.yaml +++ /dev/null @@ -1,20 +0,0 @@ -config: - exporters: - # Reconfigure the OTLP exporter with settings taken from the injected envs - otlp: - endpoint: ${OTLP_ENDPOINT} - headers: - Authorization: ${AUTH_HEADER} - -# Load envs with values from the secret -extraEnvs: -- name: OTLP_ENDPOINT - valueFrom: - secretKeyRef: - name: mySecret - key: endpoint -- name: AUTH_HEADER - valueFrom: - secretKeyRef: - name: mySecret - key: authHeaderValue diff --git a/tests/README.md b/tests/README.md deleted file mode 100644 index 9281eb43..00000000 --- a/tests/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# Examples Acceptance Tests - -## Overview - -This folder contains the acceptance tests for the examples that you can run as part of the Kyma testing process. The tests are written in Go. Run them as standard Go tests. Each example has a separate folder such as `http-db-example`. - -## Usage - -This section provides information on how to build and version the Docker image, as well as how to configure Kyma. - -### Configure Kyma - -After building and pushing the Docker image, set the proper tag `acceptanceTest.imageTag` in the `resources/core/values.yaml` file. diff --git a/tests/http-db-service/Dockerfile b/tests/http-db-service/Dockerfile deleted file mode 100644 index f3fc04a5..00000000 --- a/tests/http-db-service/Dockerfile +++ /dev/null @@ -1,11 +0,0 @@ -FROM golang:1.12-alpine - -ENV SRC_DIR=/go/src/github.com/kyma-project/examples/tests/http-db-service - -ADD . $SRC_DIR - -WORKDIR $SRC_DIR - -LABEL source=git@github.com:kyma-project/examples.git - -ENTRYPOINT go test -v ./... \ No newline at end of file diff --git a/tests/http-db-service/Gopkg.lock b/tests/http-db-service/Gopkg.lock deleted file mode 100644 index 56cf735d..00000000 --- a/tests/http-db-service/Gopkg.lock +++ /dev/null @@ -1,72 +0,0 @@ -# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. - - -[[projects]] - digest = "1:ffe9824d294da03b391f44e1ae8281281b4afc1bdaa9588c9097785e3af10cec" - name = "github.com/davecgh/go-spew" - packages = ["spew"] - pruneopts = "UT" - revision = "8991bc29aa16c548c550c7ff78260e27b9ab7c73" - version = "v1.1.1" - -[[projects]] - digest = "1:0028cb19b2e4c3112225cd871870f2d9cf49b9b4276531f03438a88e94be86fe" - name = "github.com/pmezard/go-difflib" - packages = ["difflib"] - pruneopts = "UT" - revision = "792786c7400a136282c1664665ae0a8db921c6c2" - version = "v1.0.0" - -[[projects]] - digest = "1:99d32780e5238c2621fff621123997c3e3cca96db8be13179013aea77dfab551" - name = "github.com/stretchr/testify" - packages = [ - "assert", - "require", - ] - pruneopts = "UT" - revision = "221dbe5ed46703ee255b1da0dec05086f5035f62" - version = "v1.4.0" - -[[projects]] - branch = "master" - digest = "1:334b27eac455cb6567ea28cd424230b07b1a64334a2f861a8075ac26ce10af43" - name = "golang.org/x/lint" - packages = [ - ".", - "golint", - ] - pruneopts = "UT" - revision = "fdd1cda4f05fd1fd86124f0ef9ce31a0b72c8448" - -[[projects]] - branch = "master" - digest = "1:4eb5ea8395fb60212dd58b92c9db80bab59d5e99c7435f9a6a0a528c373b60e7" - name = "golang.org/x/tools" - packages = [ - "go/ast/astutil", - "go/gcexportdata", - "go/internal/gcimporter", - "go/types/typeutil", - ] - pruneopts = "UT" - revision = "7093a17b0467e77fb41804b2754a44f54a8c9ca2" - -[[projects]] - digest = "1:b75b3deb2bce8bc079e16bb2aecfe01eb80098f5650f9e93e5643ca8b7b73737" - name = "gopkg.in/yaml.v2" - packages = ["."] - pruneopts = "UT" - revision = "1f64d6156d11335c3f22d9330b0ad14fc1e789ce" - version = "v2.2.7" - -[solve-meta] - analyzer-name = "dep" - analyzer-version = 1 - input-imports = [ - "github.com/stretchr/testify/assert", - "github.com/stretchr/testify/require", - "golang.org/x/lint/golint", - ] - solver-name = "gps-cdcl" - solver-version = 1 diff --git a/tests/http-db-service/Gopkg.toml b/tests/http-db-service/Gopkg.toml deleted file mode 100644 index 06631fec..00000000 --- a/tests/http-db-service/Gopkg.toml +++ /dev/null @@ -1,13 +0,0 @@ - - -required = [ - "golang.org/x/lint/golint" -] - -[[constraint]] - name = "github.com/stretchr/testify" - version = "1.3.0" - -[prune] - go-tests = true - unused-packages = true diff --git a/tests/http-db-service/Makefile b/tests/http-db-service/Makefile deleted file mode 100644 index eabf0b72..00000000 --- a/tests/http-db-service/Makefile +++ /dev/null @@ -1,26 +0,0 @@ -APP_NAME = http-db-service-acceptance-tests -IMG = $(DOCKER_PUSH_REPOSITORY)$(DOCKER_PUSH_DIRECTORY)/$(APP_NAME) -TAG = $(DOCKER_TAG) - -resolve: - dep ensure -vendor-only -v - -validate: - go build -o golint-vendored ./vendor/golang.org/x/lint/golint - ./golint-vendored - rm golint-vendored - -.PHONY: build-image -build-image: - docker build -t $(APP_NAME):latest . - -.PHONY: push-image -push-image: - docker tag $(APP_NAME) $(IMG):$(TAG) - docker push $(IMG):$(TAG) - -.PHONY: ci-pr -ci-pr: resolve validate build-image push-image - -.PHONY: ci-main -ci-main: resolve validate build-image push-image diff --git a/tests/http-db-service/deployment/pod.yaml b/tests/http-db-service/deployment/pod.yaml deleted file mode 100755 index 82fd906d..00000000 --- a/tests/http-db-service/deployment/pod.yaml +++ /dev/null @@ -1,19 +0,0 @@ -apiVersion: v1 -kind: Pod -metadata: - labels: - app: http-db-service-acceptance-tests - example: http-db-service - name: http-db-service-acceptance-tests -spec: - containers: - # replace the repository URL with your own repository (e.g. {DockerID}/http-db-service-acceptance-tests:0.0.x for Docker Hub). - - image: eu.gcr.io/kyma-project/example/http-db-service-acceptance-tests:0.1.15 - imagePullPolicy: IfNotPresent - name: http-db-service-acceptance-tests - resources: - limits: - memory: 200Mi - requests: - memory: 64Mi - restartPolicy: Never diff --git a/tests/http-db-service/service_test.go b/tests/http-db-service/service_test.go deleted file mode 100644 index e8e2d24d..00000000 --- a/tests/http-db-service/service_test.go +++ /dev/null @@ -1,106 +0,0 @@ -package service - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "testing" - "time" - - "github.com/stretchr/testify/assert" - - "github.com/stretchr/testify/require" -) - -const ( - targetHost = "http://http-db-service:8017" - ordersPath = "orders" - nsOrdersPath = "namespace/%s/orders" -) - -type order struct { - OrderId string `json:"orderId"` - Namespace string `json:"namespace"` - Total float64 `json:"total"` -} - -// TestAcceptanceOrders runs an acceptance test on the orders endpoint. -// First it tests getting orders, then adding orders and finally deleting. -func TestAcceptanceOrders(t *testing.T) { - http.DefaultClient.Timeout = 5 * time.Second - - // guarantee that all is deleted also when the test fails. - defer delete(t, ordersPath) - - // initially no orders - os := get(t, ordersPath) - assert.Len(t, os, 0) - - // insert an order to default Namespace - post(t, ordersPath, order{OrderId: "66", Total: 9000}) - - // check the inserted order - os = get(t, ordersPath) - assert.Len(t, os, 1) - assert.Equal(t, "default", os[0].Namespace) - - // insert an order to custom Namespace - post(t, ordersPath, order{OrderId: "66", Namespace: "N7", Total: 9000}) - - // check get by namespace - os = get(t, fmt.Sprintf(nsOrdersPath, "N7")) - assert.Len(t, os, 1) - - // check total orders - os = get(t, ordersPath) - assert.Len(t, os, 2) - - // delete custom namespace orders - delete(t, fmt.Sprintf(nsOrdersPath, "N7")) - // check no orders in namespace - os = get(t, fmt.Sprintf(nsOrdersPath, "N7")) - assert.Len(t, os, 0) - // but still orders in other namespaces - os = get(t, ordersPath) - assert.Len(t, os, 1) - - //delete orders - delete(t, ordersPath) - // check no orders - os = get(t, ordersPath) - assert.Len(t, os, 0) -} - -func get(t *testing.T, path string) []order { - resp, err := http.Get(fmt.Sprintf("%s/%s", targetHost, path)) - require.NoError(t, err) - require.Equal(t, http.StatusOK, resp.StatusCode) - - b, err := ioutil.ReadAll(resp.Body) - require.NoError(t, err) - defer resp.Body.Close() - - var os []order - require.NoError(t, json.Unmarshal(b, &os)) - - return os -} - -func post(t *testing.T, path string, data interface{}) { - order, err := json.Marshal(data) - require.NoError(t, err) - body := bytes.NewReader(order) - resp, err := http.Post(fmt.Sprintf("%s/%s", targetHost, path), "application/json", body) - require.NoError(t, err) - assert.Equal(t, http.StatusCreated, resp.StatusCode) -} - -func delete(t *testing.T, path string) { - r, err := http.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", targetHost, path), nil) - require.NoError(t, err) - resp, err := http.DefaultClient.Do(r) - require.NoError(t, err) - assert.Equal(t, http.StatusNoContent, resp.StatusCode) -} diff --git a/tracing/.gitignore b/tracing/.gitignore deleted file mode 100644 index 4d552586..00000000 --- a/tracing/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -.idea -*.iml -.vscode/ -/debug -/temp_* -vendor/ -.DS_Store -telepresence.log \ No newline at end of file diff --git a/tracing/Dockerfile b/tracing/Dockerfile deleted file mode 100644 index 0b40dd55..00000000 --- a/tracing/Dockerfile +++ /dev/null @@ -1,16 +0,0 @@ -FROM golang:1.19 as builder - -WORKDIR /go/src/tracing -COPY ./go.mod . -COPY src/order-front.go . -RUN CGO_ENABLED=0 GOOS=linux go build -v -a -installsuffix cgo -o order-front . - -FROM scratch - -WORKDIR /root/ - -COPY --from=builder /go/src/tracing . - -EXPOSE 8080 - -ENTRYPOINT ["/root/order-front"] diff --git a/tracing/Makefile b/tracing/Makefile deleted file mode 100644 index d27c58ad..00000000 --- a/tracing/Makefile +++ /dev/null @@ -1,27 +0,0 @@ -APP_NAME = tracing -IMG = $(DOCKER_PUSH_REPOSITORY)$(DOCKER_PUSH_DIRECTORY)/$(APP_NAME) -TAG = $(DOCKER_TAG) - -resolve: - go mod download - -validate: - go test ./... -count=1 - -build: - CGO_ENABLED=0 go build -ldflags "-s -w" -a -o ./bin/app ./src - -.PHONY: build-image -build-image: - docker build -t $(APP_NAME):latest . - -.PHONY: push-image -push-image: - docker tag $(APP_NAME) $(IMG):$(TAG) - docker push $(IMG):$(TAG) - -.PHONY: ci-pr -ci-pr: resolve validate build-image push-image - -.PHONY: ci-main -ci-main: resolve validate build-image push-image diff --git a/tracing/README.md b/tracing/README.md deleted file mode 100644 index 1f11befa..00000000 --- a/tracing/README.md +++ /dev/null @@ -1,60 +0,0 @@ -# Example Tracing - ->**CAUTION** This example is outdated and will be updated soon. - -## Overview - -This example illustrates how to enable tracing for a service deployed in Kyma. For demonstration, it creates a [Go application](src/order-front.go). This application uses [http-db-service](../http-db-service) for CRUD operations on orders. - -To understand how traces are propagated, see the [Go application](src/order-front.go). See the [`deployment`](deployment/deployment.yaml) file to learn about port naming and setting the `app` label. - -## Prerequisites - -- Kyma OS version 2.10.x or higher -- kubectl version 1.22.x or higher -- Helm 3.x - ->**NOTE:** By default, the sampling rate for Istio is set to `1`, while `100` is the maximum value. This means that only 1 out of 100 requests is sent to Jaeger for trace recording, which can affect the number of traces displayed for the service. To change this behavior, adjust the `randomSamplingPercentage` setting in the Istio's telemetry resource: -```bash -kubectl -n istio-system edit telemetries.telemetry.istio.io kyma-traces -``` - -## Installation - -1. Export your Namespace as a variable by replacing the `{namespace}` placeholder in the following command and running it: - - ```bash - export K8S_NAMESPACE="{namespace}" - ``` - -2. Deploy the service. Run this command: - - ```bash - kubectl apply -f deployment/deployment.yaml -n $K8S_NAMESPACE - ``` - -## Get traces from the example service - -1. Call the example service to simulate an incoming order. Run: - - ```bash - curl -H "Content-Type: application/json" -d '{"orderCode" : "007", "orderPrice" : 12.0}' https://order-front-api.{YOUR_CLUSTER_DOMAIN}/orders - ``` - -2. Access the Jaeger UI on the cluster at `http://localhost:16686` using port-forwarding: -```bash -kubectl port-forward -n kyma-system svc/tracing-jaeger-query 16686:16686 -``` - -3. Select **order-front** from the list of available services and click **Find Traces**. - -4. The UI displays end-to-end traces for the API call that simulated an incoming order. - - -## Cleanup - -To remove all resources related to this example from your Kyma cluster, run this command: - -```bash -kubectl delete all,api -l example=tracing -n $K8S_NAMESPACE -``` diff --git a/tracing/bin/app b/tracing/bin/app deleted file mode 100755 index db5edeea..00000000 Binary files a/tracing/bin/app and /dev/null differ diff --git a/tracing/build.sh b/tracing/build.sh deleted file mode 100755 index 1200f741..00000000 --- a/tracing/build.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash -set -e -set -o pipefail - -IMAGE_NAME=order-front:latest - -echo -e "Start building docker image [ ${IMAGE_NAME} ]" - -docker build --no-cache -t ${IMAGE_NAME} . - -echo -e "Docker image [ ${IMAGE_NAME} ] has been built successfully ..." diff --git a/tracing/deployment/deployment.yaml b/tracing/deployment/deployment.yaml deleted file mode 100644 index e1527880..00000000 --- a/tracing/deployment/deployment.yaml +++ /dev/null @@ -1,116 +0,0 @@ -apiVersion: gateway.kyma-project.io/v1beta1 -kind: APIRule -metadata: - name: order-front-api - labels: - example: tracing -spec: - gateway: kyma-system/kyma-gateway - service: - name: order-front - port: 8080 - host: order-front-api - rules: - - path: /.* - methods: ["GET"] - accessStrategies: - - handler: allow ---- -apiVersion: v1 -kind: Service -metadata: - name: order-front - labels: - example: tracing - app: order-front -spec: - type: ClusterIP - ports: - - port: 8080 - protocol: TCP - name: http - selector: - app: order-front ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: order-front - labels: - example: tracing - app: order-front -spec: - replicas: 1 - selector: - matchLabels: - app: order-front - example: tracing - template: - metadata: - labels: - app: order-front - example: tracing - spec: - containers: - - name: order-front - image: eu.gcr.io/kyma-project/snapshot/example/tracing-order-front:PR-64 - imagePullPolicy: IfNotPresent - args: - - --port=8080 - - --db-url=http://db-service:8017/orders - ports: - - containerPort: 8080 - resources: - requests: - cpu: "100m" - limits: - memory: "32M" ---- -apiVersion: v1 -kind: Service -metadata: - name: db-service - labels: - example: tracing - app: db-service -spec: - type: ClusterIP - ports: - - name: http - port: 8017 - protocol: TCP - selector: - app: db-service ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: db-service - labels: - example: tracing - app: db-service -spec: - replicas: 1 - selector: - matchLabels: - example: tracing - app: db-service - template: - metadata: - labels: - example: tracing - app: db-service - spec: - imagePullSecrets: - containers: - # replace the repository URL with your own repository (e.g. {DockerID}/http-db-service:0.0.x for Docker Hub). - - image: eu.gcr.io/kyma-project/example/http-db-service:0.0.6 - imagePullPolicy: IfNotPresent - name: db-service - ports: - - name: http - containerPort: 8017 - env: - - name: dbtype - # available dbtypes are: [memory, mssql] - value: "memory" diff --git a/tracing/go.mod b/tracing/go.mod deleted file mode 100644 index 1a9f8ea3..00000000 --- a/tracing/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module github.com/kyma-project/examples/tracing - -go 1.19 diff --git a/tracing/src/order-front.go b/tracing/src/order-front.go deleted file mode 100644 index 14cfa614..00000000 --- a/tracing/src/order-front.go +++ /dev/null @@ -1,158 +0,0 @@ -package main - -import ( - "bytes" - "encoding/json" - "errors" - "flag" - "fmt" - "io" - "log" - "net/http" -) - -type Order struct { - OrderCode string `json:"orderCode"` - OrderPrice float64 `json:"orderPrice"` -} - -type StoredOrder struct { - OrderId string `json:"orderId"` - Namespace string `json:"namespace"` - Total float64 `json:"total"` -} - -var httpTransport *http.Transport -var httpClient *http.Client - -func main() { - - var ( - port = flag.Int("port", 8080, "tcp port on which to listen for http requests") - dbUrl = flag.String("db-url", "", "db url to which store order data") - ) - flag.Parse() - - httpTransport = &http.Transport{} - httpClient = &http.Client{ - Transport: httpTransport, - } - - http.Handle("/orders", ordersHandler(dbUrl)) - - log.Printf("HTTP server starting on port %d", *port) - log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", *port), nil)) -} - -func ordersHandler(dbUrl *string) http.Handler { - - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - switch requestMethod := &r.Method; *requestMethod { - case http.MethodPost: - if r.Body == nil { - http.Error(w, "Please send a CloudEvent in the HTTP request body", http.StatusBadRequest) - return - } - - b, err := io.ReadAll(r.Body) - defer r.Body.Close() - if err != nil { - log.Printf("Error reading HTTP request body: %v", err) - http.Error(w, "Error reading HTTP request body", http.StatusBadRequest) - return - } - - var order Order - if err := json.Unmarshal(b, &order); err != nil { - log.Printf("Error unmarshalling event data: %v", err) - http.Error(w, err.Error(), http.StatusBadRequest) - return - } - - log.Println(r.Header) - - if err := storeOrdersInDB(&order, dbUrl, r.Header); err != nil { - w.WriteHeader(http.StatusInternalServerError) - } else { - w.WriteHeader(http.StatusCreated) - } - case http.MethodGet: - orders, err := getOrdersFromDB(dbUrl, r.Header) - if err != nil { - w.WriteHeader(http.StatusInternalServerError) - } else { - json.NewEncoder(w).Encode(orders) - } - case http.MethodDelete: - statusCode, err := deleteOrdersFromDB(dbUrl, r.Header) - if err != nil { - w.WriteHeader(http.StatusInternalServerError) - } else { - w.WriteHeader(statusCode) - } - default: - http.Error(w, fmt.Sprintf("HTTP method '%v' is not supported", *requestMethod), http.StatusMethodNotAllowed) - } - }) -} - -func getOrdersFromDB(dbUrl *string, incomingHeaders http.Header) (*[]StoredOrder, error) { - downstreamRequest, _ := http.NewRequest(http.MethodGet, *dbUrl, nil) - propagateTracingHeaders(incomingHeaders, downstreamRequest) - resp, err := httpClient.Do(downstreamRequest) - if err != nil { - return nil, err - } - - orders := make([]StoredOrder, 0) - byteArray, err := io.ReadAll(resp.Body) - if err != nil { - return nil, err - } - json.Unmarshal(byteArray, &orders) - - return &orders, nil -} - -func deleteOrdersFromDB(dbUrl *string, incomingHeaders http.Header) (int, error) { - downstreamRequest, _ := http.NewRequest(http.MethodDelete, *dbUrl, nil) - propagateTracingHeaders(incomingHeaders, downstreamRequest) - resp, err := httpClient.Do(downstreamRequest) - if err != nil { - return -1, err - } - - return resp.StatusCode, nil -} - -func storeOrdersInDB(order *Order, dbUrl *string, incomingHeaders http.Header) error { - toSend := StoredOrder{OrderId: order.OrderCode, Total: order.OrderPrice} - payload, err := json.Marshal(toSend) - - if err != nil { - return err - } - downstreamRequest, _ := http.NewRequest(http.MethodPost, *dbUrl, bytes.NewBuffer(payload)) - downstreamRequest.Header.Add("Content-Type", "application/json") - propagateTracingHeaders(incomingHeaders, downstreamRequest) - - resp, err := httpClient.Do(downstreamRequest) - statusCode := resp.StatusCode - - if statusCode >= 399 && statusCode != 409 { - return errors.New("error status when storing event") - } - - return err -} - -func propagateTracingHeaders(incomingHeaders http.Header, downstreamRequest *http.Request) { - traceHeadersName := [...]string{"Traceparent", "Tracestate", "Baggage"} - for _, headerName := range traceHeadersName { - headerVal := incomingHeaders[headerName] - if len(headerVal) > 0 { - log.Print(headerName, headerVal) - downstreamRequest.Header[headerName] = headerVal - } - } -}