@@ -192,11 +192,14 @@ func TestGetSamplerParams(t *testing.T) {
192
192
logger := zap .NewNop ()
193
193
194
194
tests := []struct {
195
+ name string
195
196
tags model.KeyValues
197
+ enableFlag bool
196
198
expectedType model.SamplerType
197
199
expectedParam float64
198
200
}{
199
201
{
202
+ name : "Valid probabilistic sampler with string param" ,
200
203
tags : model.KeyValues {
201
204
model .String ("sampler.type" , "probabilistic" ),
202
205
model .String ("sampler.param" , "1e-05" ),
@@ -205,6 +208,7 @@ func TestGetSamplerParams(t *testing.T) {
205
208
expectedParam : 0.00001 ,
206
209
},
207
210
{
211
+ name : "Valid probabilistic sampler with float64 param" ,
208
212
tags : model.KeyValues {
209
213
model .String ("sampler.type" , "probabilistic" ),
210
214
model .Float64 ("sampler.param" , 0.10404450002098709 ),
@@ -213,6 +217,7 @@ func TestGetSamplerParams(t *testing.T) {
213
217
expectedParam : 0.10404450002098709 ,
214
218
},
215
219
{
220
+ name : "Valid probabilistic sampler with stringified float param" ,
216
221
tags : model.KeyValues {
217
222
model .String ("sampler.type" , "probabilistic" ),
218
223
model .String ("sampler.param" , "0.10404450002098709" ),
@@ -221,6 +226,7 @@ func TestGetSamplerParams(t *testing.T) {
221
226
expectedParam : 0.10404450002098709 ,
222
227
},
223
228
{
229
+ name : "Probabilistic sampler with int64 param" ,
224
230
tags : model.KeyValues {
225
231
model .String ("sampler.type" , "probabilistic" ),
226
232
model .Int64 ("sampler.param" , 1 ),
@@ -229,6 +235,7 @@ func TestGetSamplerParams(t *testing.T) {
229
235
expectedParam : 1.0 ,
230
236
},
231
237
{
238
+ name : "Valid rate limiting sampler" ,
232
239
tags : model.KeyValues {
233
240
model .String ("sampler.type" , "ratelimiting" ),
234
241
model .String ("sampler.param" , "1" ),
@@ -237,25 +244,37 @@ func TestGetSamplerParams(t *testing.T) {
237
244
expectedParam : 1 ,
238
245
},
239
246
{
247
+ name : "Invalid sampler.type (float instead of string)" ,
240
248
tags : model.KeyValues {
241
249
model .Float64 ("sampler.type" , 1.5 ),
242
250
},
243
251
expectedType : model .SamplerTypeUnrecognized ,
244
252
expectedParam : 0 ,
245
253
},
246
254
{
255
+ name : "Probabilistic sampler missing param" ,
247
256
tags : model.KeyValues {
248
257
model .String ("sampler.type" , "probabilistic" ),
249
258
},
250
259
expectedType : model .SamplerTypeUnrecognized ,
251
260
expectedParam : 0 ,
252
261
},
253
262
{
254
- tags : model.KeyValues {},
263
+ name : "No tags, feature flag disabled" ,
264
+ tags : model.KeyValues {},
265
+ enableFlag : false ,
255
266
expectedType : model .SamplerTypeUnrecognized ,
256
267
expectedParam : 0 ,
257
268
},
258
269
{
270
+ name : "No tags, feature flag enabled" ,
271
+ tags : model.KeyValues {},
272
+ enableFlag : true ,
273
+ expectedType : model .SamplerTypeProbabilistic ,
274
+ expectedParam : 1.0 ,
275
+ },
276
+ {
277
+ name : "Lowerbound sampler with string param" ,
259
278
tags : model.KeyValues {
260
279
model .String ("sampler.type" , "lowerbound" ),
261
280
model .String ("sampler.param" , "1" ),
@@ -264,6 +283,7 @@ func TestGetSamplerParams(t *testing.T) {
264
283
expectedParam : 1 ,
265
284
},
266
285
{
286
+ name : "Lowerbound sampler with int64 param" ,
267
287
tags : model.KeyValues {
268
288
model .String ("sampler.type" , "lowerbound" ),
269
289
model .Int64 ("sampler.param" , 1 ),
@@ -272,6 +292,7 @@ func TestGetSamplerParams(t *testing.T) {
272
292
expectedParam : 1 ,
273
293
},
274
294
{
295
+ name : "Lowerbound sampler with float64 param" ,
275
296
tags : model.KeyValues {
276
297
model .String ("sampler.type" , "lowerbound" ),
277
298
model .Float64 ("sampler.param" , 0.5 ),
@@ -280,6 +301,7 @@ func TestGetSamplerParams(t *testing.T) {
280
301
expectedParam : 0.5 ,
281
302
},
282
303
{
304
+ name : "Invalid sampler.param (not a number) for lowerbound" ,
283
305
tags : model.KeyValues {
284
306
model .String ("sampler.type" , "lowerbound" ),
285
307
model .String ("sampler.param" , "not_a_number" ),
@@ -288,6 +310,7 @@ func TestGetSamplerParams(t *testing.T) {
288
310
expectedParam : 0 ,
289
311
},
290
312
{
313
+ name : "Invalid sampler.type and invalid sampler.param" ,
291
314
tags : model.KeyValues {
292
315
model .String ("sampler.type" , "not_a_type" ),
293
316
model .String ("sampler.param" , "not_a_number" ),
@@ -299,12 +322,15 @@ func TestGetSamplerParams(t *testing.T) {
299
322
300
323
for i , test := range tests {
301
324
tt := test
302
- t .Run (strconv .Itoa (i ), func (t * testing.T ) {
303
- span := & model.Span {}
304
- span .Tags = tt .tags
325
+ t .Run (strconv .Itoa (i )+ "_" + tt .name , func (t * testing.T ) {
326
+ // Set the feature flag for this test case
327
+ EnableAdaptiveSamplingWithoutTags = tt .enableFlag
328
+
329
+ span := & model.Span {Tags : tt .tags }
305
330
actualType , actualParam := getSamplerParams (span , logger )
306
- assert .Equal (t , tt .expectedType , actualType )
307
- assert .InDelta (t , tt .expectedParam , actualParam , 0.01 )
331
+
332
+ assert .Equal (t , tt .expectedType , actualType , "Test failed for case: %s" , tt .name )
333
+ assert .InDelta (t , tt .expectedParam , actualParam , 0.01 , "Test failed for case: %s" , tt .name )
308
334
})
309
335
}
310
336
}
0 commit comments