forked from jpillora/go-ogle-analytics
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(event): update ua to ga4 analytics
Signed-off-by: Abhinandan Purkait <[email protected]>
- Loading branch information
1 parent
ecc4269
commit b8c3d30
Showing
7 changed files
with
184 additions
and
93 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
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 |
---|---|---|
@@ -1,69 +1,127 @@ | ||
package event | ||
|
||
import ( | ||
"github.com/openebs/lib-csi/pkg/common/errors" | ||
) | ||
|
||
type OpenebsEventOption func(*OpenebsEvent) error | ||
|
||
// OpenebsEvent Hit Type | ||
type OpenebsEvent struct { | ||
Category string `json:"category"` | ||
Action string `json:"action"` | ||
Label string `json:"label"` | ||
Value int64 `json:"value"` | ||
// Specify Project name, ex OpenEBS | ||
Project string `json:"project"` | ||
// K8s Version, ex v1.25.15 | ||
K8sVersion string `json:"k8s_version"` | ||
// Name of the engine, ex lvm-localpv | ||
EngineName string `json:"engine_name"` | ||
// 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, ex f5d2a546-19ce-407d-99d4-0655d67e2f76 | ||
K8sDefaultNsUid string `json:"k8s_default_ns_uid"` | ||
// Installer of the app, ex lvm-localpv-helm | ||
EngineInstaller string `json:"engine_installer"` | ||
// Machine's os, ex Ubuntu 20.04.6 LTS | ||
NodeOs string `json:"node_os"` | ||
// Machine's kernel version, ex 5.4.0-165-generic | ||
NodeKernelVersion string `json:"node_kernel_version"` | ||
// Machine's arch, ex linux/amd64 | ||
NodeArch string `json:"node_arch"` | ||
// Name of the pv object, example `pvc-b3968e30-9020-4011-943a-7ab338d5f19f` | ||
VolumeName string `json:"vol_name"` | ||
// 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_label"` | ||
// Value for the label, i.e 4, 2 | ||
Value string `json:"event_value"` | ||
} | ||
|
||
// OpenebsEventBuilder is builder for OpenebsEvent | ||
type OpenebsEventBuilder struct { | ||
openebsEvent *OpenebsEvent | ||
} | ||
|
||
func NewOpenebsEventBuilder() *OpenebsEventBuilder { | ||
openebsEvent := &OpenebsEvent{} | ||
b := &OpenebsEventBuilder{openebsEvent: openebsEvent} | ||
return b | ||
} | ||
|
||
func (b *OpenebsEventBuilder) Project(project string) *OpenebsEventBuilder { | ||
b.openebsEvent.Project = project | ||
return b | ||
} | ||
|
||
func (b *OpenebsEventBuilder) K8sVersion(k8sVersion string) *OpenebsEventBuilder { | ||
b.openebsEvent.K8sVersion = k8sVersion | ||
return b | ||
} | ||
|
||
func (b *OpenebsEventBuilder) EngineName(engineName string) *OpenebsEventBuilder { | ||
b.openebsEvent.EngineName = engineName | ||
return b | ||
} | ||
|
||
func NewOpenebsEvent(opts ...OpenebsEventOption) (*OpenebsEvent, error) { | ||
e := &OpenebsEvent{} | ||
func (b *OpenebsEventBuilder) EngineVersion(engineVersion string) *OpenebsEventBuilder { | ||
b.openebsEvent.EngineVersion = engineVersion | ||
return b | ||
} | ||
|
||
func (b *OpenebsEventBuilder) K8sDefaultNsUid(k8sDefaultNsUid string) *OpenebsEventBuilder { | ||
b.openebsEvent.K8sDefaultNsUid = k8sDefaultNsUid | ||
return b | ||
} | ||
|
||
var err error | ||
for _, opt := range opts { | ||
err = opt(e) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "failed to build OpenebsEvent") | ||
} | ||
} | ||
func (b *OpenebsEventBuilder) EngineInstaller(engineInstaller string) *OpenebsEventBuilder { | ||
b.openebsEvent.EngineInstaller = engineInstaller | ||
return b | ||
} | ||
|
||
return e, nil | ||
func (b *OpenebsEventBuilder) NodeOs(nodeOs string) *OpenebsEventBuilder { | ||
b.openebsEvent.NodeOs = nodeOs | ||
return b | ||
} | ||
|
||
func WithCategory(category string) OpenebsEventOption { | ||
return func(e *OpenebsEvent) error { | ||
if len(category) == 0 { | ||
return errors.Errorf("failed to set OpenebsEvent category: category is an empty string") | ||
} | ||
func (b *OpenebsEventBuilder) NodeKernelVersion(nodeKernelVersion string) *OpenebsEventBuilder { | ||
b.openebsEvent.NodeKernelVersion = nodeKernelVersion | ||
return b | ||
} | ||
|
||
e.Category = category | ||
return nil | ||
} | ||
func (b *OpenebsEventBuilder) NodeArch(nodeArch string) *OpenebsEventBuilder { | ||
b.openebsEvent.NodeArch = nodeArch | ||
return b | ||
} | ||
|
||
func WithAction(action string) OpenebsEventOption { | ||
return func(e *OpenebsEvent) error { | ||
if len(action) == 0 { | ||
return errors.Errorf("failed to set OpenebsEvent action: action is an empty string") | ||
} | ||
func (b *OpenebsEventBuilder) VolumeName(volumeName string) *OpenebsEventBuilder { | ||
b.openebsEvent.VolumeName = volumeName | ||
return b | ||
} | ||
|
||
e.Action = action | ||
return nil | ||
} | ||
func (b *OpenebsEventBuilder) VolumeClaimName(volumeClaimName string) *OpenebsEventBuilder { | ||
b.openebsEvent.VolumeClaimName = volumeClaimName | ||
return b | ||
} | ||
|
||
func WithLabel(label string) OpenebsEventOption { | ||
return func(e *OpenebsEvent) error { | ||
if len(label) == 0 { | ||
return errors.Errorf("failed to set OpenebsEvent label: label is an empty string") | ||
} | ||
func (b *OpenebsEventBuilder) Category(category string) *OpenebsEventBuilder { | ||
b.openebsEvent.Category = category | ||
return b | ||
} | ||
|
||
func (b *OpenebsEventBuilder) Action(action string) *OpenebsEventBuilder { | ||
b.openebsEvent.Action = action | ||
return b | ||
} | ||
|
||
func (b *OpenebsEventBuilder) Label(label string) *OpenebsEventBuilder { | ||
b.openebsEvent.Label = label | ||
return b | ||
} | ||
|
||
e.Label = label | ||
return nil | ||
} | ||
func (b *OpenebsEventBuilder) Value(value string) *OpenebsEventBuilder { | ||
b.openebsEvent.Value = value | ||
return b | ||
} | ||
|
||
func WithValue(value int64) OpenebsEventOption { | ||
return func(e *OpenebsEvent) error { | ||
e.Value = value | ||
return nil | ||
} | ||
func (b *OpenebsEventBuilder) Build() *OpenebsEvent { | ||
return b.openebsEvent | ||
} |
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 |
---|---|---|
@@ -1,34 +1,44 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
gaClient "github.com/openebs/go-ogle-analytics/client" | ||
gaEvent "github.com/openebs/go-ogle-analytics/event" | ||
) | ||
|
||
func main() { | ||
client, err := gaClient.NewMeasurementClient( | ||
gaClient.WithApiSecret("NguBiGh6QeOdeG3zJswggQ"), | ||
gaClient.WithMeasurementId("G-TZGP46618W"), | ||
gaClient.WithClientId("uniqueUserId-000000001"), | ||
gaClient.WithApiSecret("<api-secret>"), | ||
gaClient.WithMeasurementId("<measurement-id>"), | ||
gaClient.WithClientId("<client-id>"), | ||
) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
event, err := gaEvent.NewOpenebsEvent( | ||
gaEvent.WithCategory("Foo"), | ||
gaEvent.WithAction("Bar"), | ||
gaEvent.WithLabel("Baz"), | ||
gaEvent.WithValue(19072023), | ||
) | ||
if err != nil { | ||
panic(err) | ||
} | ||
event := gaEvent.NewOpenebsEventBuilder(). | ||
Project("OpenEBS"). | ||
K8sVersion("v1.25.15"). | ||
EngineName("test-engine"). | ||
EngineVersion("v1.0.0"). | ||
K8sDefaultNsUid("f5d2a546-19ce-407d-99d4-0655d67e2f76"). | ||
EngineInstaller("helm"). | ||
NodeOs("Ubuntu 20.04.6 LTS"). | ||
NodeArch("linux/amd64"). | ||
NodeKernelVersion("5.4.0-165-generic"). | ||
VolumeName("pvc-b3968e30-9020-4011-943a-7ab338d5f19f"). | ||
VolumeClaimName("openebs-lvmpv"). | ||
Category("volume-deprovision"). | ||
Action("replica:2"). | ||
Label("Capacity"). | ||
Value("2Gi"). | ||
Build() | ||
|
||
err = client.Send(event) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
println("Event fired!") | ||
fmt.Println("Event fired!") | ||
} |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package payload | ||
|
||
import ( | ||
"strings" | ||
) | ||
|
||
// Replace the `-` with `_` from the name | ||
func NormalizedEventName(name string) string { | ||
return strings.ReplaceAll(name, "-", "_") | ||
} |