@@ -24,6 +24,7 @@ import (
24
24
"github.com/litmuschaos/litmus-go/pkg/utils/retry"
25
25
"github.com/palantir/stacktrace"
26
26
"go.opentelemetry.io/otel"
27
+ "go.opentelemetry.io/otel/codes"
27
28
)
28
29
29
30
var (
@@ -55,11 +56,16 @@ func PrepareChaos(ctx context.Context, experimentsDetails *experimentTypes.Exper
55
56
//get the disk name or list of disk names
56
57
diskNameList := strings .Split (experimentsDetails .VirtualDiskNames , "," )
57
58
if experimentsDetails .VirtualDiskNames == "" || len (diskNameList ) == 0 {
58
- return cerrors.Error {ErrorCode : cerrors .ErrorTypeTargetSelection , Reason : "no volume names found to detach" }
59
+ span .SetStatus (codes .Error , "no volume names found to detach" )
60
+ err := cerrors.Error {ErrorCode : cerrors .ErrorTypeTargetSelection , Reason : "no volume names found to detach" }
61
+ span .RecordError (err )
62
+ return err
59
63
}
60
64
instanceNamesWithDiskNames , err := diskStatus .GetInstanceNameForDisks (diskNameList , experimentsDetails .SubscriptionID , experimentsDetails .ResourceGroup )
61
65
62
66
if err != nil {
67
+ span .SetStatus (codes .Error , "failed to get instance names for disks" )
68
+ span .RecordError (err )
63
69
return stacktrace .Propagate (err , "error fetching attached instances for disks" )
64
70
}
65
71
@@ -69,6 +75,8 @@ func PrepareChaos(ctx context.Context, experimentsDetails *experimentTypes.Exper
69
75
for instanceName := range instanceNamesWithDiskNames {
70
76
attachedDisksWithInstance [instanceName ], err = diskStatus .GetInstanceDiskList (experimentsDetails .SubscriptionID , experimentsDetails .ResourceGroup , experimentsDetails .ScaleSet , instanceName )
71
77
if err != nil {
78
+ span .SetStatus (codes .Error , "failed to get attached disks" )
79
+ span .RecordError (err )
72
80
return stacktrace .Propagate (err , "error fetching virtual disks" )
73
81
}
74
82
}
@@ -85,14 +93,21 @@ func PrepareChaos(ctx context.Context, experimentsDetails *experimentTypes.Exper
85
93
switch strings .ToLower (experimentsDetails .Sequence ) {
86
94
case "serial" :
87
95
if err = injectChaosInSerialMode (ctx , experimentsDetails , instanceNamesWithDiskNames , attachedDisksWithInstance , clients , resultDetails , eventsDetails , chaosDetails ); err != nil {
96
+ span .SetStatus (codes .Error , "failed to run chaos in serial mode" )
97
+ span .RecordError (err )
88
98
return stacktrace .Propagate (err , "could not run chaos in serial mode" )
89
99
}
90
100
case "parallel" :
91
101
if err = injectChaosInParallelMode (ctx , experimentsDetails , instanceNamesWithDiskNames , attachedDisksWithInstance , clients , resultDetails , eventsDetails , chaosDetails ); err != nil {
102
+ span .SetStatus (codes .Error , "failed to run chaos in parallel mode" )
103
+ span .RecordError (err )
92
104
return stacktrace .Propagate (err , "could not run chaos in parallel mode" )
93
105
}
94
106
default :
95
- return cerrors.Error {ErrorCode : cerrors .ErrorTypeGeneric , Reason : fmt .Sprintf ("'%s' sequence is not supported" , experimentsDetails .Sequence )}
107
+ span .SetStatus (codes .Error , "sequence is not supported" )
108
+ err := cerrors.Error {ErrorCode : cerrors .ErrorTypeGeneric , Reason : fmt .Sprintf ("'%s' sequence is not supported" , experimentsDetails .Sequence )}
109
+ span .RecordError (err )
110
+ return err
96
111
}
97
112
98
113
//Waiting for the ramp time after chaos injection
@@ -125,6 +140,8 @@ func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experime
125
140
log .Info ("[Chaos]: Detaching the virtual disks from the instances" )
126
141
for instanceName , diskNameList := range instanceNamesWithDiskNames {
127
142
if err = diskStatus .DetachDisks (experimentsDetails .SubscriptionID , experimentsDetails .ResourceGroup , instanceName , experimentsDetails .ScaleSet , diskNameList ); err != nil {
143
+ span .SetStatus (codes .Error , "failed to detach disks" )
144
+ span .RecordError (err )
128
145
return stacktrace .Propagate (err , "failed to detach disks" )
129
146
}
130
147
}
@@ -133,6 +150,8 @@ func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experime
133
150
for _ , diskName := range diskNameList {
134
151
log .Infof ("[Wait]: Waiting for Disk '%v' to detach" , diskName )
135
152
if err := diskStatus .WaitForDiskToDetach (experimentsDetails , diskName ); err != nil {
153
+ span .SetStatus (codes .Error , "failed to detach disks" )
154
+ span .RecordError (err )
136
155
return stacktrace .Propagate (err , "disk detachment check failed" )
137
156
}
138
157
}
@@ -147,6 +166,8 @@ func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experime
147
166
// run the probes during chaos
148
167
if len (resultDetails .ProbeDetails ) != 0 {
149
168
if err := probe .RunProbes (ctx , chaosDetails , clients , resultDetails , "DuringChaos" , eventsDetails ); err != nil {
169
+ span .SetStatus (codes .Error , "failed to run probes" )
170
+ span .RecordError (err )
150
171
return stacktrace .Propagate (err , "failed to run probes" )
151
172
}
152
173
}
@@ -159,6 +180,8 @@ func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experime
159
180
log .Info ("[Chaos]: Attaching the Virtual disks back to the instances" )
160
181
for instanceName , diskNameList := range attachedDisksWithInstance {
161
182
if err = diskStatus .AttachDisk (experimentsDetails .SubscriptionID , experimentsDetails .ResourceGroup , instanceName , experimentsDetails .ScaleSet , diskNameList ); err != nil {
183
+ span .SetStatus (codes .Error , "virtual disk attachment failed" )
184
+ span .RecordError (err )
162
185
return stacktrace .Propagate (err , "virtual disk attachment failed" )
163
186
}
164
187
@@ -167,6 +190,8 @@ func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experime
167
190
for _ , diskName := range diskNameList {
168
191
log .Infof ("[Wait]: Waiting for Disk '%v' to attach" , diskName )
169
192
if err := diskStatus .WaitForDiskToAttach (experimentsDetails , diskName ); err != nil {
193
+ span .SetStatus (codes .Error , "failed to attach disks" )
194
+ span .RecordError (err )
170
195
return stacktrace .Propagate (err , "disk attachment check failed" )
171
196
}
172
197
}
@@ -209,12 +234,16 @@ func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experiment
209
234
// Detaching the virtual disks
210
235
log .Infof ("[Chaos]: Detaching %v from the instance" , diskName )
211
236
if err = diskStatus .DetachDisks (experimentsDetails .SubscriptionID , experimentsDetails .ResourceGroup , instanceName , experimentsDetails .ScaleSet , diskNameToList ); err != nil {
237
+ span .SetStatus (codes .Error , "failed to detach disks" )
238
+ span .RecordError (err )
212
239
return stacktrace .Propagate (err , "failed to detach disks" )
213
240
}
214
241
215
242
// Waiting for disk to be detached
216
243
log .Infof ("[Wait]: Waiting for Disk '%v' to detach" , diskName )
217
244
if err := diskStatus .WaitForDiskToDetach (experimentsDetails , diskName ); err != nil {
245
+ span .SetStatus (codes .Error , "failed to detach disks" )
246
+ span .RecordError (err )
218
247
return stacktrace .Propagate (err , "disk detachment check failed" )
219
248
}
220
249
@@ -235,12 +264,16 @@ func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experiment
235
264
//Attaching the virtual disks to the instance
236
265
log .Infof ("[Chaos]: Attaching %v back to the instance" , diskName )
237
266
if err = diskStatus .AttachDisk (experimentsDetails .SubscriptionID , experimentsDetails .ResourceGroup , instanceName , experimentsDetails .ScaleSet , attachedDisksWithInstance [instanceName ]); err != nil {
267
+ span .SetStatus (codes .Error , "disk attachment failed" )
268
+ span .RecordError (err )
238
269
return stacktrace .Propagate (err , "disk attachment failed" )
239
270
}
240
271
241
272
// Waiting for disk to be attached
242
273
log .Infof ("[Wait]: Waiting for Disk '%v' to attach" , diskName )
243
274
if err := diskStatus .WaitForDiskToAttach (experimentsDetails , diskName ); err != nil {
275
+ span .SetStatus (codes .Error , "failed to attach disks" )
276
+ span .RecordError (err )
244
277
return stacktrace .Propagate (err , "disk attachment check failed" )
245
278
}
246
279
0 commit comments