Skip to content

Commit

Permalink
feat(event): update ua to ga4 analytics
Browse files Browse the repository at this point in the history
Signed-off-by: Abhinandan Purkait <[email protected]>
  • Loading branch information
Abhinandan-Purkait committed Nov 10, 2023
1 parent 0b5433e commit 7a2967d
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 34 deletions.
1 change: 1 addition & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func (c *MeasurementClient) Send(event *event.OpenebsEvent) error {
req.URL.RawQuery = v.Encode()

req.Header.Set("Content-Type", "application/json")

resp, err := client.HttpClient.Do(req)
if err != nil {
return err
Expand Down
43 changes: 24 additions & 19 deletions event/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,39 @@ type OpenebsEventOption func(*OpenebsEvent) error

// OpenebsEvent Hit Type
type OpenebsEvent struct {
// Our Application Org, example OpenEBS
// Specify Project name, ex OpenEBS
Project string `json:"project"`
// K8s Version, example v1.25.15
// K8s Version, ex v1.25.15
K8sVersion string `json:"k8s_version"`
// Name of the engine,example lvm-localpv
// Name of the engine, ex lvm-localpv
EngineName string `json:"engine_name"`
// Version of the engine, example lvm-v1.3.x-e927123:11-08-2023-e927123
// Version of the engine, ex lvm-v1.3.0-e927123:11-08-2023-e927123
EngineVersion string `json:"engine_version"`
// Uid of the default k8s ns, to uniquely identify, example f5d2a546-19ce-407d-99d4-0655d67e2f76
// Uid of the default k8s ns, ex f5d2a546-19ce-407d-99d4-0655d67e2f76
K8sDefaultNsUid string `json:"k8s_default_ns_uid"`
// Installer of the app, example lvm-localpv-helm
// Installer of the app, ex lvm-localpv-helm
EngineInstaller string `json:"engine_installer"`
// Machine's os example Ubuntu 20.04.6 LTS, 5.4.0-165-generic, x86_64
// Machine's os, ex Ubuntu 20.04.6 LTS
NodeOs string `json:"node_os"`
// Machine's kernel version, example 5.4.0-165-generic
// Machine's kernel version, ex 5.4.0-165-generic
NodeKernelVersion string `json:"node_kernel_version"`
// Machine's arch, example x86_64
// Machine's arch, ex linux/amd64
NodeArch string `json:"node_arch"`
// Id of the involved object, example `pvc-b3968e30-9020-4011-943a-7ab338d5f19f`
// Name of the pv object, example `pvc-b3968e30-9020-4011-943a-7ab338d5f19f`
VolumeName string `json:"vol_name"`
// Extra detail of the involved object, example `lvm-vol-new`
// Name of the pvc object, example `openebs-lvmpv`
VolumeClaimName string `json:"vol_claim_name"`
// Category of event, i.e install, volume-provision
Category string `json:"event_category"`
// Action of the event, i.e running, replica:1
Action string `json:"event_action"`
// Label for the event, i.e nodes, capacity
Label string `json:"event_category"`
// Value for the event, i.e 4, 2
Value string `json:"event_action"`
Label string `json:"event_label"`
// Value for the label, i.e 4, 2
Value string `json:"event_value"`
}

// OpenebsEventBuilder builder pattern code
// OpenebsEventBuilder is builder for OpenebsEvent
type OpenebsEventBuilder struct {
openebsEvent *OpenebsEvent
}
Expand Down Expand Up @@ -92,8 +92,13 @@ func (b *OpenebsEventBuilder) NodeArch(nodeArch string) *OpenebsEventBuilder {
return b
}

func (b *OpenebsEventBuilder) ResourceId(resourceId string) *OpenebsEventBuilder {
b.openebsEvent.ResourceId = resourceId
func (b *OpenebsEventBuilder) VolumeName(volumeName string) *OpenebsEventBuilder {
b.openebsEvent.VolumeName = volumeName
return b
}

func (b *OpenebsEventBuilder) VolumeClaimName(volumeClaimName string) *OpenebsEventBuilder {
b.openebsEvent.VolumeClaimName = volumeClaimName
return b
}

Expand All @@ -117,6 +122,6 @@ func (b *OpenebsEventBuilder) Value(value string) *OpenebsEventBuilder {
return b
}

func (b *OpenebsEventBuilder) Build() *OpenebsEvent {
return b.openebsEvent
func (b *OpenebsEventBuilder) Build() (*OpenebsEvent, error) {
return b.openebsEvent, nil
}
15 changes: 6 additions & 9 deletions event/event.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package event

import "strings"
import (
"strings"
)

func (e *OpenebsEvent) CategoryStr() string {
return e.Category
}

// Replace the `-` with `_` in the Category
func (e *OpenebsEvent) NormalizedCategoryStr() string {
return strings.ReplaceAll(e.CategoryStr(), "-", "_")
}

func (e *OpenebsEvent) ActionStr() string {
return e.Action
}
func (e *OpenebsEvent) EngineNameStr() string {
return e.EngineName
}
5 changes: 3 additions & 2 deletions example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"

gaClient "github.com/openebs/go-ogle-analytics/client"
gaEvent "github.com/openebs/go-ogle-analytics/event"
)
Expand All @@ -24,8 +25,8 @@ func main() {
K8sDefaultNsUid("f5d2a546-19ce-407d-99d4-0655d67e2f76").
EngineInstaller("helm").
NodeOs("Ubuntu 20.04.6 LTS").
NodeArch("x86_64").
NodeKernelVersion(" 5.4.0-165-generic").
NodeArch("linux/amd64").
NodeKernelVersion("5.4.0-165-generic").
ResourceId("pvc-b3968e30-9020-4011-943a-7ab338d5f19f").
Category("volume-deprovision").
Action("replica:2").
Expand Down
7 changes: 3 additions & 4 deletions payload/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ import (
type PayloadOption func(*Payload) error

type Payload struct {
ClientId string `json:"client_id"`

Events []ApiEvent `json:"events"`
ClientId string `json:"client_id"`
Events []ApiEvent `json:"events"`
}

type ApiEvent struct {
Expand Down Expand Up @@ -46,7 +45,7 @@ func WithClientId(clientId string) PayloadOption {
func WithOpenebsEvent(event *event.OpenebsEvent) PayloadOption {
return func(p *Payload) error {
p.Events = append(p.Events, ApiEvent{
Name: event.NormalizedCategoryStr(),
Name: NormalizedEventName(event.EngineNameStr() + "-" + event.CategoryStr()),
Params: *event,
})
return nil
Expand Down
10 changes: 10 additions & 0 deletions payload/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package payload

import (
"strings"
)

// Replace the `-` with `_` from the name
func NormalizedEventName(name string) string {
return strings.ReplaceAll(name, "-", "_")
}

0 comments on commit 7a2967d

Please sign in to comment.