Skip to content

Commit 36a13bf

Browse files
committed
feat(event): add Nodes as an Event member
Signed-off-by: Niladri Halder <[email protected]>
1 parent ed2bb54 commit 36a13bf

File tree

3 files changed

+10
-63
lines changed

3 files changed

+10
-63
lines changed

example/main.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ func main() {
3030
VolumeName("pvc-b3968e30-9020-4011-943a-7ab338d5f19f").
3131
VolumeClaimName("openebs-lvmpv").
3232
Category("volume_deprovision").
33-
Action("replica").
34-
Label("Capacity").
35-
Value("2").
33+
Nodes("2").
3634
Build()
3735

3836
err = client.Send(event)

pkg/event/build.go

+4-18
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,8 @@ type OpenebsEvent struct {
4444
VolumeClaimName string `json:"vol_claim_name"`
4545
// Category of event, i.e install, volume-provision
4646
Category string `json:"event_category"`
47-
// Action of the event, i.e running, replica:1
48-
Action string `json:"event_action"`
49-
// Label for the event, i.e nodes, capacity
50-
Label string `json:"event_label"`
51-
// Value for the label, i.e 4, 2
52-
Value string `json:"event_value"`
47+
// Node count
48+
Nodes string `json:"nodes"`
5349
}
5450

5551
// OpenebsEventBuilder is builder for OpenebsEvent
@@ -123,18 +119,8 @@ func (b *OpenebsEventBuilder) Category(category string) *OpenebsEventBuilder {
123119
return b
124120
}
125121

126-
func (b *OpenebsEventBuilder) Action(action string) *OpenebsEventBuilder {
127-
b.openebsEvent.Action = action
128-
return b
129-
}
130-
131-
func (b *OpenebsEventBuilder) Label(label string) *OpenebsEventBuilder {
132-
b.openebsEvent.Label = label
133-
return b
134-
}
135-
136-
func (b *OpenebsEventBuilder) Value(value string) *OpenebsEventBuilder {
137-
b.openebsEvent.Value = value
122+
func (b *OpenebsEventBuilder) Nodes(nodes string) *OpenebsEventBuilder {
123+
b.openebsEvent.Nodes = nodes
138124
return b
139125
}
140126

usage/usage.go

+5-42
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ package usage
1919
import (
2020
"strconv"
2121

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

2524
ga4Client "github.com/openebs/google-analytics-4/pkg/client"
2625
ga4Event "github.com/openebs/google-analytics-4/pkg/event"
26+
k8sapi "github.com/openebs/lib-csi/pkg/client/k8s"
2727
)
2828

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

70-
// SetAction sets the action of an event
71-
func (u *Usage) SetAction(a string) *Usage {
72-
u.OpenebsEventBuilder.Action(a)
73-
return u
74-
}
75-
76-
// SetLabel sets the label for an event
77-
func (u *Usage) SetLabel(l string) *Usage {
78-
u.OpenebsEventBuilder.Label(l)
79-
return u
80-
}
81-
82-
// SetValue sets the value for an event's label
83-
func (u *Usage) SetValue(v string) *Usage {
84-
u.OpenebsEventBuilder.Value(v)
85-
return u
86-
}
87-
88-
// SetVolumeCapacity sets the storage capacity of the volume for a volume event
89-
func (u *Usage) SetVolumeCapacity(volCapG string) *Usage {
90-
s, _ := toGigaUnits(volCapG)
91-
u.SetValue(strconv.FormatInt(s, 10))
92-
return u
93-
}
94-
95-
// SetReplicaCount Wrapper for setting replica count for volume events
96-
// NOTE: This doesn't get the replica count in a volume de-provision event.
97-
// TODO: Pick the current value of replica-count from the CAS-engine
98-
func (u *Usage) SetReplicaCount(count, method string) *Usage {
99-
if method == VolumeProvision && count == "" {
100-
// Case: When volume-provision the replica count isn't specified
101-
// it is set to three by default by the m-apiserver
102-
u.OpenebsEventBuilder.Action(DefaultReplicaCount)
103-
} else {
104-
// Catch all case for volume-deprovision event and
105-
// volume-provision event with an overridden replica-count
106-
u.OpenebsEventBuilder.Action(Replica + count)
107-
}
70+
// SetNodes sets the node count for a k8s cluster.
71+
func (u *Usage) SetNodes(n string) *Usage {
72+
u.OpenebsEventBuilder.Nodes(n)
10873
return u
10974
}
11075

@@ -149,9 +114,7 @@ func (u *Usage) InstallBuilder(override bool) *Usage {
149114
u.OpenebsEventBuilder.
150115
K8sDefaultNsUid(v.id).
151116
Category(InstallEvent).
152-
Action(RunningStatus).
153-
Label(EventLabelNode).
154-
Value(strconv.Itoa(clusterSize))
117+
Nodes(strconv.Itoa(clusterSize))
155118

156119
return u
157120
}

0 commit comments

Comments
 (0)