Skip to content

Commit b38f4cb

Browse files
namkyu1999ispeakc0de
authored andcommitted
feat: implement otel telemetry sdk for distributed tracing (#221)
* feat: implement otel sdk Signed-off-by: namkyu1999 <lak9348@konkuk.ac.kr> * fix: update endpoint Signed-off-by: namkyu1999 <lak9348@konkuk.ac.kr> * fix: fix context logic Signed-off-by: namkyu1999 <lak9348@konkuk.ac.kr> * fix: make otel optional Signed-off-by: namkyu1999 <lak9348@konkuk.ac.kr> * (chore): Fix the release pipeline (#224) Signed-off-by: Shubham Chaudhary <shubham.chaudhary@harness.io> * fix: add logs Signed-off-by: namkyu1999 <lak9348@gmail.com> * chore Signed-off-by: namkyu1999 <lak9348@gmail.com> * feat: go version from 1.20 to 1.22 Signed-off-by: namkyu1999 <lak9348@gmail.com> --------- Signed-off-by: namkyu1999 <lak9348@konkuk.ac.kr> Signed-off-by: Shubham Chaudhary <shubham.chaudhary@harness.io> Signed-off-by: namkyu1999 <lak9348@gmail.com> Co-authored-by: Shubham Chaudhary <shubham.chaudhary@harness.io> Signed-off-by: Iván Álvarez <ivanape@inditex.com>
1 parent b0bca2f commit b38f4cb

File tree

10 files changed

+347
-149
lines changed

10 files changed

+347
-149
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ jobs:
8484
# Install golang
8585
- uses: actions/setup-go@v2
8686
with:
87-
go-version: 1.20.0
87+
go-version: 1.22.0
8888

8989
# Checkout to the latest commit
9090
# On specific directory/path

.github/workflows/push.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
# Install golang
1414
- uses: actions/setup-go@v2
1515
with:
16-
go-version: 1.20.0
16+
go-version: 1.22.0
1717

1818
# Checkout to the latest commit
1919
# On specific directory/path

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
# Install golang
1212
- uses: actions/setup-go@v2
1313
with:
14-
go-version: 1.20.0
14+
go-version: 1.22.0
1515

1616
# Checkout to the latest commit
1717
# On specific directory/path

bin/runner.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
package main
22

33
import (
4+
"context"
5+
"errors"
6+
"os"
7+
48
"github.com/litmuschaos/chaos-runner/pkg/log"
9+
"github.com/litmuschaos/chaos-runner/pkg/telemetry"
510
"github.com/litmuschaos/chaos-runner/pkg/utils"
611
"github.com/litmuschaos/chaos-runner/pkg/utils/analytics"
712
"github.com/sirupsen/logrus"
13+
"go.opentelemetry.io/otel"
814
)
915

1016
func init() {
@@ -17,9 +23,26 @@ func init() {
1723
}
1824

1925
func main() {
26+
ctx := context.Background()
27+
// Set up Observability.
28+
if otelExporterEndpoint := os.Getenv(telemetry.OTELExporterOTLPEndpoint); otelExporterEndpoint != "" {
29+
shutdown, err := telemetry.InitOTelSDK(ctx, otelExporterEndpoint)
30+
if err != nil {
31+
log.Errorf("Failed to initialize OTel SDK: %v", err)
32+
return
33+
}
34+
defer func() {
35+
err = errors.Join(err, shutdown(ctx))
36+
}()
37+
ctx = telemetry.GetTraceParentContext()
38+
}
2039

2140
engineDetails := utils.EngineDetails{}
2241
clients := utils.ClientSets{}
42+
43+
ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "ExecuteChaosRunner")
44+
defer span.End()
45+
2346
// Getting kubeConfig and Generate ClientSets
2447
if err := clients.GenerateClientSetFromKubeConfig(); err != nil {
2548
log.Errorf("unable to create ClientSets, error: %v", err)
@@ -66,7 +89,7 @@ func main() {
6689
continue
6790
}
6891
// derive the envs from the chaos experiment and override their values from chaosengine if any
69-
if err := experiment.SetENV(engineDetails, clients); err != nil {
92+
if err := experiment.SetENV(ctx, engineDetails, clients); err != nil {
7093
log.Errorf("unable to patch ENV, error: %v", err)
7194
experiment.ExperimentSkipped(utils.ExperimentEnvParseErrorReason, engineDetails, clients)
7295
engineDetails.ExperimentSkippedPatchEngine(&experiment, clients)
@@ -92,7 +115,7 @@ func main() {
92115
experiment.ExperimentDependencyCheck(engineDetails, clients)
93116

94117
// Creation of PodTemplateSpec, and Final Job
95-
if err := utils.BuildingAndLaunchJob(&experiment, clients); err != nil {
118+
if err := utils.BuildingAndLaunchJob(ctx, &experiment, clients); err != nil {
96119
log.Errorf("unable to construct chaos experiment job, error: %v", err)
97120
experiment.ExperimentSkipped(utils.ExperimentDependencyCheckReason, engineDetails, clients)
98121
engineDetails.ExperimentSkippedPatchEngine(&experiment, clients)

go.mod

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/litmuschaos/chaos-runner
22

3-
go 1.20
3+
go 1.22
44

55
require (
66
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24
@@ -12,39 +12,50 @@ require (
1212
github.com/onsi/gomega v1.15.0
1313
github.com/pkg/errors v0.9.1
1414
github.com/sirupsen/logrus v1.9.3
15-
github.com/stretchr/testify v1.7.0
15+
github.com/stretchr/testify v1.9.0
16+
go.opentelemetry.io/otel v1.27.0
17+
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.27.0
18+
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.27.0
19+
go.opentelemetry.io/otel/sdk v1.27.0
1620
k8s.io/api v0.26.0
1721
k8s.io/apimachinery v0.26.0
1822
k8s.io/client-go v12.0.0+incompatible
1923
)
2024

2125
require (
26+
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
2227
github.com/davecgh/go-spew v1.1.1 // indirect
2328
github.com/evanphx/json-patch v4.11.0+incompatible // indirect
2429
github.com/fsnotify/fsnotify v1.4.9 // indirect
25-
github.com/go-logr/logr v1.2.3 // indirect
30+
github.com/go-logr/logr v1.4.1 // indirect
31+
github.com/go-logr/stdr v1.2.2 // indirect
2632
github.com/gogo/protobuf v1.3.2 // indirect
27-
github.com/golang/protobuf v1.5.2 // indirect
28-
github.com/google/go-cmp v0.5.6 // indirect
33+
github.com/golang/protobuf v1.5.4 // indirect
34+
github.com/google/go-cmp v0.6.0 // indirect
2935
github.com/google/gofuzz v1.1.0 // indirect
3036
github.com/googleapis/gnostic v0.5.5 // indirect
37+
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
3138
github.com/imdario/mergo v0.3.12 // indirect
3239
github.com/json-iterator/go v1.1.12 // indirect
33-
github.com/kr/pretty v0.2.1 // indirect
3440
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
3541
github.com/modern-go/reflect2 v1.0.2 // indirect
3642
github.com/nxadm/tail v1.4.8 // indirect
3743
github.com/palantir/stacktrace v0.0.0-20161112013806-78658fd2d177 // indirect
3844
github.com/pmezard/go-difflib v1.0.0 // indirect
3945
github.com/spf13/pflag v1.0.5 // indirect
40-
golang.org/x/net v0.19.0 // indirect
41-
golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c // indirect
42-
golang.org/x/sys v0.15.0 // indirect
46+
go.opentelemetry.io/otel/metric v1.27.0 // indirect
47+
go.opentelemetry.io/otel/trace v1.27.0 // indirect
48+
go.opentelemetry.io/proto/otlp v1.2.0 // indirect
49+
golang.org/x/net v0.25.0 // indirect
50+
golang.org/x/oauth2 v0.21.0 // indirect
51+
golang.org/x/sys v0.20.0 // indirect
4352
golang.org/x/term v0.15.0 // indirect
44-
golang.org/x/text v0.14.0 // indirect
45-
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
46-
google.golang.org/appengine v1.6.7 // indirect
47-
google.golang.org/protobuf v1.26.0 // indirect
53+
golang.org/x/text v0.15.0 // indirect
54+
golang.org/x/time v0.5.0 // indirect
55+
google.golang.org/genproto/googleapis/api v0.0.0-20240610135401-a8a62080eff3 // indirect
56+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240610135401-a8a62080eff3 // indirect
57+
google.golang.org/grpc v1.64.0 // indirect
58+
google.golang.org/protobuf v1.34.1 // indirect
4859
gopkg.in/inf.v0 v0.9.1 // indirect
4960
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
5061
gopkg.in/yaml.v2 v2.4.0 // indirect
@@ -60,14 +71,11 @@ require (
6071
// Pinned to kubernetes-1.21.2
6172
replace (
6273
k8s.io/api => k8s.io/api v0.21.2
63-
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.21.2
6474
k8s.io/apimachinery => k8s.io/apimachinery v0.21.2
65-
k8s.io/apiserver => k8s.io/apiserver v0.21.2
6675
k8s.io/cli-runtime => k8s.io/cli-runtime v0.21.2
6776
k8s.io/client-go => k8s.io/client-go v0.21.2
6877
k8s.io/cloud-provider => k8s.io/cloud-provider v0.21.2
6978
k8s.io/cluster-bootstrap => k8s.io/cluster-bootstrap v0.21.2
70-
k8s.io/code-generator => k8s.io/code-generator v0.21.2
7179
k8s.io/component-base => k8s.io/component-base v0.21.2
7280
k8s.io/cri-api => k8s.io/cri-api v0.21.2
7381
k8s.io/csi-translation-lib => k8s.io/csi-translation-lib v0.21.2

0 commit comments

Comments
 (0)