github.com/thanos-io/thanos@v0.32.5/pkg/component/component.go (about)

     1  // Copyright (c) The Thanos Authors.
     2  // Licensed under the Apache License 2.0.
     3  
     4  package component
     5  
     6  import (
     7  	"strings"
     8  
     9  	"github.com/thanos-io/thanos/pkg/store/storepb"
    10  )
    11  
    12  // Component is a generic component interface.
    13  type Component interface {
    14  	String() string
    15  }
    16  
    17  // StoreAPI is a component that implements Thanos' gRPC StoreAPI.
    18  type StoreAPI interface {
    19  	implementsStoreAPI()
    20  	String() string
    21  	ToProto() storepb.StoreType
    22  }
    23  
    24  // Source is a Thanos component that produce blocks of metrics.
    25  type Source interface {
    26  	producesBlocks()
    27  	String() string
    28  }
    29  
    30  // SourceStoreAPI is a component that implements Thanos' gRPC StoreAPI
    31  // and produce blocks of metrics.
    32  type SourceStoreAPI interface {
    33  	implementsStoreAPI()
    34  	producesBlocks()
    35  	String() string
    36  	ToProto() storepb.StoreType
    37  }
    38  
    39  type component struct {
    40  	name string
    41  }
    42  
    43  func (c component) String() string { return c.name }
    44  
    45  type storeAPI struct {
    46  	component
    47  }
    48  
    49  func (storeAPI) implementsStoreAPI() {}
    50  
    51  func (s sourceStoreAPI) ToProto() storepb.StoreType {
    52  	return storepb.StoreType(storepb.StoreType_value[strings.ToUpper(s.String())])
    53  }
    54  
    55  func (s storeAPI) ToProto() storepb.StoreType {
    56  	return storepb.StoreType(storepb.StoreType_value[strings.ToUpper(s.String())])
    57  }
    58  
    59  type source struct {
    60  	component
    61  }
    62  
    63  func (source) producesBlocks() {}
    64  
    65  type sourceStoreAPI struct {
    66  	component
    67  	source
    68  	storeAPI
    69  }
    70  
    71  // FromProto converts from a gRPC StoreType to StoreAPI.
    72  func FromProto(storeType storepb.StoreType) StoreAPI {
    73  	switch storeType {
    74  	case storepb.StoreType_QUERY:
    75  		return Query
    76  	case storepb.StoreType_RULE:
    77  		return Rule
    78  	case storepb.StoreType_SIDECAR:
    79  		return Sidecar
    80  	case storepb.StoreType_STORE:
    81  		return Store
    82  	case storepb.StoreType_RECEIVE:
    83  		return Receive
    84  	case storepb.StoreType_DEBUG:
    85  		return Debug
    86  	default:
    87  		return UnknownStoreAPI
    88  	}
    89  }
    90  
    91  func FromString(storeType string) StoreAPI {
    92  	switch storeType {
    93  	case "query":
    94  		return Query
    95  	case "rule":
    96  		return Rule
    97  	case "sidecar":
    98  		return Sidecar
    99  	case "store":
   100  		return Store
   101  	case "receive":
   102  		return Receive
   103  	case "debug":
   104  		return Debug
   105  	default:
   106  		return UnknownStoreAPI
   107  	}
   108  }
   109  
   110  var (
   111  	Bucket          = source{component: component{name: "bucket"}}
   112  	Cleanup         = source{component: component{name: "cleanup"}}
   113  	Mark            = source{component: component{name: "mark"}}
   114  	Rewrite         = source{component: component{name: "rewrite"}}
   115  	Retention       = source{component: component{name: "retention"}}
   116  	Compact         = source{component: component{name: "compact"}}
   117  	Downsample      = source{component: component{name: "downsample"}}
   118  	Replicate       = source{component: component{name: "replicate"}}
   119  	QueryFrontend   = source{component: component{name: "query-frontend"}}
   120  	Debug           = sourceStoreAPI{component: component{name: "debug"}}
   121  	Receive         = sourceStoreAPI{component: component{name: "receive"}}
   122  	Rule            = sourceStoreAPI{component: component{name: "rule"}}
   123  	Sidecar         = sourceStoreAPI{component: component{name: "sidecar"}}
   124  	Store           = storeAPI{component: component{name: "store"}}
   125  	UnknownStoreAPI = storeAPI{component: component{name: "unknown-store-api"}}
   126  	Query           = storeAPI{component: component{name: "query"}}
   127  )