Skip to content

Commit

Permalink
Rewording Explode -> Expand
Browse files Browse the repository at this point in the history
Signed-off-by: Pedro Tanaka <pedro.tanaka@shopify.com>
  • Loading branch information
pedro-stanaka committed Dec 23, 2024
1 parent e5c2d40 commit a125dac
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 52 deletions.
10 changes: 5 additions & 5 deletions pkg/event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ type MultiObserverEvent struct {
SampleRate float64
}

type ExplodableEvent interface {
Explode() []Event
type ExpandableEvent interface {
Expand() []Event
}

func (m *MultiObserverEvent) MetricName() string { return m.OMetricName }
Expand All @@ -165,10 +165,10 @@ func (m *MultiObserverEvent) Labels() map[string]string { return m.OLabels }
func (m *MultiObserverEvent) MetricType() mapper.MetricType { return mapper.MetricTypeObserver }
func (m *MultiObserverEvent) Values() []float64 { return m.OValues }

// Explode returns a list of events that are the result of exploding the multi-value event.
// Expand returns a list of events that are the result of expanding the multi-value event.
// This will be used as a middle-step in the pipeline to convert multi-value events to single-value events.
// And keep the exporter code compatible with previous versions.
func (m *MultiObserverEvent) Explode() []Event {
func (m *MultiObserverEvent) Expand() []Event {
if len(m.OValues) == 1 && m.SampleRate == 0 {
return []Event{m}
}
Expand Down Expand Up @@ -200,7 +200,7 @@ func (m *MultiObserverEvent) Explode() []Event {
}

var (
_ ExplodableEvent = &MultiObserverEvent{}
_ ExpandableEvent = &MultiObserverEvent{}
_ MultiValueEvent = &MultiObserverEvent{}
_ MultiValueEvent = &CounterEvent{}
_ MultiValueEvent = &GaugeEvent{}
Expand Down
50 changes: 3 additions & 47 deletions pkg/event/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func TestMultiValueEvent(t *testing.T) {
}
}

func TestMultiObserverEvent_Explode(t *testing.T) {
func TestMultiObserverEvent_Expand(t *testing.T) {
tests := []struct {
name string
event *MultiObserverEvent
Expand Down Expand Up @@ -263,54 +263,10 @@ func TestMultiObserverEvent_Explode(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := tt.event.Explode()
got := tt.event.Expand()
if !reflect.DeepEqual(got, tt.wantEvents) {
t.Errorf("MultiObserverEvent.Explode() = %v, want %v", got, tt.wantEvents)
t.Errorf("MultiObserverEvent.Expand() = %v, want %v", got, tt.wantEvents)
}
})
}
}

func TestEventImplementations(t *testing.T) {
t.Run("MultiObserverEvent implements MultiValueEvent", func(t *testing.T) {
event := &MultiObserverEvent{}
if _, ok := interface{}(event).(MultiValueEvent); !ok {
t.Error("MultiObserverEvent does not implement MultiValueEvent")
}
})

t.Run("MultiObserverEvent implements ExplodableEvent", func(t *testing.T) {
event := &MultiObserverEvent{}
if _, ok := interface{}(event).(ExplodableEvent); !ok {
t.Error("MultiObserverEvent does not implement ExplodableEvent")
}
})

t.Run("MultiObserverEvent implements Event", func(t *testing.T) {
event := &MultiObserverEvent{}
if _, ok := interface{}(event).(Event); !ok {
t.Error("MultiObserverEvent does not implement Event")
}
})

t.Run("CounterEvent implements MultiValueEvent", func(t *testing.T) {
event := &CounterEvent{}
if _, ok := interface{}(event).(MultiValueEvent); !ok {
t.Error("CounterEvent does not implement MultiValueEvent")
}
})

t.Run("GaugeEvent implements MultiValueEvent", func(t *testing.T) {
event := &GaugeEvent{}
if _, ok := interface{}(event).(MultiValueEvent); !ok {
t.Error("GaugeEvent does not implement MultiValueEvent")
}
})

t.Run("ObserverEvent implements MultiValueEvent", func(t *testing.T) {
event := &ObserverEvent{}
if _, ok := interface{}(event).(MultiValueEvent); !ok {
t.Error("ObserverEvent does not implement MultiValueEvent")
}
})
}

0 comments on commit a125dac

Please sign in to comment.