github.com/sequix/cortex@v1.1.6/pkg/chunk/aws/fixtures.go (about)

     1  package aws
     2  
     3  import (
     4  	"fmt"
     5  	"time"
     6  
     7  	"golang.org/x/time/rate"
     8  
     9  	"github.com/sequix/cortex/pkg/chunk"
    10  	"github.com/sequix/cortex/pkg/chunk/testutils"
    11  	"github.com/sequix/cortex/pkg/util"
    12  )
    13  
    14  type fixture struct {
    15  	name    string
    16  	clients func() (chunk.IndexClient, chunk.ObjectClient, chunk.TableClient, chunk.SchemaConfig, error)
    17  }
    18  
    19  func (f fixture) Name() string {
    20  	return f.name
    21  }
    22  
    23  func (f fixture) Clients() (chunk.IndexClient, chunk.ObjectClient, chunk.TableClient, chunk.SchemaConfig, error) {
    24  	return f.clients()
    25  }
    26  
    27  func (f fixture) Teardown() error {
    28  	return nil
    29  }
    30  
    31  // Fixtures for testing the various configuration of AWS storage.
    32  var Fixtures = []testutils.Fixture{
    33  	fixture{
    34  		name: "S3 chunks",
    35  		clients: func() (chunk.IndexClient, chunk.ObjectClient, chunk.TableClient, chunk.SchemaConfig, error) {
    36  			schemaConfig := testutils.DefaultSchemaConfig("s3")
    37  			dynamoDB := newMockDynamoDB(0, 0)
    38  			table := &dynamoTableClient{
    39  				DynamoDB: dynamoDB,
    40  			}
    41  			index := &dynamoDBStorageClient{
    42  				DynamoDB:                dynamoDB,
    43  				queryRequestFn:          dynamoDB.queryRequest,
    44  				batchGetItemRequestFn:   dynamoDB.batchGetItemRequest,
    45  				batchWriteItemRequestFn: dynamoDB.batchWriteItemRequest,
    46  				schemaCfg:               schemaConfig,
    47  			}
    48  			object := &s3ObjectClient{
    49  				S3: newMockS3(),
    50  			}
    51  			return index, object, table, schemaConfig, nil
    52  		},
    53  	},
    54  	dynamoDBFixture(0, 10, 20),
    55  	dynamoDBFixture(0, 0, 20),
    56  	dynamoDBFixture(2, 10, 20),
    57  }
    58  
    59  func dynamoDBFixture(provisionedErr, gangsize, maxParallelism int) testutils.Fixture {
    60  	return fixture{
    61  		name: fmt.Sprintf("DynamoDB chunks provisionedErr=%d, ChunkGangSize=%d, ChunkGetMaxParallelism=%d",
    62  			provisionedErr, gangsize, maxParallelism),
    63  		clients: func() (chunk.IndexClient, chunk.ObjectClient, chunk.TableClient, chunk.SchemaConfig, error) {
    64  			dynamoDB := newMockDynamoDB(0, provisionedErr)
    65  			schemaCfg := testutils.DefaultSchemaConfig("aws")
    66  			table := &dynamoTableClient{
    67  				DynamoDB: dynamoDB,
    68  			}
    69  			storage := &dynamoDBStorageClient{
    70  				cfg: DynamoDBConfig{
    71  					ChunkGangSize:          gangsize,
    72  					ChunkGetMaxParallelism: maxParallelism,
    73  					backoffConfig: util.BackoffConfig{
    74  						MinBackoff: 1 * time.Millisecond,
    75  						MaxBackoff: 5 * time.Millisecond,
    76  						MaxRetries: 20,
    77  					},
    78  				},
    79  				DynamoDB:                dynamoDB,
    80  				writeThrottle:           rate.NewLimiter(10, dynamoDBMaxWriteBatchSize),
    81  				queryRequestFn:          dynamoDB.queryRequest,
    82  				batchGetItemRequestFn:   dynamoDB.batchGetItemRequest,
    83  				batchWriteItemRequestFn: dynamoDB.batchWriteItemRequest,
    84  				schemaCfg:               schemaCfg,
    85  			}
    86  			return storage, storage, table, schemaCfg, nil
    87  		},
    88  	}
    89  }