mirror of https://github.com/grafana/grafana
Live: pipeline rule crud (file-based, still for MVP) (#39238)
parent
3ad5ee87a3
commit
a696fc8b2b
@ -0,0 +1,25 @@ |
||||
package pattern |
||||
|
||||
import ( |
||||
"fmt" |
||||
"regexp" |
||||
"strings" |
||||
) |
||||
|
||||
var patternReString = `^[A-z0-9_\-/=.:*]*$` |
||||
var patternRe = regexp.MustCompile(patternReString) |
||||
|
||||
var maxPatternLength = 160 |
||||
|
||||
func Valid(pattern string) (bool, string) { |
||||
if strings.HasPrefix(pattern, "/") { |
||||
return false, "pattern can't start with /" |
||||
} |
||||
if !patternRe.MatchString(pattern) { |
||||
return false, fmt.Sprintf("pattern format error, must match %s", patternReString) |
||||
} |
||||
if len(pattern) > maxPatternLength { |
||||
return false, fmt.Sprintf("pattern max length exceeded (%d)", maxPatternLength) |
||||
} |
||||
return true, "" |
||||
} |
||||
@ -0,0 +1,37 @@ |
||||
package pattern |
||||
|
||||
import "testing" |
||||
|
||||
func TestValid(t *testing.T) { |
||||
type args struct { |
||||
pattern string |
||||
} |
||||
tests := []struct { |
||||
name string |
||||
args args |
||||
want bool |
||||
}{ |
||||
{ |
||||
name: "valid", |
||||
args: args{ |
||||
pattern: "xxx", |
||||
}, |
||||
want: true, |
||||
}, |
||||
{ |
||||
name: "invalid", |
||||
args: args{ |
||||
pattern: "/xxx", |
||||
}, |
||||
want: false, |
||||
}, |
||||
} |
||||
for _, tt := range tests { |
||||
t.Run(tt.name, func(t *testing.T) { |
||||
got, _ := Valid(tt.args.pattern) |
||||
if got != tt.want { |
||||
t.Errorf("Valid() got = %v, want %v", got, tt.want) |
||||
} |
||||
}) |
||||
} |
||||
} |
||||
@ -0,0 +1,91 @@ |
||||
package pipeline |
||||
|
||||
type EntityInfo struct { |
||||
Type string `json:"type"` |
||||
Description string `json:"description"` |
||||
Example interface{} `json:"example,omitempty"` |
||||
} |
||||
|
||||
var SubscribersRegistry = []EntityInfo{ |
||||
{ |
||||
Type: SubscriberTypeBuiltin, |
||||
Description: "apply builtin feature subscribe logic", |
||||
}, |
||||
{ |
||||
Type: SubscriberTypeManagedStream, |
||||
Description: "apply managed stream subscribe logic", |
||||
}, |
||||
{ |
||||
Type: SubscriberTypeMultiple, |
||||
Description: "apply multiple subscribers", |
||||
}, |
||||
{ |
||||
Type: SubscriberTypeAuthorizeRole, |
||||
Description: "authorize user role", |
||||
}, |
||||
} |
||||
|
||||
var OutputsRegistry = []EntityInfo{ |
||||
{ |
||||
Type: OutputTypeManagedStream, |
||||
Description: "Only send schema when structure changes. Note this also requires a matching subscriber", |
||||
Example: ManagedStreamOutputConfig{}, |
||||
}, |
||||
{ |
||||
Type: OutputTypeMultiple, |
||||
Description: "Send the output to multiple destinations", |
||||
Example: MultipleOutputterConfig{}, |
||||
}, |
||||
{ |
||||
Type: OutputTypeConditional, |
||||
Description: "send to an output depending on frame values", |
||||
Example: ConditionalOutputConfig{}, |
||||
}, |
||||
{ |
||||
Type: OutputTypeRedirect, |
||||
}, |
||||
{ |
||||
Type: OutputTypeThreshold, |
||||
}, |
||||
{ |
||||
Type: OutputTypeChangeLog, |
||||
}, |
||||
{ |
||||
Type: OutputTypeRemoteWrite, |
||||
}, |
||||
} |
||||
|
||||
var ConvertersRegistry = []EntityInfo{ |
||||
{ |
||||
Type: ConverterTypeJsonAuto, |
||||
}, |
||||
{ |
||||
Type: ConverterTypeJsonExact, |
||||
}, |
||||
{ |
||||
Type: ConverterTypeInfluxAuto, |
||||
Description: "accept influx line protocol", |
||||
Example: AutoInfluxConverterConfig{}, |
||||
}, |
||||
{ |
||||
Type: ConverterTypeJsonFrame, |
||||
}, |
||||
} |
||||
|
||||
var ProcessorsRegistry = []EntityInfo{ |
||||
{ |
||||
Type: ProcessorTypeKeepFields, |
||||
Description: "list the fields that should stay", |
||||
Example: KeepFieldsProcessorConfig{}, |
||||
}, |
||||
{ |
||||
Type: ProcessorTypeDropFields, |
||||
Description: "list the fields that should be removed", |
||||
Example: DropFieldsProcessorConfig{}, |
||||
}, |
||||
{ |
||||
Type: ProcessorTypeMultiple, |
||||
Description: "apply multiple processors", |
||||
Example: MultipleProcessorConfig{}, |
||||
}, |
||||
} |
||||
Loading…
Reference in new issue