@@ -34,6 +34,10 @@ import (
3434
3535 "github.com/efficientgo/core/testutil"
3636
37+ "github.com/thanos-io/objstore"
38+ "github.com/thanos-io/objstore/client"
39+ "github.com/thanos-io/objstore/providers/s3"
40+
3741 "github.com/thanos-io/thanos/pkg/exemplars/exemplarspb"
3842 "github.com/thanos-io/thanos/pkg/promclient"
3943 "github.com/thanos-io/thanos/pkg/receive"
@@ -1390,3 +1394,59 @@ func TestReceiveWithRelabelConfigSmoke(t *testing.T) {
13901394 e2emon .WaitMissingMetrics (),
13911395 ))
13921396}
1397+
1398+ func TestReceiveUploadOnShutdown (t * testing.T ) {
1399+ t .Parallel ()
1400+
1401+ e , err := e2e .NewDockerEnvironment ("receive-u-s" )
1402+ testutil .Ok (t , err )
1403+ t .Cleanup (e2ethanos .CleanScenario (t , e ))
1404+
1405+ const bucket = "receive-upload-shutdown-test"
1406+ m := e2edb .NewMinio (e , "thanos-minio" , bucket , e2edb .WithMinioTLS ())
1407+ testutil .Ok (t , e2e .StartAndWaitReady (m ))
1408+
1409+ bktConfig := client.BucketConfig {
1410+ Type : objstore .S3 ,
1411+ Config : e2ethanos .NewS3Config (bucket , m .InternalEndpoint ("http" ), m .InternalDir ()),
1412+ }
1413+
1414+ i := e2ethanos .NewReceiveBuilder (e , "ingestor" ).
1415+ WithIngestionEnabled ().
1416+ WithObjStoreConfig (bktConfig ).
1417+ Init ()
1418+ testutil .Ok (t , e2e .StartAndWaitReady (i ))
1419+
1420+ ctx , cancel := context .WithTimeout (context .Background (), 3 * time .Minute )
1421+ t .Cleanup (cancel )
1422+
1423+ require .NoError (t , runutil .RetryWithLog (logkit .NewLogfmtLogger (os .Stdout ), 1 * time .Second , ctx .Done (), func () error {
1424+ return storeWriteRequest (ctx , "http://" + i .Endpoint ("remote-write" )+ "/api/v1/receive" , & prompb.WriteRequest {
1425+ Timeseries : []prompb.TimeSeries {
1426+ {
1427+ Labels : []prompb.Label {
1428+ {Name : "__name__" , Value : "upload_test_metric" },
1429+ {Name : "foo" , Value : "bar" },
1430+ },
1431+ Samples : []prompb.Sample {
1432+ {Value : 1 , Timestamp : time .Now ().UnixMilli ()},
1433+ },
1434+ },
1435+ },
1436+ })
1437+ }))
1438+
1439+ testutil .Ok (t , i .Stop ())
1440+
1441+ l := logkit .NewLogfmtLogger (os .Stdout )
1442+ bkt , err := s3 .NewBucketWithConfig (l ,
1443+ e2ethanos .NewS3Config (bucket , m .Endpoint ("http" ), m .Dir ()), "test-verify" , nil )
1444+ testutil .Ok (t , err )
1445+
1446+ var blockCount int
1447+ testutil .Ok (t , bkt .Iter (ctx , "" , func (_ string ) error {
1448+ blockCount ++
1449+ return nil
1450+ }))
1451+ require .Greater (t , blockCount , 0 , "expected at least one block uploaded to object storage after receiver shutdown" )
1452+ }
0 commit comments