- Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathtelemetry.go
68 lines (53 loc) · 1.66 KB
/
telemetry.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
/*
2021 © Postgres.ai
*/
// Package telemetry contains tools to collect Database Lab Engine data.
package telemetry
import (
"context"
platformSvc "gitlab.com/postgres-ai/database-lab/v3/internal/platform"
"gitlab.com/postgres-ai/database-lab/v3/pkg/client/platform"
"gitlab.com/postgres-ai/database-lab/v3/pkg/log"
)
const (
// EngineStartedEvent defines the engine start event.
EngineStartedEvent="engine_started"
// EngineStoppedEvent describes the engine stop event.
EngineStoppedEvent="engine_stopped"
// CloneCreatedEvent describes the clone creation event.
CloneCreatedEvent="clone_created"
// CloneResetEvent describes the clone reset event.
CloneResetEvent="clone_reset"
// CloneDestroyedEvent describes a clone destruction event.
CloneDestroyedEvent="clone_destroyed"
// SnapshotCreatedEvent describes a snapshot creation event.
SnapshotCreatedEvent="snapshot_created"
// AlertEvent describes alert events.
AlertEvent="alert"
)
// Agent represent a telemetry agent to collect engine data.
typeAgentstruct {
instanceIDstring
platform*platformSvc.Service
}
// New creates a new agent.
funcNew(platformSvc*platformSvc.Service, instanceIDstring) *Agent {
return&Agent{
instanceID: instanceID,
platform: platformSvc,
}
}
// SendEvent sends a telemetry event.
func (a*Agent) SendEvent(ctx context.Context, eventTypestring, payloadinterface{}) {
if!a.platform.IsTelemetryEnabled() {
return
}
_, err:=a.platform.Client.SendTelemetryEvent(ctx, platform.TelemetryEvent{
InstanceID: a.instanceID,
EventType: eventType,
Payload: payload,
})
iferr!=nil {
log.Err("Failed to send telemetry event", err)
}
}