@@ -16,6 +16,10 @@ import (
16
16
17
17
"github.com/grafana/loki/v3/pkg/distributor"
18
18
"github.com/grafana/loki/v3/pkg/loki/common"
19
+ azurebucket "github.com/grafana/loki/v3/pkg/storage/bucket/azure"
20
+ "github.com/grafana/loki/v3/pkg/storage/bucket/filesystem"
21
+ "github.com/grafana/loki/v3/pkg/storage/bucket/gcs"
22
+ "github.com/grafana/loki/v3/pkg/storage/bucket/s3"
19
23
"github.com/grafana/loki/v3/pkg/storage/bucket/swift"
20
24
"github.com/grafana/loki/v3/pkg/storage/chunk/client/alibaba"
21
25
"github.com/grafana/loki/v3/pkg/storage/chunk/client/aws"
@@ -842,6 +846,48 @@ storage_config:
842
846
assert .Equal (t , "789abc" , config .StorageConfig .NamedStores .AWS ["store-2" ].S3Config .SecretAccessKey .String ())
843
847
})
844
848
849
+ t .Run ("named storage config (thanos) provided via config file is preserved" , func (t * testing.T ) {
850
+ namedStoresConfig := `common:
851
+ storage:
852
+ object_store:
853
+ s3:
854
+ endpoint: s3://common-bucket
855
+ region: us-east1
856
+ access_key_id: abc123
857
+ secret_access_key: def789
858
+ storage_config:
859
+ object_store:
860
+ named_stores:
861
+ s3:
862
+ store-1:
863
+ endpoint: s3://foo-bucket
864
+ region: us-west1
865
+ access_key_id: 123abc
866
+ secret_access_key: 789def
867
+ store-2:
868
+ endpoint: s3://bar-bucket
869
+ region: us-west2
870
+ access_key_id: 456def
871
+ secret_access_key: 789abc`
872
+ config , _ := testContext (namedStoresConfig , nil )
873
+
874
+ // should be set by common config
875
+ assert .Equal (t , "s3://common-bucket" , config .StorageConfig .ObjectStore .S3 .Endpoint )
876
+ assert .Equal (t , "us-east1" , config .StorageConfig .ObjectStore .S3 .Region )
877
+ assert .Equal (t , "abc123" , config .StorageConfig .ObjectStore .S3 .AccessKeyID )
878
+ assert .Equal (t , "def789" , config .StorageConfig .ObjectStore .S3 .SecretAccessKey .String ())
879
+
880
+ assert .Equal (t , "s3://foo-bucket" , config .StorageConfig .ObjectStore .NamedStores .S3 ["store-1" ].Endpoint )
881
+ assert .Equal (t , "us-west1" , config .StorageConfig .ObjectStore .NamedStores .S3 ["store-1" ].Region )
882
+ assert .Equal (t , "123abc" , config .StorageConfig .ObjectStore .NamedStores .S3 ["store-1" ].AccessKeyID )
883
+ assert .Equal (t , "789def" , config .StorageConfig .ObjectStore .NamedStores .S3 ["store-1" ].SecretAccessKey .String ())
884
+
885
+ assert .Equal (t , "s3://bar-bucket" , config .StorageConfig .ObjectStore .NamedStores .S3 ["store-2" ].Endpoint )
886
+ assert .Equal (t , "us-west2" , config .StorageConfig .ObjectStore .NamedStores .S3 ["store-2" ].Region )
887
+ assert .Equal (t , "456def" , config .StorageConfig .ObjectStore .NamedStores .S3 ["store-2" ].AccessKeyID )
888
+ assert .Equal (t , "789abc" , config .StorageConfig .ObjectStore .NamedStores .S3 ["store-2" ].SecretAccessKey .String ())
889
+ })
890
+
845
891
t .Run ("partial ruler config from file is honored for overriding things like bucket names" , func (t * testing.T ) {
846
892
specificRulerConfig := `common:
847
893
storage:
@@ -2280,3 +2326,91 @@ func TestNamedStores_applyDefaults(t *testing.T) {
2280
2326
assert .Equal (t , expected , (alibaba .OssConfig )(nsCfg .AlibabaCloud ["store-8" ]))
2281
2327
})
2282
2328
}
2329
+
2330
+ func TestBucketNamedStores_applyDefaults (t * testing.T ) {
2331
+ namedStoresConfig := `storage_config:
2332
+ object_store:
2333
+ named_stores:
2334
+ s3:
2335
+ store-1:
2336
+ endpoint: s3.test
2337
+ bucket_name: foobar
2338
+ dualstack_enabled: false
2339
+ azure:
2340
+ store-2:
2341
+ account_name: foo
2342
+ container_name: bar
2343
+ max_retries: 3
2344
+ gcs:
2345
+ store-3:
2346
+ bucket_name: foobar
2347
+ filesystem:
2348
+ store-4:
2349
+ dir: foobar
2350
+ swift:
2351
+ store-5:
2352
+ container_name: foobar
2353
+ request_timeout: 30s
2354
+ `
2355
+ // make goconst happy
2356
+ bucketName := "foobar"
2357
+
2358
+ config , defaults , err := configWrapperFromYAML (t , namedStoresConfig , nil )
2359
+ require .NoError (t , err )
2360
+
2361
+ nsCfg := config .StorageConfig .ObjectStore .NamedStores
2362
+
2363
+ t .Run ("s3" , func (t * testing.T ) {
2364
+ assert .Len (t , nsCfg .S3 , 1 )
2365
+
2366
+ // expect the defaults to be set on named store config
2367
+ expected := defaults .StorageConfig .ObjectStore .S3
2368
+ expected .BucketName = bucketName
2369
+ expected .Endpoint = "s3.test"
2370
+ // override defaults
2371
+ expected .DualstackEnabled = false
2372
+
2373
+ assert .Equal (t , expected , (s3 .Config )(nsCfg .S3 ["store-1" ]))
2374
+ })
2375
+
2376
+ t .Run ("azure" , func (t * testing.T ) {
2377
+ assert .Len (t , nsCfg .Azure , 1 )
2378
+
2379
+ expected := defaults .StorageConfig .ObjectStore .Azure
2380
+ expected .StorageAccountName = "foo"
2381
+ expected .ContainerName = "bar"
2382
+ // overrides defaults
2383
+ expected .MaxRetries = 3
2384
+
2385
+ assert .Equal (t , expected , (azurebucket .Config )(nsCfg .Azure ["store-2" ]))
2386
+ })
2387
+
2388
+ t .Run ("gcs" , func (t * testing.T ) {
2389
+ assert .Len (t , nsCfg .GCS , 1 )
2390
+
2391
+ expected := defaults .StorageConfig .ObjectStore .GCS
2392
+ expected .BucketName = bucketName
2393
+
2394
+ assert .Equal (t , expected , (gcs .Config )(nsCfg .GCS ["store-3" ]))
2395
+ })
2396
+
2397
+ t .Run ("filesystem" , func (t * testing.T ) {
2398
+ assert .Len (t , nsCfg .Filesystem , 1 )
2399
+
2400
+ expected := defaults .StorageConfig .ObjectStore .Filesystem
2401
+ expected .Directory = bucketName
2402
+
2403
+ assert .Equal (t , expected , (filesystem .Config )(nsCfg .Filesystem ["store-4" ]))
2404
+ })
2405
+
2406
+ t .Run ("swift" , func (t * testing.T ) {
2407
+ assert .Len (t , nsCfg .Swift , 1 )
2408
+
2409
+ expected := defaults .StorageConfig .ObjectStore .Swift
2410
+ expected .ContainerName = bucketName
2411
+ // override defaults
2412
+ expected .RequestTimeout = 30 * time .Second
2413
+
2414
+ assert .Equal (t , expected , (swift .Config )(nsCfg .Swift ["store-5" ]))
2415
+ })
2416
+ }
0 commit comments