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