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

Commit

Permalink
gRPC version of passthru processor plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
marcin-krolik committed Sep 6, 2016
1 parent 0b228f5 commit 18bb38a
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 0 deletions.
34 changes: 34 additions & 0 deletions plugin/processor/snap-plugin-processor-passthru-grpc/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
http://www.apache.org/licenses/LICENSE-2.0.txt
Copyright 2015 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main

import (
"github.com/intelsdi-x/snap-plugin-lib-go/v1/plugin"
"github.com/intelsdi-x/snap/plugin/processor/snap-plugin-processor-passthru-grpc/passthru"
)

const (
pluginName = "passthru-grpc"
pluginVersion = 1
)

func main() {
plugin.StartProcessor(passthru.NewPassthruProcessor(), pluginName, pluginVersion)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// +build small

/*
http://www.apache.org/licenses/LICENSE-2.0.txt
Copyright 2015 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main

import (
"testing"

. "github.com/smartystreets/goconvey/convey"
)

func TestMain(t *testing.T) {
Convey("ensure plugin loads and responds", t, func() {
So(func() { main() }, ShouldNotPanic)
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
http://www.apache.org/licenses/LICENSE-2.0.txt
Copyright 2016 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package passthru

import (
log "github.com/Sirupsen/logrus"

"github.com/intelsdi-x/snap-plugin-lib-go/v1/plugin"
)

const (
debug = "debug"
)

func NewPassthruProcessor() *passthruProcessor {
return &passthruProcessor{}
}

type passthruProcessor struct{}

func (p *passthruProcessor) GetConfigPolicy() (plugin.ConfigPolicy, error) {
policy := plugin.NewConfigPolicy()
rule, err := plugin.NewBoolRule(debug, false)
if err != nil {
panic(err)
}
policy.AddBoolRule([]string{""}, rule)
return *policy, nil
}

func (p *passthruProcessor) Process(metrics []plugin.Metric, config plugin.Config) ([]plugin.Metric, error) {
log.SetFormatter(&log.TextFormatter{DisableTimestamp: true})
if _, err := config.GetBool(debug); err == nil {
log.SetLevel(log.DebugLevel)
} else {
log.SetLevel(log.InfoLevel)
}

log.Debug("processing started")

if _, err := config.GetBool("test"); err == nil {
log.Debug("test configuration found")
for idx, m := range metrics {
if m.Namespace.Strings()[0] == "foo" {
log.Print("found foo metric")
metrics[idx].Data = 2
}
}
}

return metrics, nil
}

0 comments on commit 18bb38a

Please sign in to comment.