|
1 | 1 | package event |
2 | 2 |
|
3 | | -import ( |
4 | | - "github.com/openebs/lib-csi/pkg/common/errors" |
5 | | -) |
6 | | - |
7 | 3 | type OpenebsEventOption func(*OpenebsEvent) error |
8 | 4 |
|
9 | 5 | // OpenebsEvent Hit Type |
10 | 6 | type OpenebsEvent struct { |
11 | | - Category string `json:"category"` |
12 | | - Action string `json:"action"` |
13 | | - Label string `json:"label"` |
14 | | - Value int64 `json:"value"` |
| 7 | + // Specify Project name, ex OpenEBS |
| 8 | + Project string `json:"project"` |
| 9 | + // K8s Version, ex v1.25.15 |
| 10 | + K8sVersion string `json:"k8s_version"` |
| 11 | + // Name of the engine, ex lvm-localpv |
| 12 | + EngineName string `json:"engine_name"` |
| 13 | + // Version of the engine, ex lvm-v1.3.0-e927123:11-08-2023-e927123 |
| 14 | + EngineVersion string `json:"engine_version"` |
| 15 | + // Uid of the default k8s ns, ex f5d2a546-19ce-407d-99d4-0655d67e2f76 |
| 16 | + K8sDefaultNsUid string `json:"k8s_default_ns_uid"` |
| 17 | + // Installer of the app, ex lvm-localpv-helm |
| 18 | + EngineInstaller string `json:"engine_installer"` |
| 19 | + // Machine's os, ex Ubuntu 20.04.6 LTS |
| 20 | + NodeOs string `json:"node_os"` |
| 21 | + // Machine's kernel version, ex 5.4.0-165-generic |
| 22 | + NodeKernelVersion string `json:"node_kernel_version"` |
| 23 | + // Machine's arch, ex linux/amd64 |
| 24 | + NodeArch string `json:"node_arch"` |
| 25 | + // Name of the pv object, example `pvc-b3968e30-9020-4011-943a-7ab338d5f19f` |
| 26 | + VolumeName string `json:"vol_name"` |
| 27 | + // Name of the pvc object, example `openebs-lvmpv` |
| 28 | + VolumeClaimName string `json:"vol_claim_name"` |
| 29 | + // Category of event, i.e install, volume-provision |
| 30 | + Category string `json:"event_category"` |
| 31 | + // Action of the event, i.e running, replica:1 |
| 32 | + Action string `json:"event_action"` |
| 33 | + // Label for the event, i.e nodes, capacity |
| 34 | + Label string `json:"event_label"` |
| 35 | + // Value for the label, i.e 4, 2 |
| 36 | + Value string `json:"event_value"` |
| 37 | +} |
| 38 | + |
| 39 | +// OpenebsEventBuilder is builder for OpenebsEvent |
| 40 | +type OpenebsEventBuilder struct { |
| 41 | + openebsEvent *OpenebsEvent |
| 42 | +} |
| 43 | + |
| 44 | +func NewOpenebsEventBuilder() *OpenebsEventBuilder { |
| 45 | + openebsEvent := &OpenebsEvent{} |
| 46 | + b := &OpenebsEventBuilder{openebsEvent: openebsEvent} |
| 47 | + return b |
| 48 | +} |
| 49 | + |
| 50 | +func (b *OpenebsEventBuilder) Project(project string) *OpenebsEventBuilder { |
| 51 | + b.openebsEvent.Project = project |
| 52 | + return b |
| 53 | +} |
| 54 | + |
| 55 | +func (b *OpenebsEventBuilder) K8sVersion(k8sVersion string) *OpenebsEventBuilder { |
| 56 | + b.openebsEvent.K8sVersion = k8sVersion |
| 57 | + return b |
| 58 | +} |
| 59 | + |
| 60 | +func (b *OpenebsEventBuilder) EngineName(engineName string) *OpenebsEventBuilder { |
| 61 | + b.openebsEvent.EngineName = engineName |
| 62 | + return b |
15 | 63 | } |
16 | 64 |
|
17 | | -func NewOpenebsEvent(opts ...OpenebsEventOption) (*OpenebsEvent, error) { |
18 | | - e := &OpenebsEvent{} |
| 65 | +func (b *OpenebsEventBuilder) EngineVersion(engineVersion string) *OpenebsEventBuilder { |
| 66 | + b.openebsEvent.EngineVersion = engineVersion |
| 67 | + return b |
| 68 | +} |
| 69 | + |
| 70 | +func (b *OpenebsEventBuilder) K8sDefaultNsUid(k8sDefaultNsUid string) *OpenebsEventBuilder { |
| 71 | + b.openebsEvent.K8sDefaultNsUid = k8sDefaultNsUid |
| 72 | + return b |
| 73 | +} |
19 | 74 |
|
20 | | - var err error |
21 | | - for _, opt := range opts { |
22 | | - err = opt(e) |
23 | | - if err != nil { |
24 | | - return nil, errors.Wrap(err, "failed to build OpenebsEvent") |
25 | | - } |
26 | | - } |
| 75 | +func (b *OpenebsEventBuilder) EngineInstaller(engineInstaller string) *OpenebsEventBuilder { |
| 76 | + b.openebsEvent.EngineInstaller = engineInstaller |
| 77 | + return b |
| 78 | +} |
27 | 79 |
|
28 | | - return e, nil |
| 80 | +func (b *OpenebsEventBuilder) NodeOs(nodeOs string) *OpenebsEventBuilder { |
| 81 | + b.openebsEvent.NodeOs = nodeOs |
| 82 | + return b |
29 | 83 | } |
30 | 84 |
|
31 | | -func WithCategory(category string) OpenebsEventOption { |
32 | | - return func(e *OpenebsEvent) error { |
33 | | - if len(category) == 0 { |
34 | | - return errors.Errorf("failed to set OpenebsEvent category: category is an empty string") |
35 | | - } |
| 85 | +func (b *OpenebsEventBuilder) NodeKernelVersion(nodeKernelVersion string) *OpenebsEventBuilder { |
| 86 | + b.openebsEvent.NodeKernelVersion = nodeKernelVersion |
| 87 | + return b |
| 88 | +} |
36 | 89 |
|
37 | | - e.Category = category |
38 | | - return nil |
39 | | - } |
| 90 | +func (b *OpenebsEventBuilder) NodeArch(nodeArch string) *OpenebsEventBuilder { |
| 91 | + b.openebsEvent.NodeArch = nodeArch |
| 92 | + return b |
40 | 93 | } |
41 | 94 |
|
42 | | -func WithAction(action string) OpenebsEventOption { |
43 | | - return func(e *OpenebsEvent) error { |
44 | | - if len(action) == 0 { |
45 | | - return errors.Errorf("failed to set OpenebsEvent action: action is an empty string") |
46 | | - } |
| 95 | +func (b *OpenebsEventBuilder) VolumeName(volumeName string) *OpenebsEventBuilder { |
| 96 | + b.openebsEvent.VolumeName = volumeName |
| 97 | + return b |
| 98 | +} |
47 | 99 |
|
48 | | - e.Action = action |
49 | | - return nil |
50 | | - } |
| 100 | +func (b *OpenebsEventBuilder) VolumeClaimName(volumeClaimName string) *OpenebsEventBuilder { |
| 101 | + b.openebsEvent.VolumeClaimName = volumeClaimName |
| 102 | + return b |
51 | 103 | } |
52 | 104 |
|
53 | | -func WithLabel(label string) OpenebsEventOption { |
54 | | - return func(e *OpenebsEvent) error { |
55 | | - if len(label) == 0 { |
56 | | - return errors.Errorf("failed to set OpenebsEvent label: label is an empty string") |
57 | | - } |
| 105 | +func (b *OpenebsEventBuilder) Category(category string) *OpenebsEventBuilder { |
| 106 | + b.openebsEvent.Category = category |
| 107 | + return b |
| 108 | +} |
| 109 | + |
| 110 | +func (b *OpenebsEventBuilder) Action(action string) *OpenebsEventBuilder { |
| 111 | + b.openebsEvent.Action = action |
| 112 | + return b |
| 113 | +} |
| 114 | + |
| 115 | +func (b *OpenebsEventBuilder) Label(label string) *OpenebsEventBuilder { |
| 116 | + b.openebsEvent.Label = label |
| 117 | + return b |
| 118 | +} |
58 | 119 |
|
59 | | - e.Label = label |
60 | | - return nil |
61 | | - } |
| 120 | +func (b *OpenebsEventBuilder) Value(value string) *OpenebsEventBuilder { |
| 121 | + b.openebsEvent.Value = value |
| 122 | + return b |
62 | 123 | } |
63 | 124 |
|
64 | | -func WithValue(value int64) OpenebsEventOption { |
65 | | - return func(e *OpenebsEvent) error { |
66 | | - e.Value = value |
67 | | - return nil |
68 | | - } |
| 125 | +func (b *OpenebsEventBuilder) Build() *OpenebsEvent { |
| 126 | + return b.openebsEvent |
69 | 127 | } |
0 commit comments