Skip to content

Commit

Permalink
feat(event): add NodeCount, ReplicaCount, VolumeCapacity event fields
Browse files Browse the repository at this point in the history
Signed-off-by: Niladri Halder <[email protected]>
  • Loading branch information
niladrih committed Jun 17, 2024
1 parent ed2bb54 commit 9fc28c8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 52 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ Create a new `client` and `Send()` an 'event'.
VolumeName("pvc-b3968e30-9020-4011-943a-7ab338d5f19f").
VolumeClaimName("openebs-lvmpv").
Category("volume-deprovision").
Action("replica:2").
Label("Capacity").
Value("2Gi").
NodeCount("3").
Build()

err = client.Send(event)
Expand Down
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").
NodeCount("2").
Build()

err = client.Send(event)
Expand Down
24 changes: 12 additions & 12 deletions pkg/event/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ 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"`
// NodeCount is the number of kubernetes nodes in the cluster.
NodeCount string `json:"node_count"`
// VolumeCapacity is the size of a volume.
VolumeCapacity string `json:"volume_capacity,omitempty"`
// ReplicaCount is the number of replicas attached to a volume.
ReplicaCount string `json:"replica_count,omitempty"`
}

// OpenebsEventBuilder is builder for OpenebsEvent
Expand Down Expand Up @@ -123,18 +123,18 @@ func (b *OpenebsEventBuilder) Category(category string) *OpenebsEventBuilder {
return b
}

func (b *OpenebsEventBuilder) Action(action string) *OpenebsEventBuilder {
b.openebsEvent.Action = action
func (b *OpenebsEventBuilder) NodeCount(nodeCount string) *OpenebsEventBuilder {
b.openebsEvent.NodeCount = nodeCount
return b
}

func (b *OpenebsEventBuilder) Label(label string) *OpenebsEventBuilder {
b.openebsEvent.Label = label
func (b *OpenebsEventBuilder) ReplicaCount(replicaCount string) *OpenebsEventBuilder {
b.openebsEvent.ReplicaCount = replicaCount
return b
}

func (b *OpenebsEventBuilder) Value(value string) *OpenebsEventBuilder {
b.openebsEvent.Value = value
func (b *OpenebsEventBuilder) VolumeCapacity(capacity string) *OpenebsEventBuilder {
b.openebsEvent.VolumeCapacity = capacity
return b
}

Expand Down
44 changes: 10 additions & 34 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,22 @@ 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)
// SetNodeCount sets the node count for a k8s cluster.
func (u *Usage) SetNodeCount(n string) *Usage {
u.OpenebsEventBuilder.NodeCount(n)
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
// SetVolumeCapacity sets the size of a volume.
func (u *Usage) SetVolumeCapacity(volCapG string) *Usage {
s, _ := toGigaUnits(volCapG)
u.SetValue(strconv.FormatInt(s, 10))
u.OpenebsEventBuilder.VolumeCapacity(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)
}
// SetReplicaCount sets the number of replicas for a volume.
func (u *Usage) SetReplicaCount(replicaCount string) *Usage {
u.OpenebsEventBuilder.ReplicaCount(replicaCount)
return u
}

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

return u
}
Expand Down

0 comments on commit 9fc28c8

Please sign in to comment.