-
Notifications
You must be signed in to change notification settings - Fork 773
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
π implement telemetry
- Loading branch information
Showing
12 changed files
with
177 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
DISABLE_TELEMETRY=true | ||
PORT=8888 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ import ( | |
"github.com/cyclops-ui/cycops-ctrl/internal/cluster/k8sclient" | ||
"github.com/cyclops-ui/cycops-ctrl/internal/models" | ||
"github.com/cyclops-ui/cycops-ctrl/internal/storage/templates" | ||
"github.com/cyclops-ui/cycops-ctrl/internal/telemetry" | ||
templaterepo "github.com/cyclops-ui/cycops-ctrl/internal/template" | ||
) | ||
|
||
|
@@ -46,7 +47,8 @@ type ModuleReconciler struct { | |
templates *templates.Storage | ||
kubernetesClient *k8sclient.KubernetesClient | ||
|
||
logger logr.Logger | ||
telemetryClient telemetry.Client | ||
logger logr.Logger | ||
} | ||
|
||
func NewModuleReconciler( | ||
|
@@ -55,13 +57,15 @@ func NewModuleReconciler( | |
templatesRepo *templaterepo.Repo, | ||
templates *templates.Storage, | ||
kubernetesClient *k8sclient.KubernetesClient, | ||
telemetryClient telemetry.Client, | ||
) *ModuleReconciler { | ||
return &ModuleReconciler{ | ||
Client: client, | ||
Scheme: scheme, | ||
templatesRepo: templatesRepo, | ||
templates: templates, | ||
kubernetesClient: kubernetesClient, | ||
telemetryClient: telemetryClient, | ||
logger: ctrl.Log.WithName("reconciler"), | ||
} | ||
} | ||
|
@@ -81,6 +85,7 @@ func NewModuleReconciler( | |
// - https://pkg.go.dev/sigs.k8s.io/[email protected]/pkg/reconcile | ||
func (r *ModuleReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { | ||
_ = log.FromContext(ctx) | ||
r.telemetryClient.ModuleReconciliation() | ||
|
||
var module cyclopsv1alpha1.Module | ||
err := r.Get(ctx, req.NamespacedName, &module) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package telemetry | ||
|
||
import ( | ||
"github.com/google/uuid" | ||
"github.com/posthog/posthog-go" | ||
) | ||
|
||
type Client interface { | ||
ModuleCreation() | ||
ModuleReconciliation() | ||
InstanceStart() | ||
} | ||
|
||
type EnqueueClient struct { | ||
client posthog.Client | ||
distinctID string | ||
} | ||
|
||
type MockClient struct{} | ||
|
||
func NewClient(disable bool) (Client, error) { | ||
if disable { | ||
return MockClient{}, nil | ||
} | ||
|
||
client, err := posthog.NewWithConfig( | ||
"phc_1GSZ1j83eWbXITdpYO3u2Epo6ZZ7IimmRsLue7oDx3p", | ||
posthog.Config{ | ||
Endpoint: "https://eu.posthog.com", | ||
}, | ||
) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
id, err := uuid.NewUUID() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return EnqueueClient{ | ||
client: client, | ||
distinctID: id.String(), | ||
}, nil | ||
} | ||
|
||
func (c EnqueueClient) InstanceStart() { | ||
_ = c.client.Enqueue(posthog.Capture{ | ||
Event: "cyclops-instance-start", | ||
DistinctId: c.distinctID, | ||
}) | ||
} | ||
|
||
func (c EnqueueClient) ModuleReconciliation() { | ||
_ = c.client.Enqueue(posthog.Capture{ | ||
Event: "module-reconciliation", | ||
DistinctId: c.distinctID, | ||
}) | ||
} | ||
|
||
func (c EnqueueClient) ModuleCreation() { | ||
_ = c.client.Enqueue(posthog.Capture{ | ||
Event: "module-creation", | ||
DistinctId: c.distinctID, | ||
}) | ||
} | ||
|
||
func (c MockClient) InstanceStart() { | ||
} | ||
|
||
func (c MockClient) ModuleReconciliation() { | ||
} | ||
|
||
func (c MockClient) ModuleCreation() { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,3 @@ We intend to finish developing a stable version by the start of the next year. | |
|
||
### Contact us | ||
If you have the knowledge or resources to help in contributing to Cyclops, contact us at [email protected] | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Usage metrics | ||
|
||
Cyclops tracks usage metrics so that the maintainers can gain better insights into Cyclops usage. No sensitive or user data is sent; only triggered events, like a Cyclops instance start, are sent. | ||
|
||
These events include: | ||
|
||
**- `cyclops-instance-start`** - triggered once at the start of cyclops-ctrl pod | ||
**- `module-creation`** - called by the UI each time you create a new module | ||
**- `module-reconciliation`** - each time a Module CRD in the cluster is changed | ||
|
||
The metric collection is implemented using [posthog](https://posthog.com). | ||
|
||
Each time one of the events above is triggered, Cyclops sends an HTTP request to the posthog API with the following information: | ||
```json | ||
{ | ||
"type": "capture", | ||
"timestamp": "2024-03-23T19:05:38.808279+01:00", | ||
"distinct_id": "f46d57f0-e93f-11ee-924c-8281c5d92ae4", | ||
"event": "cyclops-instance-start" | ||
} | ||
``` | ||
`distinct_id` - generated for each Cyclops instance using [NewUUID](https://pkg.go.dev/github.com/google/uuid#NewUUID) from google/uuid package | ||
`event` - which event was triggered; see events above | ||
|
||
## Turn off | ||
|
||
If you wish to turn off tracking metrics, add an environment variable to cyclops-ctrl: | ||
`DISABLE_TELEMETRY: true` | ||
|
||
You can turn it off by adding the env variable to your `cyclops-ctrl` Deployment definition. Navigate to the `env` part of the deployment definition and add the following: | ||
|
||
``` | ||
env: | ||
- name: PORT | ||
value: "8080" | ||
+ - name: DISABLE_TELEMETRY | ||
+ value: "true" | ||
``` | ||
|
||
The metric collection is enabled by default but is [disabled in development](https://github.com/cyclops-ui/cyclops/blob/main/cyclops-ctrl/.env). | ||
|
||
## Other | ||
If you have any additional questions about Cyclops and tracking usage metrics, reach out to us at `[email protected]` |
Oops, something went wrong.