Skip to content

Commit a485e58

Browse files
🔭 emit template creation events (cyclops-ui#533)
* emit template creation events * disable telemetry in dev * ⚙️ update cyclops to v0.10.0-rc-telemetry --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent ea8acd7 commit a485e58

File tree

9 files changed

+75
-9
lines changed

9 files changed

+75
-9
lines changed

.github/workflows/ci.yml

+2
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ jobs:
8686
with:
8787
context: "{{defaultContext}}:cyclops-ctrl"
8888
platforms: linux/amd64,linux/arm64
89+
build-args: |
90+
VERSION=${{ github.event.inputs.version }}
8991
push: true
9092
tags: cyclopsui/cyclops-ctrl:${{ github.event.inputs.version }}
9193

cyclops-ctrl/.env

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
DISABLE_TELEMETRY=true
22
PORT=8888
3-
WATCH_NAMESPACE=cyclops
3+
WATCH_NAMESPACE=cyclops
4+
CYCLOPS_VERSION=v0.0.0

cyclops-ctrl/Dockerfile

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ RUN go build -o /build/bin ./...
1313

1414
FROM alpine:3.20.0
1515

16+
ARG VERSION
17+
ENV CYCLOPS_VERSION=$VERSION
18+
1619
WORKDIR /app
1720

1821
RUN mkdir /app/bin

cyclops-ctrl/cmd/main/main.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ func main() {
6363

6464
setupLog.Info("starting handler")
6565

66-
telemetryClient, _ := telemetry.NewClient(getEnvBool("DISABLE_TELEMETRY"), setupLog)
66+
telemetryClient, _ := telemetry.NewClient(
67+
getEnvBool("DISABLE_TELEMETRY"),
68+
os.Getenv("CYCLOPS_VERSION"),
69+
setupLog,
70+
)
6771
telemetryClient.InstanceStart()
6872

6973
k8sClient, err := k8sclient.New()

cyclops-ctrl/internal/controller/templates.go

+8
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,25 @@ import (
1212
"github.com/cyclops-ui/cyclops/cyclops-ctrl/internal/cluster/k8sclient"
1313
"github.com/cyclops-ui/cyclops/cyclops-ctrl/internal/mapper"
1414
"github.com/cyclops-ui/cyclops/cyclops-ctrl/internal/models/dto"
15+
"github.com/cyclops-ui/cyclops/cyclops-ctrl/internal/telemetry"
1516
"github.com/cyclops-ui/cyclops/cyclops-ctrl/internal/template"
1617
)
1718

1819
type Templates struct {
1920
templatesRepo *template.Repo
2021
kubernetesClient *k8sclient.KubernetesClient
22+
telemetryClient telemetry.Client
2123
}
2224

2325
func NewTemplatesController(
2426
templatesRepo *template.Repo,
2527
kubernetes *k8sclient.KubernetesClient,
28+
telemetryClient telemetry.Client,
2629
) *Templates {
2730
return &Templates{
2831
templatesRepo: templatesRepo,
2932
kubernetesClient: kubernetes,
33+
telemetryClient: telemetryClient,
3034
}
3135
}
3236

@@ -136,6 +140,8 @@ func (c *Templates) CreateTemplatesStore(ctx *gin.Context) {
136140

137141
k8sTemplateStore := mapper.DTOToTemplateStore(*templateStore, tmpl.IconURL)
138142

143+
c.telemetryClient.TemplateCreation()
144+
139145
if err := c.kubernetesClient.CreateTemplateStore(k8sTemplateStore); err != nil {
140146
ctx.JSON(http.StatusInternalServerError, dto.NewError("Error creating module", err.Error()))
141147
return
@@ -174,6 +180,8 @@ func (c *Templates) EditTemplatesStore(ctx *gin.Context) {
174180

175181
k8sTemplateStore := mapper.DTOToTemplateStore(*templateStore, tmpl.IconURL)
176182

183+
c.telemetryClient.TemplateEdit()
184+
177185
if err := c.kubernetesClient.UpdateTemplateStore(k8sTemplateStore); err != nil {
178186
ctx.JSON(http.StatusInternalServerError, dto.NewError("Error creating module", err.Error()))
179187
return

cyclops-ctrl/internal/handler/handler.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func New(
4444
func (h *Handler) Start() error {
4545
gin.SetMode(gin.DebugMode)
4646

47-
templatesController := controller.NewTemplatesController(h.templatesRepo, h.k8sClient)
47+
templatesController := controller.NewTemplatesController(h.templatesRepo, h.k8sClient, h.telemetryClient)
4848
modulesController := controller.NewModulesController(h.templatesRepo, h.k8sClient, h.renderer, h.telemetryClient, h.monitor)
4949
clusterController := controller.NewClusterController(h.k8sClient)
5050

cyclops-ctrl/internal/telemetry/client.go

+42-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ type Client interface {
99
ModuleCreation()
1010
ModuleReconciliation()
1111
InstanceStart()
12+
TemplateCreation()
13+
TemplateEdit()
1214
}
1315

1416
type logger interface {
@@ -19,11 +21,12 @@ type logger interface {
1921
type EnqueueClient struct {
2022
client posthog.Client
2123
distinctID string
24+
version string
2225
}
2326

2427
type MockClient struct{}
2528

26-
func NewClient(disable bool, logger logger) (Client, error) {
29+
func NewClient(disable bool, version string, logger logger) (Client, error) {
2730
if disable {
2831
logger.Info("telemetry disabled")
2932
return MockClient{}, nil
@@ -53,30 +56,62 @@ func NewClient(disable bool, logger logger) (Client, error) {
5356
return EnqueueClient{
5457
client: client,
5558
distinctID: idStr,
59+
version: version,
5660
}, nil
5761
}
5862

5963
func (c EnqueueClient) InstanceStart() {
6064
_ = c.client.Enqueue(posthog.Capture{
6165
Event: "cyclops-instance-start",
6266
DistinctId: c.distinctID,
67+
Properties: map[string]interface{}{
68+
"version": c.version,
69+
},
6370
})
6471
}
6572

6673
func (c EnqueueClient) ModuleReconciliation() {
6774
_ = c.client.Enqueue(posthog.Capture{
6875
Event: "module-reconciliation",
6976
DistinctId: c.distinctID,
77+
Properties: map[string]interface{}{
78+
"version": c.version,
79+
},
7080
})
7181
}
7282

7383
func (c EnqueueClient) ModuleCreation() {
7484
_ = c.client.Enqueue(posthog.Capture{
7585
Event: "module-creation",
7686
DistinctId: c.distinctID,
87+
Properties: map[string]interface{}{
88+
"version": c.version,
89+
},
90+
})
91+
}
92+
93+
func (c EnqueueClient) TemplateCreation() {
94+
_ = c.client.Enqueue(posthog.Capture{
95+
Event: "template-creation",
96+
DistinctId: c.distinctID,
97+
Properties: map[string]interface{}{
98+
"version": c.version,
99+
},
77100
})
78101
}
79102

103+
func (c EnqueueClient) TemplateEdit() {
104+
_ = c.client.Enqueue(posthog.Capture{
105+
Event: "template-edit",
106+
DistinctId: c.distinctID,
107+
Properties: map[string]interface{}{
108+
"version": c.version,
109+
},
110+
})
111+
}
112+
113+
// region mock client
114+
80115
func (c MockClient) InstanceStart() {
81116
}
82117

@@ -85,3 +120,9 @@ func (c MockClient) ModuleReconciliation() {
85120

86121
func (c MockClient) ModuleCreation() {
87122
}
123+
124+
func (c MockClient) TemplateCreation() {}
125+
126+
func (c MockClient) TemplateEdit() {}
127+
128+
// endregion

install/cyclops-install.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ spec:
334334
spec:
335335
containers:
336336
- name: cyclops-ui
337-
image: cyclopsui/cyclops-ui:v0.9.1
337+
image: cyclopsui/cyclops-ui:v0.10.0-rc-telemetry
338338
ports:
339339
- containerPort: 80
340340
env:
@@ -397,7 +397,7 @@ spec:
397397
serviceAccountName: cyclops-ctrl
398398
containers:
399399
- name: cyclops-ctrl
400-
image: cyclopsui/cyclops-ctrl:v0.9.1
400+
image: cyclopsui/cyclops-ctrl:v0.10.0-rc-telemetry
401401
ports:
402402
- containerPort: 8080
403403
env:

web/docs/usage_metrics/usage_metrics.md

+10-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ These events include:
66

77
**- `cyclops-instance-start`** - triggered once at the start of cyclops-ctrl pod
88
**- `module-creation`** - called by the UI each time you create a new module
9-
**- `module-reconciliation`** - each time a Module CRD in the cluster is changed
9+
**- `module-reconciliation`** - each time a Module CRD in the cluster is changed
10+
**- `template-creation`** - called each time a template is added in the `Templates` tab
11+
**- `template-edit`** - called each time a template is edited in the `Templates` tab
12+
1013

1114
The metric collection is implemented using [posthog](https://posthog.com).
1215

@@ -17,12 +20,16 @@ Each time one of the events above is triggered, Cyclops sends an HTTP request to
1720
"type": "capture",
1821
"timestamp": "2024-03-23T19:05:38.808279+01:00",
1922
"distinct_id": "f46d57f0-e93f-11ee-924c-8281c5d92ae4",
20-
"event": "cyclops-instance-start"
23+
"event": "cyclops-instance-start",
24+
"properties": {
25+
"version": "v0.10.0"
26+
}
2127
}
2228
```
2329

2430
`distinct_id` - generated for each Cyclops instance using [NewUUID](https://pkg.go.dev/github.com/google/uuid#NewUUID) from google/uuid package
25-
`event` - which event was triggered; see events above
31+
`event` - which event was triggered; see events above
32+
`properties.version` - version of your Cyclops instance
2633

2734
## Turn off
2835

0 commit comments

Comments
 (0)