-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtelemetry.go
69 lines (58 loc) · 2.15 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
69
// Copyright (c) Abstract Machines
// SPDX-License-Identifier: Apache-2.0
package callhome
import (
"context"
"time"
"github.com/lib/pq"
)
type Telemetry struct {
Services pq.StringArray `json:"services,omitempty" db:"services"`
Service string `json:"service,omitempty" db:"service"`
Longitude float64 `json:"longitude,omitempty" db:"longitude"`
Latitude float64 `json:"latitude,omitempty" db:"latitude"`
IpAddress string `json:"-" db:"ip_address"`
Version string `json:"magistrala_version,omitempty" db:"mg_version"`
LastSeen time.Time `json:"last_seen" db:"service_time"`
Country string `json:"country,omitempty" db:"country"`
City string `json:"city,omitempty" db:"city"`
ServiceTime time.Time `json:"timestamp" db:"time"`
}
type TelemetryFilters struct {
From time.Time
To time.Time
Country string
City string
Version string
Service string
}
type PageMetadata struct {
Total uint64
Offset uint64
Limit uint64
}
type TelemetryPage struct {
PageMetadata
Telemetry []Telemetry
}
type CountrySummary struct {
Country string `json:"country" db:"country"`
NoDeployments int `json:"number_of_deployments" db:"count"`
}
type TelemetrySummary struct {
Countries []CountrySummary `json:"countries,omitempty"`
Cities []string `json:"cities,omitempty"`
Services []string `json:"services,omitempty"`
Versions []string `json:"versions,omitempty"`
TotalDeployments int `json:"total_deployments,omitempty"`
}
// TelemetryRepository specifies an account persistence API.
type TelemetryRepo interface {
// Save persists the telemetry event. A non-nil error is returned to indicate
// operation failure.
Save(ctx context.Context, t Telemetry) error
// RetrieveAll retrieves all telemetry events.
RetrieveAll(ctx context.Context, pm PageMetadata, filters TelemetryFilters) (TelemetryPage, error)
// RetrieveSummary gets distinct countries, cities,services and versions in a summarised form.
RetrieveSummary(ctx context.Context, filters TelemetryFilters) (TelemetrySummary, error)
}