github.com/yankunsam/loki/v2@v2.6.3-0.20220817130409-389df5235c27/pkg/storage/chunk/client/aws/fixtures.go (about)

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