@@ -114,6 +114,7 @@ func TestAppender(t *testing.T) {
114
114
for i := 0 ; i < N ; i ++ {
115
115
addMinimalDoc (t , indexer , "logs-foo-testing" )
116
116
}
117
+ <- time .After (2 * time .Second )
117
118
118
119
// Appender has not been flushed, there is one active bulk indexer.
119
120
// assert.Equal(t, docappender.Stats{Added: N, Active: N, AvailableBulkRequests: 9, IndexersActive: 1}, indexer.Stats())
@@ -269,56 +270,28 @@ func TestAppenderRetry(t *testing.T) {
269
270
)
270
271
271
272
indexer , err := docappender .New (client , docappender.Config {
272
- FlushInterval : time .Minute ,
273
- FlushBytes : 750 , // this is enough to flush after 9 documents
273
+ FlushInterval : 2 * time .Minute ,
274
+ FlushBytes : 800 , // this is enough to flush after 9 documents
274
275
MaxRequests : 1 , // to ensure the test is stable
275
276
MaxDocumentRetries : 1 , // to test the document retry logic
276
- MeterProvider : sdkmetric .NewMeterProvider (sdkmetric .WithReader (rdr )),
277
- MetricAttributes : indexerAttrs ,
277
+ MeterProvider : sdkmetric .NewMeterProvider (
278
+ sdkmetric .WithReader (rdr ),
279
+ ),
280
+ MetricAttributes : indexerAttrs ,
278
281
})
279
282
280
283
require .NoError (t , err )
281
- defer indexer .Close (context .Background ())
284
+ // defer indexer.Close(context.Background())
282
285
283
286
const N = 10
284
287
for i := 0 ; i < N ; i ++ {
285
288
addMinimalDoc (t , indexer , "logs-foo-testing" )
286
289
}
287
-
288
- bulkRequests := func () int64 {
289
- var rm metricdata.ResourceMetrics
290
- assert .NoError (t , rdr .Collect (context .Background (), & rm ))
291
-
292
- var res int64
293
- for _ , m := range rm .ScopeMetrics [0 ].Metrics {
294
- if m .Name == "elasticsearch.bulk_requests.count" {
295
- counter := m .Data .(metricdata.Sum [int64 ])
296
- for _ , dp := range counter .DataPoints {
297
- res += dp .Value
298
- }
299
- }
300
- }
301
-
302
- return res
303
- }
304
- timeout := time .After (4 * time .Second )
305
- loop:
306
- for {
307
- select {
308
- case <- time .After (10 * time .Millisecond ):
309
- // Because the internal channel is buffered to increase performance,
310
- // the available indexer may not take documents right away, loop until
311
- // the available bulk requests has been lowered.
312
- if bulkRequests () == 1 {
313
- break loop
314
- }
315
- case <- timeout :
316
- t .Fatalf ("timed out waiting for the active bulk indexer to send one bulk request" )
317
- }
318
- }
290
+ <- time .After (20 * time .Second )
319
291
320
292
var rm metricdata.ResourceMetrics
321
293
assert .NoError (t , rdr .Collect (context .Background (), & rm ))
294
+ <- time .After (20 * time .Second )
322
295
323
296
var asserted atomic.Int64
324
297
assertCounter := docappendertest .NewAssertCounter (t , & asserted )
@@ -331,7 +304,7 @@ loop:
331
304
case "elasticsearch.events.count" :
332
305
assertCounter (m , int64 (N ), indexerAttrs )
333
306
case "elasticsearch.events.queued" :
334
- assertCounter (m , int64 (2 ), indexerAttrs )
307
+ assertCounter (m , int64 (1 ), indexerAttrs )
335
308
case "elasticsearch.bulk_requests.count" :
336
309
assertCounter (m , int64 (1 ), indexerAttrs )
337
310
case "elasticsearch.events.processed" :
@@ -344,7 +317,7 @@ loop:
344
317
switch status .AsString () {
345
318
case "Success" :
346
319
processedAsserted ++
347
- assert .Equal (t , int64 (6 ), dp .Value )
320
+ assert .Equal (t , int64 (7 ), dp .Value )
348
321
case "FailedClient" :
349
322
processedAsserted ++
350
323
assert .Equal (t , int64 (1 ), dp .Value )
@@ -378,7 +351,7 @@ loop:
378
351
attribute .Int ("greatest_retry" , 1 ),
379
352
))
380
353
case "elasticsearch.bulk_requests.available" :
381
- assertCounter (m , int64 (0 ), indexerAttrs )
354
+ assertCounter (m , int64 (1 ), indexerAttrs )
382
355
case "elasticsearch.flushed.bytes" :
383
356
assertCounter (m , bytesTotal , indexerAttrs )
384
357
case "elasticsearch.flushed.uncompressed.bytes" :
@@ -2047,7 +2020,6 @@ func TestAppenderScaling(t *testing.T) {
2047
2020
case "Success" :
2048
2021
assert .Equal (t , int64 (docs ), dp .Value )
2049
2022
default :
2050
- fmt .Println ("HELLO" )
2051
2023
assert .FailNow (t , "Unexpected metric with status: " + status .AsString ())
2052
2024
}
2053
2025
}
0 commit comments