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

Commit 38df137

Browse files
Merge pull request #1678 from IzabellaRaulin/fix_1674
Updated exemplary streaming collector plugin
2 parents a492827 + f4df5b4 commit 38df137

File tree

10 files changed

+75
-13
lines changed

10 files changed

+75
-13
lines changed

control/control_security_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ func TestSecureStreamingCollector(t *testing.T) {
217217
SetCertPath(tlsTestSrv+fixtures.TestCrtFileExt).
218218
SetKeyPath(tlsTestSrv+fixtures.TestKeyFileExt).
219219
SetCACertPaths(tlsTestCA+fixtures.TestCrtFileExt).
220-
SetTLSEnabled(true), helper.PluginFilePath("snap-plugin-stream-collector-rand1"),
220+
SetTLSEnabled(true), helper.PluginFilePath("snap-plugin-streaming-collector-rand1"),
221221
security)
222222
So(err, ShouldBeNil)
223223
Convey("and valid plugin client should be obtained", func() {

control/control_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,7 +1367,7 @@ func TestStreamMetrics(t *testing.T) {
13671367
c.eventManager.RegisterHandler("Control.PluginLoaded", lpe)
13681368

13691369
// Load plugin
1370-
_, e := load(c, fixtures.PluginPathStreamRand1)
1370+
_, e := load(c, fixtures.PluginPathStreamingRand1)
13711371
So(e, ShouldBeNil)
13721372
<-lpe.done
13731373
mts, err := c.MetricCatalog()
@@ -1392,7 +1392,7 @@ func TestStreamMetrics(t *testing.T) {
13921392
}
13931393

13941394
// retrieve loaded plugin
1395-
lp, err := c.pluginManager.get("collector" + core.Separator + "test-rand-streamer" + core.Separator + "1")
1395+
lp, err := c.pluginManager.get("streaming-collector" + core.Separator + "test-rand-streamer" + core.Separator + "1")
13961396
So(err, ShouldBeNil)
13971397
So(lp, ShouldNotBeNil)
13981398

@@ -1406,10 +1406,10 @@ func TestStreamMetrics(t *testing.T) {
14061406
taskHit := "hitting"
14071407

14081408
Convey("create a pool, add subscriptions and start plugins", func() {
1409-
serrs := c.SubscribeDeps(taskHit, r, []core.SubscribedPlugin{subscribedPlugin{typeName: "collector", name: "test-rand-streamer", version: 1}}, cdt)
1409+
serrs := c.SubscribeDeps(taskHit, r, []core.SubscribedPlugin{subscribedPlugin{typeName: "streaming-collector", name: "test-rand-streamer", version: 1}}, cdt)
14101410
So(serrs, ShouldBeNil)
14111411

1412-
pool, errp := c.pluginRunner.AvailablePlugins().getOrCreatePool("collector" + core.Separator + "test-rand-streamer" + core.Separator + "1")
1412+
pool, errp := c.pluginRunner.AvailablePlugins().getOrCreatePool("streaming-collector" + core.Separator + "test-rand-streamer" + core.Separator + "1")
14131413
So(errp, ShouldBeNil)
14141414
So(pool, ShouldNotBeNil)
14151415

control/fixtures/fixtures.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ var (
3939
PluginNameMock2 = "snap-plugin-collector-mock2"
4040
PluginPathMock2 = helper.PluginFilePath(PluginNameMock2)
4141

42-
PluginNameStreamRand1 = "snap-plugin-stream-collector-rand1"
43-
PluginPathStreamRand1 = helper.PluginFilePath(PluginNameStreamRand1)
42+
PluginNameStreamingRand1 = "snap-plugin-streaming-collector-rand1"
43+
PluginPathStreamingRand1 = helper.PluginFilePath(PluginNameStreamingRand1)
4444

4545
PluginNameMock2Grpc = "snap-plugin-collector-mock2-grpc"
4646
PluginPathMock2Grpc = helper.PluginFilePath(PluginNameMock2Grpc)

glide.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mgmt/rest/client/client_func_test.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ var (
5151
MOCK_PLUGIN_PATH2 = []string{helper.PluginFilePath("snap-plugin-collector-mock2")}
5252
ANOTHERMOCK_PLUGIN_PATH = []string{helper.PluginFilePath("snap-plugin-collector-anothermock1")}
5353
FILE_PLUGIN_PATH = []string{helper.PluginFilePath("snap-plugin-publisher-mock-file")}
54+
RAND_PLUGIN_PATH = []string{helper.PluginFilePath("snap-plugin-streaming-collector-rand1")}
55+
PASSTHRU_PLUGIN_PATH = []string{helper.PluginFilePath("snap-plugin-processor-passthru")}
5456
DIRECTORY_PATH = []string{helper.PluginPath()}
5557

5658
NextPort = 45000
@@ -640,6 +642,61 @@ func TestSnapClient(t *testing.T) {
640642
})
641643
}
642644

645+
func TestClient_SimpleLoadAndUnloadPlugin(t *testing.T) {
646+
CompressUpload = false
647+
648+
Convey("Client should exist", t, func() {
649+
uri := startAPI()
650+
c, cerr := New(uri, "v1", true)
651+
So(cerr, ShouldBeNil)
652+
653+
Convey("load collector plugin", func() {
654+
p := c.LoadPlugin(MOCK_PLUGIN_PATH1)
655+
So(p.Err, ShouldBeNil)
656+
Convey("unload loaded plugin", func() {
657+
p := c.UnloadPlugin("collector", "mock", 1)
658+
So(p.Err, ShouldBeNil)
659+
So(p.Name, ShouldEqual, "mock")
660+
So(p.Version, ShouldEqual, 1)
661+
So(p.Type, ShouldEqual, "collector")
662+
})
663+
})
664+
Convey("load publisher plugin", func() {
665+
p := c.LoadPlugin(FILE_PLUGIN_PATH)
666+
So(p.Err, ShouldBeNil)
667+
Convey("unload loaded plugin", func() {
668+
p := c.UnloadPlugin("publisher", "mock-file", 3)
669+
So(p.Err, ShouldBeNil)
670+
So(p.Name, ShouldEqual, "mock-file")
671+
So(p.Version, ShouldEqual, 3)
672+
So(p.Type, ShouldEqual, "publisher")
673+
})
674+
})
675+
Convey("load processor plugin", func() {
676+
p := c.LoadPlugin(PASSTHRU_PLUGIN_PATH)
677+
So(p.Err, ShouldBeNil)
678+
Convey("unload loaded plugin", func() {
679+
p := c.UnloadPlugin("processor", "passthru", 1)
680+
So(p.Err, ShouldBeNil)
681+
So(p.Name, ShouldEqual, "passthru")
682+
So(p.Version, ShouldEqual, 1)
683+
So(p.Type, ShouldEqual, "processor")
684+
})
685+
})
686+
Convey("load streaming collector plugin", func() {
687+
p := c.LoadPlugin(RAND_PLUGIN_PATH)
688+
So(p.Err, ShouldBeNil)
689+
Convey("unload loaded plugin", func() {
690+
p := c.UnloadPlugin("streaming-collector", "test-rand-streamer", 1)
691+
So(p.Err, ShouldBeNil)
692+
So(p.Name, ShouldEqual, "test-rand-streamer")
693+
So(p.Version, ShouldEqual, 1)
694+
So(p.Type, ShouldEqual, "streaming-collector")
695+
})
696+
})
697+
})
698+
}
699+
643700
func TestClient_UnloadPlugin(t *testing.T) {
644701
CompressUpload = false
645702

-9.89 MB
Binary file not shown.
-9.56 MB
Binary file not shown.

plugin/collector/snap-plugin-stream-collector-rand1/README.md renamed to plugin/collector/snap-plugin-streaming-collector-rand1/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## Notice
2+
This exemplary streaming collector plugin comes from snap-plugin-lib-go repo. It is highly recommended to use up-to-date source code from
3+
the original location: https://github.com/intelsdi-x/snap-plugin-lib-go/tree/master/examples
4+
5+
16

27
## Snap Plugin Go Library: Stream Collector Plugin Example
38
Here you will find an example plugin that covers the basics for writing a stream collector plugin.

plugin/collector/snap-plugin-stream-collector-rand1/main.go renamed to plugin/collector/snap-plugin-streaming-collector-rand1/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ package main
2121

2222
import (
2323
"github.com/intelsdi-x/snap-plugin-lib-go/v1/plugin"
24-
"github.com/intelsdi-x/snap/plugin/collector/snap-plugin-stream-collector-rand1/rand"
24+
"github.com/intelsdi-x/snap/plugin/collector/snap-plugin-streaming-collector-rand1/rand"
2525
)
2626

2727
const (

plugin/collector/snap-plugin-stream-collector-rand1/rand/rand.go renamed to plugin/collector/snap-plugin-streaming-collector-rand1/rand/rand.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ limitations under the License.
2020
package rand
2121

2222
import (
23+
"context"
2324
"fmt"
2425
"math/rand"
2526
"time"
@@ -61,21 +62,21 @@ type RandCollector struct {
6162
metrics []plugin.Metric
6263
}
6364

64-
// StreamMetrics taks both an in and out channel of []plugin.Metric
65+
// StreamMetrics takes both an in and out channel of []plugin.Metric
6566
//
6667
// The metrics_in channel is used to set/update the metrics that Snap is
6768
// currently requesting to be collected by the plugin.
6869
//
6970
// The metrics_out channel is used by the plugin to send the collected metrics
7071
// to Snap.
7172
func (r *RandCollector) StreamMetrics(
73+
ctx context.Context,
7274
metrics_in chan []plugin.Metric,
7375
metrics_out chan []plugin.Metric,
7476
err chan string) error {
7577

7678
go r.streamIt(metrics_out, err)
77-
go r.drainMetrics(metrics_in)
78-
79+
r.drainMetrics(metrics_in)
7980
return nil
8081
}
8182

@@ -145,7 +146,6 @@ func (RandCollector) GetMetricTypes(cfg plugin.Config) ([]plugin.Metric, error)
145146
for _, val := range vals {
146147
metric := plugin.Metric{
147148
Namespace: plugin.NewNamespace("random", val),
148-
Version: 1,
149149
}
150150
metrics = append(metrics, metric)
151151
}

0 commit comments

Comments
 (0)