Live: array for Processor, Outputter and Subscriber in channel rule top level (#39677)

This commit is contained in:
Alexander Emelin
2021-10-06 20:43:25 +03:00
committed by GitHub
parent ed0c43b106
commit 5358c45a3a
46 changed files with 1276 additions and 716 deletions
@@ -0,0 +1,46 @@
package pipeline
import (
"context"
"github.com/grafana/grafana-plugin-sdk-go/data"
)
type KeepFieldsFrameProcessorConfig struct {
FieldNames []string `json:"fieldNames"`
}
// KeepFieldsFrameProcessor can keep specified fields in a data.Frame dropping all other fields.
type KeepFieldsFrameProcessor struct {
config KeepFieldsFrameProcessorConfig
}
func NewKeepFieldsFrameProcessor(config KeepFieldsFrameProcessorConfig) *KeepFieldsFrameProcessor {
return &KeepFieldsFrameProcessor{config: config}
}
func stringInSlice(str string, slice []string) bool {
for _, s := range slice {
if s == str {
return true
}
}
return false
}
const FrameProcessorTypeKeepFields = "keepFields"
func (p *KeepFieldsFrameProcessor) Type() string {
return FrameProcessorTypeKeepFields
}
func (p *KeepFieldsFrameProcessor) ProcessFrame(_ context.Context, _ Vars, frame *data.Frame) (*data.Frame, error) {
var fieldsToKeep []*data.Field
for _, field := range frame.Fields {
if stringInSlice(field.Name, p.config.FieldNames) {
fieldsToKeep = append(fieldsToKeep, field)
}
}
f := data.NewFrame(frame.Name, fieldsToKeep...)
return f, nil
}