-
Notifications
You must be signed in to change notification settings - Fork 53
/
spec.go
85 lines (72 loc) · 2.95 KB
/
spec.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
package spec
import (
"context"
"github.com/rancher/opni/pkg/alerting/drivers/routing"
"github.com/rancher/opni/pkg/alerting/interfaces"
"github.com/rancher/opni/pkg/alerting/storage/opts"
alertingv1 "github.com/rancher/opni/pkg/apis/alerting/v1"
"google.golang.org/protobuf/types/known/timestamppb"
)
type AlertingStoreBroker interface {
NewClientSet() AlertingClientSet
// Use applies a specific storage client to the matching storage client in the clientset
//
// It is also responsible for migrating existing data if there is an existing store
// of the same type already in use by the clientset
Use(store any)
}
type AlertingClientSet interface {
HashRing
Purge(ctx context.Context) error
Conditions() ConditionStorage
Endpoints() EndpointStorage
Routers() RouterStorage
States() StateStorage
Incidents() IncidentStorage
}
// HashRing Hash ring uniquely maps groups of objects to a (key, hash) pairs
type HashRing interface {
CalculateHash(ctx context.Context, key string, syncOptions *opts.SyncOptions) error
GetHash(ctx context.Context, key string) string
// Sync reads from the client set and updates the router storage in the appropriate way
// It returns the router keys that have changed.
Sync(ctx context.Context, opts ...opts.SyncOption) (routerKeys []string, err error)
ForceSync(ctx context.Context, opts ...opts.SyncOption) error
}
type AlertingStorage[T any] interface {
Put(ctx context.Context, key string, value T) error
Get(ctx context.Context, key string, opts ...opts.RequestOption) (T, error)
Delete(ctx context.Context, key string) error
ListKeys(ctx context.Context) ([]string, error)
List(ctx context.Context, opts ...opts.RequestOption) ([]T, error)
}
type AlertingSecretStorage[T interfaces.AlertingSecret] interface {
AlertingStorage[T]
}
type PartitionedAlertingStorage[T interfaces.AlertingSecret] interface {
Group(id string) AlertingSecretStorage[T]
ListGroups(ctx context.Context) ([]string, error)
}
type (
ConditionStorage = PartitionedAlertingStorage[*alertingv1.AlertCondition]
EndpointStorage = AlertingSecretStorage[*alertingv1.AlertEndpoint]
RouterStorage = AlertingStorage[routing.OpniRouting]
)
type AlertingStateCache[T interfaces.AlertingSecret] interface {
AlertingStorage[T]
IsDiff(ctx context.Context, key string, value T) bool
LastKnownChange(ctx context.Context, key string) (*timestamppb.Timestamp, error)
}
type StateStorage = AlertingStateCache[*alertingv1.CachedState]
type AlertingIncidentTracker[T interfaces.AlertingSecret] interface {
AlertingStorage[T]
OpenInterval(ctx context.Context, conditionId, fingerprint string, start *timestamppb.Timestamp) error
CloseInterval(ctx context.Context, conditionId, fingerprint string, end *timestamppb.Timestamp) error
GetActiveWindowsFromIncidentTracker(
ctx context.Context,
conditionId string,
start,
end *timestamppb.Timestamp,
) ([]*alertingv1.ActiveWindow, error)
}
type IncidentStorage = AlertingIncidentTracker[*alertingv1.IncidentIntervals]