Skip to content

Commit

Permalink
feat(event): add Nodes as an Event member
Browse files Browse the repository at this point in the history
Signed-off-by: Niladri Halder <[email protected]>
  • Loading branch information
niladrih committed Jun 15, 2024
1 parent ed2bb54 commit 36a13bf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 63 deletions.
4 changes: 1 addition & 3 deletions example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ func main() {
VolumeName("pvc-b3968e30-9020-4011-943a-7ab338d5f19f").
VolumeClaimName("openebs-lvmpv").
Category("volume_deprovision").
Action("replica").
Label("Capacity").
Value("2").
Nodes("2").
Build()

err = client.Send(event)
Expand Down
22 changes: 4 additions & 18 deletions pkg/event/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,8 @@ type OpenebsEvent struct {
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"`
// Node count
Nodes string `json:"nodes"`
}

// OpenebsEventBuilder is builder for OpenebsEvent
Expand Down Expand Up @@ -123,18 +119,8 @@ func (b *OpenebsEventBuilder) Category(category string) *OpenebsEventBuilder {
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
}

func (b *OpenebsEventBuilder) Value(value string) *OpenebsEventBuilder {
b.openebsEvent.Value = value
func (b *OpenebsEventBuilder) Nodes(nodes string) *OpenebsEventBuilder {
b.openebsEvent.Nodes = nodes
return b
}

Expand Down
47 changes: 5 additions & 42 deletions usage/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ package usage
import (
"strconv"

k8sapi "github.com/openebs/lib-csi/pkg/client/k8s"
"k8s.io/klog/v2"

ga4Client "github.com/openebs/google-analytics-4/pkg/client"
ga4Event "github.com/openebs/google-analytics-4/pkg/event"
k8sapi "github.com/openebs/lib-csi/pkg/client/k8s"
)

// Usage struct represents all information about a usage metric sent to
Expand Down Expand Up @@ -67,44 +67,9 @@ func (u *Usage) SetCategory(c string) *Usage {
return u
}

// SetAction sets the action of an event
func (u *Usage) SetAction(a string) *Usage {
u.OpenebsEventBuilder.Action(a)
return u
}

// SetLabel sets the label for an event
func (u *Usage) SetLabel(l string) *Usage {
u.OpenebsEventBuilder.Label(l)
return u
}

// SetValue sets the value for an event's label
func (u *Usage) SetValue(v string) *Usage {
u.OpenebsEventBuilder.Value(v)
return u
}

// SetVolumeCapacity sets the storage capacity of the volume for a volume event
func (u *Usage) SetVolumeCapacity(volCapG string) *Usage {
s, _ := toGigaUnits(volCapG)
u.SetValue(strconv.FormatInt(s, 10))
return u
}

// SetReplicaCount Wrapper for setting replica count for volume events
// NOTE: This doesn't get the replica count in a volume de-provision event.
// TODO: Pick the current value of replica-count from the CAS-engine
func (u *Usage) SetReplicaCount(count, method string) *Usage {
if method == VolumeProvision && count == "" {
// Case: When volume-provision the replica count isn't specified
// it is set to three by default by the m-apiserver
u.OpenebsEventBuilder.Action(DefaultReplicaCount)
} else {
// Catch all case for volume-deprovision event and
// volume-provision event with an overridden replica-count
u.OpenebsEventBuilder.Action(Replica + count)
}
// SetNodes sets the node count for a k8s cluster.
func (u *Usage) SetNodes(n string) *Usage {
u.OpenebsEventBuilder.Nodes(n)
return u
}

Expand Down Expand Up @@ -149,9 +114,7 @@ func (u *Usage) InstallBuilder(override bool) *Usage {
u.OpenebsEventBuilder.
K8sDefaultNsUid(v.id).
Category(InstallEvent).
Action(RunningStatus).
Label(EventLabelNode).
Value(strconv.Itoa(clusterSize))
Nodes(strconv.Itoa(clusterSize))

return u
}
Expand Down

0 comments on commit 36a13bf

Please sign in to comment.