Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit b05093c

Browse files
author
Mateusz Kleina
committed
Fix publishers and processors subscription
1 parent a492827 commit b05093c

3 files changed

Lines changed: 24 additions & 5 deletions

File tree

control/available_plugin.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,15 +625,15 @@ func (ap *availablePlugins) findLatestPool(pType, name string) (strategy.Pool, s
625625
var latest strategy.Pool
626626
for key, pool := range ap.table {
627627
tnv := strings.Split(key, core.Separator)
628-
if tnv[0] == pType && tnv[1] == name {
628+
if tnv[0] == pType && tnv[1] == name && pool.Count() > 0 {
629629
latest = pool
630630
break
631631
}
632632
}
633633
if latest != nil {
634634
for key, pool := range ap.table {
635635
tnv := strings.Split(key, core.Separator)
636-
if tnv[0] == pType && tnv[1] == name && pool.Version() > latest.Version() {
636+
if tnv[0] == pType && tnv[1] == name && pool.Version() > latest.Version() && pool.Count() > 0 {
637637
latest = pool
638638
}
639639
}

control/subscription_group.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,6 @@ func (s *subscriptionGroup) process(id string) (serrs []serror.SnapError) {
433433

434434
// notice that requested plugins contains only processors and publishers
435435
for _, plugin := range s.requestedPlugins {
436-
// add processors and publishers to collectors just gathered
437-
plugins = append(plugins, plugin)
438436
// add defaults to plugins (exposed in a plugins ConfigPolicy)
439437
if lp, err := s.pluginManager.get(
440438
fmt.Sprintf("%s"+core.Separator+"%s"+core.Separator+"%d",
@@ -445,6 +443,21 @@ func (s *subscriptionGroup) process(id string) (serrs []serror.SnapError) {
445443
// set defaults to plugin config
446444
plugin.Config().ApplyDefaults(policy.Defaults())
447445
}
446+
447+
// update version info for subscribed processor or publisher
448+
version := plugin.Version()
449+
if version < 1 {
450+
version = lp.Version()
451+
}
452+
s := subscribedPlugin{
453+
name: plugin.Name(),
454+
typeName: plugin.TypeName(),
455+
version: version,
456+
config: plugin.Config(),
457+
}
458+
459+
// add processors and publishers to collectors just gathered
460+
plugins = append(plugins, s)
448461
}
449462
}
450463
// calculates those plugins that need to be subscribed and unsubscribed to

scheduler/workflow_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func TestCollectPublishWorkflow(t *testing.T) {
143143
So(err, ShouldBeNil)
144144
rp2, err := core.NewRequestedPlugin(snap_publisher_file_path, c.GetTempDir(), nil)
145145
So(err, ShouldBeNil)
146-
_, err = c.Load(rp2)
146+
plugPublisher, err := c.Load(rp2)
147147
So(err, ShouldBeNil)
148148
rp3, err := core.NewRequestedPlugin(snap_processor_passthru_path, c.GetTempDir(), nil)
149149
So(err, ShouldBeNil)
@@ -189,6 +189,12 @@ func TestCollectPublishWorkflow(t *testing.T) {
189189
So(t.LastFailureMessage(), ShouldBeEmpty)
190190
So(t.FailedCount(), ShouldEqual, 0)
191191
So(t.HitCount(), ShouldBeGreaterThan, metricsToCollect)
192+
193+
// check if task fails after unloading publisher
194+
c.Unload(plugPublisher)
195+
<-el.done
196+
So(t.LastFailureMessage(), ShouldNotBeEmpty)
197+
So(t.FailedCount(), ShouldBeGreaterThan, 0)
192198
})
193199
})
194200
})

0 commit comments

Comments
 (0)