@ -1,6 +1,7 @@
package loki
import (
"fmt"
"path/filepath"
"testing"
"time"
@ -161,33 +162,34 @@ func TestMultiKVSetup(t *testing.T) {
}
}
func TestIndexGatewayRingMode_when_TargetIsRead ( t * testing . T ) {
func TestIndexGatewayRingMode_when_TargetIsLegacy ReadOrBacken d ( t * testing . T ) {
dir := t . TempDir ( )
t . Run ( "IndexGateway always set to ring mode when running as part of read target" , func ( t * testing . T ) {
cfg := minimalWorkingConfig ( t , dir , Read )
c , err := New ( cfg )
require . NoError ( t , err )
services , err := c . ModuleManager . InitModuleServices ( Read )
defer func ( ) {
for _ , service := range services {
service . StopAsync ( )
}
} ( )
require . NoError ( t , err )
assert . Equal ( t , c . Cfg . IndexGateway . Mode , indexgateway . RingMode )
} )
type ringModeTestCase struct {
name string
transformer func ( cfg * Config )
target string
}
t . Run ( "When IndexGateway is running independent of Read target" , func ( t * testing . T ) {
t . Run ( "IndexGateway respects configured simple mode" , func ( t * testing . T ) {
cfg := minimalWorkingConfig ( t , dir , IndexGatewayRing )
cfg . IndexGateway . Mode = indexgateway . SimpleMode
for _ , tc := range [ ] ringModeTestCase {
{
name : "leagcy read" ,
target : Read ,
} ,
{
name : "backend" ,
target : Backend ,
transformer : func ( cfg * Config ) {
cfg . LegacyReadTarget = false
} ,
} ,
} {
t . Run ( fmt . Sprintf ( "IndexGateway always set to ring mode when running as part of %s" , tc . name ) , func ( t * testing . T ) {
cfg := minimalWorkingConfig ( t , dir , tc . target , tc . transformer )
c , err := New ( cfg )
require . NoError ( t , err )
services , err := c . ModuleManager . InitModuleServices ( IndexGateway )
services , err := c . ModuleManager . InitModuleServices ( Read )
defer func ( ) {
for _ , service := range services {
service . StopAsync ( )
@ -195,33 +197,71 @@ func TestIndexGatewayRingMode_when_TargetIsRead(t *testing.T) {
} ( )
require . NoError ( t , err )
assert . Equal ( t , c . Cfg . IndexGateway . Mode , indexgateway . Simple Mode)
assert . Equal ( t , c . Cfg . IndexGateway . Mode , indexgateway . Ring Mode)
} )
}
t . Run ( "IndexGateway respects configured ring mode" , func ( t * testing . T ) {
cfg := minimalWorkingConfig ( t , dir , IndexGatewayRing )
cfg . IndexGateway . Mode = indexgateway . RingMode
c , err := New ( cfg )
require . NoError ( t , err )
services , err := c . ModuleManager . InitModuleServices ( IndexGateway )
defer func ( ) {
for _ , service := range services {
service . StopAsync ( )
}
} ( )
type indexModeTestCase struct {
name string
target string
transformer func ( cfg * Config )
}
require . NoError ( t , err )
assert . Equal ( t , c . Cfg . IndexGateway . Mode , indexgateway . RingMode )
for _ , tc := range [ ] indexModeTestCase {
{
name : "index gateway" ,
target : IndexGateway ,
} ,
{
name : "new read target" ,
target : Read ,
transformer : func ( cfg * Config ) {
cfg . LegacyReadTarget = false
} ,
} ,
} {
t . Run ( fmt . Sprintf ( "When target is %s" , tc . name ) , func ( t * testing . T ) {
t . Run ( "IndexGateway config respects configured simple mode" , func ( t * testing . T ) {
cfg := minimalWorkingConfig ( t , dir , IndexGatewayRing , tc . transformer )
cfg . IndexGateway . Mode = indexgateway . SimpleMode
c , err := New ( cfg )
require . NoError ( t , err )
services , err := c . ModuleManager . InitModuleServices ( IndexGateway )
defer func ( ) {
for _ , service := range services {
service . StopAsync ( )
}
} ( )
require . NoError ( t , err )
assert . Equal ( t , c . Cfg . IndexGateway . Mode , indexgateway . SimpleMode )
} )
t . Run ( "IndexGateway config respects configured ring mode" , func ( t * testing . T ) {
cfg := minimalWorkingConfig ( t , dir , IndexGatewayRing )
cfg . IndexGateway . Mode = indexgateway . RingMode
c , err := New ( cfg )
require . NoError ( t , err )
services , err := c . ModuleManager . InitModuleServices ( IndexGateway )
defer func ( ) {
for _ , service := range services {
service . StopAsync ( )
}
} ( )
require . NoError ( t , err )
assert . Equal ( t , c . Cfg . IndexGateway . Mode , indexgateway . RingMode )
} )
} )
} )
}
}
func TestIndexGatewayClientConfig_when_TargetIsQuerierOrRead ( t * testing . T ) {
func TestIndexGatewayClientConfig ( t * testing . T ) {
dir := t . TempDir ( )
t . Run ( "IndexGateway client is disabled when running querier target" , func ( t * testing . T ) {
t . Run ( "IndexGateway client is en abled when running querier target" , func ( t * testing . T ) {
cfg := minimalWorkingConfig ( t , dir , Querier )
cfg . SchemaConfig . Configs [ 0 ] . IndexType = config . BoltDBShipperType
cfg . SchemaConfig . Configs [ 0 ] . IndexTables . Period = 24 * time . Hour
@ -240,8 +280,56 @@ func TestIndexGatewayClientConfig_when_TargetIsQuerierOrRead(t *testing.T) {
assert . False ( t , c . Cfg . StorageConfig . TSDBShipperConfig . IndexGatewayClientConfig . Disabled )
} )
t . Run ( "IndexGateway client is endabled when running read target" , func ( t * testing . T ) {
cfg := minimalWorkingConfig ( t , dir , Read )
t . Run ( "IndexGateway client is disabled when running legacy read target" , func ( t * testing . T ) {
cfg := minimalWorkingConfig ( t , dir , Read , func ( cfg * Config ) {
cfg . LegacyReadTarget = true
} )
cfg . SchemaConfig . Configs [ 0 ] . IndexType = config . BoltDBShipperType
cfg . SchemaConfig . Configs [ 0 ] . IndexTables . Period = 24 * time . Hour
cfg . CompactorConfig . SharedStoreType = config . StorageTypeFileSystem
cfg . CompactorConfig . WorkingDirectory = dir
c , err := New ( cfg )
require . NoError ( t , err )
services , err := c . ModuleManager . InitModuleServices ( Read )
defer func ( ) {
for _ , service := range services {
service . StopAsync ( )
}
} ( )
require . NoError ( t , err )
assert . True ( t , c . Cfg . StorageConfig . BoltDBShipperConfig . IndexGatewayClientConfig . Disabled )
assert . True ( t , c . Cfg . StorageConfig . TSDBShipperConfig . IndexGatewayClientConfig . Disabled )
} )
t . Run ( "IndexGateway client is enabled when running new read target" , func ( t * testing . T ) {
cfg := minimalWorkingConfig ( t , dir , Read , func ( cfg * Config ) {
cfg . LegacyReadTarget = false
} )
cfg . SchemaConfig . Configs [ 0 ] . IndexType = config . BoltDBShipperType
cfg . SchemaConfig . Configs [ 0 ] . IndexTables . Period = 24 * time . Hour
cfg . CompactorConfig . SharedStoreType = config . StorageTypeFileSystem
cfg . CompactorConfig . WorkingDirectory = dir
c , err := New ( cfg )
require . NoError ( t , err )
services , err := c . ModuleManager . InitModuleServices ( Read )
defer func ( ) {
for _ , service := range services {
service . StopAsync ( )
}
} ( )
require . NoError ( t , err )
assert . False ( t , c . Cfg . StorageConfig . BoltDBShipperConfig . IndexGatewayClientConfig . Disabled )
assert . False ( t , c . Cfg . StorageConfig . TSDBShipperConfig . IndexGatewayClientConfig . Disabled )
} )
t . Run ( "IndexGateway client is disabled when running backend target" , func ( t * testing . T ) {
cfg := minimalWorkingConfig ( t , dir , Backend , func ( cfg * Config ) {
cfg . LegacyReadTarget = false
} )
cfg . SchemaConfig . Configs [ 0 ] . IndexType = config . BoltDBShipperType
cfg . SchemaConfig . Configs [ 0 ] . IndexTables . Period = 24 * time . Hour
cfg . CompactorConfig . SharedStoreType = config . StorageTypeFileSystem
@ -264,7 +352,7 @@ func TestIndexGatewayClientConfig_when_TargetIsQuerierOrRead(t *testing.T) {
const localhost = "localhost"
func minimalWorkingConfig ( t * testing . T , dir , target string ) Config {
func minimalWorkingConfig ( t * testing . T , dir , target string , cfgTransformers ... func ( * Config ) ) Config {
prepareGlobalMetricsRegistry ( t )
cfg := Config { }
@ -315,5 +403,12 @@ func minimalWorkingConfig(t *testing.T, dir, target string) Config {
cfg . Ruler . Config . StoreConfig . Local . Directory = dir
cfg . Common . CompactorAddress = "http://localhost:0"
for _ , transformer := range cfgTransformers {
if transformer != nil {
transformer ( & cfg )
}
}
return cfg
}