Skip to content

Commit 1eaeda9

Browse files
committed
feat: add otel & tracing for distributed tracing
Signed-off-by: namkyu1999 <[email protected]>
1 parent 9689f74 commit 1eaeda9

File tree

11 files changed

+298
-64
lines changed

11 files changed

+298
-64
lines changed

bin/experiment/experiment.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package main
22

33
import (
4+
"context"
5+
"errors"
46
"flag"
57
// Uncomment to load all auth plugins
68
// _ "k8s.io/client-go/plugin/pkg/client/auth"
@@ -59,9 +61,9 @@ import (
5961
k6Loadgen "github.com/litmuschaos/litmus-go/experiments/load/k6-loadgen/experiment"
6062
springBootFaults "github.com/litmuschaos/litmus-go/experiments/spring-boot/spring-boot-faults/experiment"
6163
vmpoweroff "github.com/litmuschaos/litmus-go/experiments/vmware/vm-poweroff/experiment"
62-
63-
"github.com/litmuschaos/litmus-go/pkg/clients"
64+
cli "github.com/litmuschaos/litmus-go/pkg/clients"
6465
"github.com/litmuschaos/litmus-go/pkg/log"
66+
"github.com/litmuschaos/litmus-go/pkg/telemetry"
6567
"github.com/sirupsen/logrus"
6668
)
6769

@@ -75,8 +77,22 @@ func init() {
7577
}
7678

7779
func main() {
80+
ctx := context.Background()
81+
// Set up Observability.
82+
shutdown, err := telemetry.InitOTelSDK(ctx, true)
83+
if err != nil {
84+
return
85+
}
86+
// Handle shutdown properly so nothing leaks.
87+
defer func() {
88+
err = errors.Join(err, shutdown(ctx))
89+
}()
90+
91+
ctx = telemetry.GetTraceParentContext()
92+
clients := cli.ClientSets{Context: ctx}
7893

79-
clients := clients.ClientSets{}
94+
span := telemetry.StartTracing(clients, "ExecuteExperiment")
95+
defer span.End()
8096

8197
// parse the experiment name
8298
experimentName := flag.String("name", "pod-delete", "name of the chaos experiment")

bin/helper/helper.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package main
22

33
import (
4+
"context"
5+
"errors"
46
"flag"
57
// Uncomment to load all auth plugins
68
// _ "k8s.io/client-go/plugin/pkg/client/auth"
@@ -17,8 +19,9 @@ import (
1719
networkChaos "github.com/litmuschaos/litmus-go/chaoslib/litmus/network-chaos/helper"
1820
dnsChaos "github.com/litmuschaos/litmus-go/chaoslib/litmus/pod-dns-chaos/helper"
1921
stressChaos "github.com/litmuschaos/litmus-go/chaoslib/litmus/stress-chaos/helper"
22+
"github.com/litmuschaos/litmus-go/pkg/telemetry"
2023

21-
"github.com/litmuschaos/litmus-go/pkg/clients"
24+
cli "github.com/litmuschaos/litmus-go/pkg/clients"
2225
"github.com/litmuschaos/litmus-go/pkg/log"
2326
"github.com/sirupsen/logrus"
2427
)
@@ -33,8 +36,22 @@ func init() {
3336
}
3437

3538
func main() {
39+
ctx := context.Background()
40+
// Set up Observability.
41+
shutdown, err := telemetry.InitOTelSDK(ctx, false)
42+
if err != nil {
43+
return
44+
}
45+
// Handle shutdown properly so nothing leaks.
46+
defer func() {
47+
err = errors.Join(err, shutdown(ctx))
48+
}()
49+
50+
ctx = telemetry.GetTraceParentContext()
51+
clients := cli.ClientSets{Context: ctx}
3652

37-
clients := clients.ClientSets{}
53+
span := telemetry.StartTracing(clients, "ExecuteExperimentHelper")
54+
defer span.End()
3855

3956
// parse the helper name
4057
helperName := flag.String("name", "", "name of the helper pod")

build/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Multi-stage docker build
22
# Build stage
3-
FROM golang:1.18 AS builder
3+
FROM golang:1.22 AS builder
44

55
ARG TARGETOS=linux
66
ARG TARGETARCH

chaoslib/litmus/pod-delete/lib/pod-delete.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,25 @@ import (
88
"time"
99

1010
"github.com/litmuschaos/litmus-go/pkg/cerrors"
11-
"github.com/litmuschaos/litmus-go/pkg/workloads"
12-
"github.com/palantir/stacktrace"
13-
14-
clients "github.com/litmuschaos/litmus-go/pkg/clients"
11+
"github.com/litmuschaos/litmus-go/pkg/clients"
1512
"github.com/litmuschaos/litmus-go/pkg/events"
1613
experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/pod-delete/types"
1714
"github.com/litmuschaos/litmus-go/pkg/log"
1815
"github.com/litmuschaos/litmus-go/pkg/probe"
1916
"github.com/litmuschaos/litmus-go/pkg/status"
17+
"github.com/litmuschaos/litmus-go/pkg/telemetry"
2018
"github.com/litmuschaos/litmus-go/pkg/types"
2119
"github.com/litmuschaos/litmus-go/pkg/utils/common"
20+
"github.com/litmuschaos/litmus-go/pkg/workloads"
21+
"github.com/palantir/stacktrace"
2222
"github.com/sirupsen/logrus"
2323
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2424
)
2525

26-
// PreparePodDelete contains the prepration steps before chaos injection
26+
// PreparePodDelete contains the preparation steps before chaos injection
2727
func PreparePodDelete(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error {
28+
span := telemetry.StartTracing(clients, "InjectPodDeleteChaos")
29+
defer span.End()
2830

2931
//Waiting for the ramp time before chaos injection
3032
if experimentsDetails.RampTime != 0 {

experiments/generic/pod-delete/experiment/pod-delete.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package experiment
22

33
import (
4+
"os"
5+
46
"github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1"
57
litmusLIB "github.com/litmuschaos/litmus-go/chaoslib/litmus/pod-delete/lib"
68
"github.com/litmuschaos/litmus-go/pkg/clients"
@@ -14,12 +16,10 @@ import (
1416
"github.com/litmuschaos/litmus-go/pkg/types"
1517
"github.com/litmuschaos/litmus-go/pkg/utils/common"
1618
"github.com/sirupsen/logrus"
17-
"os"
1819
)
1920

2021
// PodDelete inject the pod-delete chaos
2122
func PodDelete(clients clients.ClientSets) {
22-
2323
experimentsDetails := experimentTypes.ExperimentDetails{}
2424
resultDetails := types.ResultDetails{}
2525
eventsDetails := types.EventDetails{}
@@ -58,7 +58,7 @@ func PodDelete(clients clients.ClientSets) {
5858
return
5959
}
6060

61-
// generating the event in chaosresult to marked the verdict as awaited
61+
// generating the event in chaosresult to mark the verdict as awaited
6262
msg := "experiment: " + experimentsDetails.ExperimentName + ", Result: Awaited"
6363
types.SetResultEventAttributes(&eventsDetails, types.AwaitedVerdict, msg, "Normal", &resultDetails)
6464
if err := events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosResult"); err != nil {

go.mod

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
module github.com/litmuschaos/litmus-go
22

3-
go 1.18
3+
go 1.22.0
44

55
require (
66
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24
7-
github.com/Azure/azure-sdk-for-go v56.1.0+incompatible
8-
github.com/Azure/go-autorest/autorest v0.11.18
7+
github.com/Azure/azure-sdk-for-go v68.0.0+incompatible
8+
github.com/Azure/go-autorest/autorest v0.11.29
99
github.com/Azure/go-autorest/autorest/azure/auth v0.5.7
1010
github.com/aws/aws-sdk-go v1.38.59
1111
github.com/containerd/cgroups v1.0.1
@@ -15,40 +15,47 @@ require (
1515
github.com/pkg/errors v0.9.1
1616
github.com/sirupsen/logrus v1.8.1
1717
github.com/spf13/cobra v1.1.1
18-
github.com/stretchr/testify v1.7.0
18+
github.com/stretchr/testify v1.9.0
19+
go.opentelemetry.io/otel v1.27.0
20+
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.27.0
21+
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.27.0
22+
go.opentelemetry.io/otel/sdk v1.27.0
1923
google.golang.org/api v0.48.0
2024
gopkg.in/yaml.v2 v2.4.0
21-
k8s.io/api v0.26.0
22-
k8s.io/apimachinery v0.26.0
25+
k8s.io/api v0.30.1
26+
k8s.io/apimachinery v0.30.1
2327
k8s.io/client-go v12.0.0+incompatible
2428
k8s.io/klog v1.0.0
2529
)
2630

2731
require (
2832
cloud.google.com/go v0.83.0 // indirect
2933
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
30-
github.com/Azure/go-autorest/autorest/adal v0.9.13 // indirect
34+
github.com/Azure/go-autorest/autorest/adal v0.9.22 // indirect
3135
github.com/Azure/go-autorest/autorest/azure/cli v0.4.2 // indirect
3236
github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect
3337
github.com/Azure/go-autorest/autorest/to v0.3.1-0.20191028180845-3492b2aff503 // indirect
3438
github.com/Azure/go-autorest/autorest/validation v0.2.1-0.20191028180845-3492b2aff503 // indirect
3539
github.com/Azure/go-autorest/logger v0.2.1 // indirect
3640
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
41+
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
3742
github.com/cilium/ebpf v0.6.2 // indirect
3843
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
3944
github.com/davecgh/go-spew v1.1.1 // indirect
4045
github.com/dimchansky/utfbom v1.1.1 // indirect
4146
github.com/docker/go-units v0.4.0 // indirect
42-
github.com/form3tech-oss/jwt-go v3.2.3+incompatible // indirect
43-
github.com/go-logr/logr v1.2.3 // indirect
47+
github.com/go-logr/logr v1.4.1 // indirect
48+
github.com/go-logr/stdr v1.2.2 // indirect
4449
github.com/godbus/dbus/v5 v5.0.4 // indirect
4550
github.com/gogo/protobuf v1.3.2 // indirect
51+
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
4652
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
47-
github.com/golang/protobuf v1.5.2 // indirect
48-
github.com/google/go-cmp v0.5.6 // indirect
53+
github.com/golang/protobuf v1.5.4 // indirect
54+
github.com/google/go-cmp v0.6.0 // indirect
4955
github.com/google/gofuzz v1.1.0 // indirect
5056
github.com/googleapis/gax-go/v2 v2.0.5 // indirect
5157
github.com/googleapis/gnostic v0.5.5 // indirect
58+
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
5259
github.com/imdario/mergo v0.3.12 // indirect
5360
github.com/inconshreveable/mousetrap v1.0.0 // indirect
5461
github.com/jmespath/go-jmespath v0.4.0 // indirect
@@ -61,17 +68,20 @@ require (
6168
github.com/pmezard/go-difflib v1.0.0 // indirect
6269
github.com/spf13/pflag v1.0.5 // indirect
6370
go.opencensus.io v0.23.0 // indirect
64-
golang.org/x/crypto v0.16.0 // indirect
65-
golang.org/x/net v0.19.0 // indirect
66-
golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c // indirect
67-
golang.org/x/sys v0.15.0 // indirect
68-
golang.org/x/term v0.15.0 // indirect
69-
golang.org/x/text v0.14.0 // indirect
71+
go.opentelemetry.io/otel/metric v1.27.0 // indirect
72+
go.opentelemetry.io/otel/trace v1.27.0 // indirect
73+
go.opentelemetry.io/proto/otlp v1.2.0 // indirect
74+
golang.org/x/crypto v0.23.0 // indirect
75+
golang.org/x/net v0.25.0 // indirect
76+
golang.org/x/oauth2 v0.20.0 // indirect
77+
golang.org/x/sys v0.20.0 // indirect
78+
golang.org/x/term v0.20.0 // indirect
79+
golang.org/x/text v0.15.0 // indirect
7080
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
71-
google.golang.org/appengine v1.6.7 // indirect
81+
google.golang.org/appengine v1.6.8 // indirect
7282
google.golang.org/genproto v0.0.0-20210604141403-392c879c8b08 // indirect
73-
google.golang.org/grpc v1.38.0 // indirect
74-
google.golang.org/protobuf v1.26.0 // indirect
83+
google.golang.org/grpc v1.64.0 // indirect
84+
google.golang.org/protobuf v1.34.1 // indirect
7585
gopkg.in/inf.v0 v0.9.1 // indirect
7686
gopkg.in/yaml.v3 v3.0.1 // indirect
7787
k8s.io/klog/v2 v2.80.1 // indirect

0 commit comments

Comments
 (0)