Skip to content

Commit

Permalink
Rename exact -> equal, regex -> match_regex
Browse files Browse the repository at this point in the history
  • Loading branch information
jotak committed Feb 26, 2024
1 parent bd31b5d commit ef20a06
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 49 deletions.
40 changes: 20 additions & 20 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,23 @@ Following is the supported API format for prometheus encode:
filter: an optional criterion to filter entries by. Deprecated: use filters instead.
key: the key to match and filter by
value: the value to match and filter by
type: (enum) the type of filter match: exact (default), exact_not, presence, absence, regex or regex_not
exact: match exactly the provided filter value
exact_not: the value must be different from the provided filter
type: (enum) the type of filter match: equal (default), not_equal, presence, absence, match_regex or not_match_regex
equal: match exactly the provided filter value
not_equal: the value must be different from the provided filter
presence: filter key must be present (filter value is ignored)
absence: filter key must be absent (filter value is ignored)
regex: match filter value as a regular expression
regex_not: the filter value must not match the provided regular expression
match_regex: match filter value as a regular expression
not_match_regex: the filter value must not match the provided regular expression
filters: a list of criteria to filter entries by
key: the key to match and filter by
value: the value to match and filter by
type: (enum) the type of filter match: exact (default), exact_not, presence, absence, regex or regex_not
exact: match exactly the provided filter value
exact_not: the value must be different from the provided filter
type: (enum) the type of filter match: equal (default), not_equal, presence, absence, match_regex or not_match_regex
equal: match exactly the provided filter value
not_equal: the value must be different from the provided filter
presence: filter key must be present (filter value is ignored)
absence: filter key must be absent (filter value is ignored)
regex: match filter value as a regular expression
regex_not: the filter value must not match the provided regular expression
match_regex: match filter value as a regular expression
not_match_regex: the filter value must not match the provided regular expression
valueKey: entry key from which to resolve metric value
labels: labels to be associated with the metric
buckets: histogram buckets
Expand Down Expand Up @@ -357,23 +357,23 @@ Following is the supported API format for writing metrics to an OpenTelemetry co
filter: an optional criterion to filter entries by. Deprecated: use filters instead.
key: the key to match and filter by
value: the value to match and filter by
type: (enum) the type of filter match: exact (default), exact_not, presence, absence, regex or regex_not
exact: match exactly the provided filter value
exact_not: the value must be different from the provided filter
type: (enum) the type of filter match: equal (default), not_equal, presence, absence, match_regex or not_match_regex
equal: match exactly the provided filter value
not_equal: the value must be different from the provided filter
presence: filter key must be present (filter value is ignored)
absence: filter key must be absent (filter value is ignored)
regex: match filter value as a regular expression
regex_not: the filter value must not match the provided regular expression
match_regex: match filter value as a regular expression
not_match_regex: the filter value must not match the provided regular expression
filters: a list of criteria to filter entries by
key: the key to match and filter by
value: the value to match and filter by
type: (enum) the type of filter match: exact (default), exact_not, presence, absence, regex or regex_not
exact: match exactly the provided filter value
exact_not: the value must be different from the provided filter
type: (enum) the type of filter match: equal (default), not_equal, presence, absence, match_regex or not_match_regex
equal: match exactly the provided filter value
not_equal: the value must be different from the provided filter
presence: filter key must be present (filter value is ignored)
absence: filter key must be absent (filter value is ignored)
regex: match filter value as a regular expression
regex_not: the filter value must not match the provided regular expression
match_regex: match filter value as a regular expression
not_match_regex: the filter value must not match the provided regular expression
valueKey: entry key from which to resolve metric value
labels: labels to be associated with the metric
buckets: histogram buckets
Expand Down
8 changes: 4 additions & 4 deletions pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ const (
AddKubernetesRuleType = "add_kubernetes"
AddKubernetesInfraRuleType = "add_kubernetes_infra"
ReinterpretDirectionRuleType = "reinterpret_direction"
PromFilterExact = "exact"
PromFilterExactNot = "exact_not"
PromFilterEqual = "equal"
PromFilterNotEqual = "not_equal"
PromFilterPresence = "presence"
PromFilterAbsence = "absence"
PromFilterRegex = "regex"
PromFilterRegexNot = "regex_not"
PromFilterRegex = "match_regex"
PromFilterNotRegex = "not_match_regex"

TagYaml = "yaml"
TagDoc = "doc"
Expand Down
14 changes: 7 additions & 7 deletions pkg/api/encode_prom.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,16 @@ type MetricsItems []MetricsItem
type MetricsFilter struct {
Key string `yaml:"key" json:"key" doc:"the key to match and filter by"`
Value string `yaml:"value" json:"value" doc:"the value to match and filter by"`
Type string `yaml:"type" json:"type" enum:"MetricEncodeFilterTypeEnum" doc:"the type of filter match: exact (default), exact_not, presence, absence, regex or regex_not"`
Type string `yaml:"type" json:"type" enum:"MetricEncodeFilterTypeEnum" doc:"the type of filter match: equal (default), not_equal, presence, absence, match_regex or not_match_regex"`
}

type MetricEncodeFilterTypeEnum struct {
Exact string `yaml:"exact" json:"exact" doc:"match exactly the provided filter value"`
ExactNot string `yaml:"exact_not" json:"exact_not" doc:"the value must be different from the provided filter"`
Presence string `yaml:"presence" json:"presence" doc:"filter key must be present (filter value is ignored)"`
Absence string `yaml:"absence" json:"absence" doc:"filter key must be absent (filter value is ignored)"`
Regex string `yaml:"regex" json:"regex" doc:"match filter value as a regular expression"`
RegexNot string `yaml:"regex_not" json:"regex_not" doc:"the filter value must not match the provided regular expression"`
Equal string `yaml:"equal" json:"equal" doc:"match exactly the provided filter value"`
NotEqual string `yaml:"not_equal" json:"not_equal" doc:"the value must be different from the provided filter"`
Presence string `yaml:"presence" json:"presence" doc:"filter key must be present (filter value is ignored)"`
Absence string `yaml:"absence" json:"absence" doc:"filter key must be absent (filter value is ignored)"`
MatchRegex string `yaml:"match_regex" json:"match_regex" doc:"match filter value as a regular expression"`
NotMatchRegex string `yaml:"not_match_regex" json:"not_match_regex" doc:"the filter value must not match the provided regular expression"`
}

func MetricEncodeFilterTypeName(t string) string {
Expand Down
22 changes: 11 additions & 11 deletions pkg/pipeline/encode/encode_prom_metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func Absence(filter api.MetricsFilter) Predicate {
}
}

func Exact(filter api.MetricsFilter) Predicate {
func Equal(filter api.MetricsFilter) Predicate {
varLookups := extractVarLookups(filter.Value)
return func(flow config.GenericMap) bool {
if val, found := flow[filter.Key]; found {
Expand All @@ -50,8 +50,8 @@ func Exact(filter api.MetricsFilter) Predicate {
}
}

func ExactNot(filter api.MetricsFilter) Predicate {
pred := Exact(filter)
func NotEqual(filter api.MetricsFilter) Predicate {
pred := Equal(filter)
return func(flow config.GenericMap) bool { return !pred(flow) }
}

Expand All @@ -69,28 +69,28 @@ func Regex(filter api.MetricsFilter) Predicate {
}
}

func RegexNot(filter api.MetricsFilter) Predicate {
func NotRegex(filter api.MetricsFilter) Predicate {
pred := Regex(filter)
return func(flow config.GenericMap) bool { return !pred(flow) }
}

func filterToPredicate(filter api.MetricsFilter) Predicate {
switch filter.Type {
case api.PromFilterExact:
return Exact(filter)
case api.PromFilterExactNot:
return ExactNot(filter)
case api.PromFilterEqual:
return Equal(filter)
case api.PromFilterNotEqual:
return NotEqual(filter)
case api.PromFilterPresence:
return Presence(filter)
case api.PromFilterAbsence:
return Absence(filter)
case api.PromFilterRegex:
return Regex(filter)
case api.PromFilterRegexNot:
return RegexNot(filter)
case api.PromFilterNotRegex:
return NotRegex(filter)
}
// Default = Exact
return Exact(filter)
return Equal(filter)
}

func extractVarLookups(value string) [][]string {
Expand Down
14 changes: 7 additions & 7 deletions pkg/pipeline/encode/encode_prom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ func Test_FilterDirection(t *testing.T) {
Name: "ingress_or_inner_packets_total",
Type: "counter",
ValueKey: "packets",
Filters: []api.MetricsFilter{{Key: "dir", Value: "0|2", Type: "regex"}},
Filters: []api.MetricsFilter{{Key: "dir", Value: "0|2", Type: "match_regex"}},
},
},
}
Expand Down Expand Up @@ -390,17 +390,17 @@ func Test_FilterSameOrDifferentNamespace(t *testing.T) {
{
"src-ns": "b",
"dst-ns": "a",
"packets": 100,
"packets": 200,
},
{
"src-ns": "a",
"dst-ns": "a",
"packets": 1000,
"packets": 3000,
},
{
"src-ns": "b",
"dst-ns": "b",
"packets": 10000,
"packets": 40000,
},
}
params := api.PromEncode{
Expand All @@ -419,7 +419,7 @@ func Test_FilterSameOrDifferentNamespace(t *testing.T) {
Name: "packets_different_namespace_total",
Type: "counter",
ValueKey: "packets",
Filters: []api.MetricsFilter{{Key: "src-ns", Type: "exact_not", Value: "$(dst-ns)"}},
Filters: []api.MetricsFilter{{Key: "src-ns", Value: "$(dst-ns)", Type: "not_equal"}},
},
},
}
Expand All @@ -433,8 +433,8 @@ func Test_FilterSameOrDifferentNamespace(t *testing.T) {

exposed := test.ReadExposedMetrics(t)

require.Contains(t, exposed, `test_packets_same_namespace_total 11000`)
require.Contains(t, exposed, `test_packets_different_namespace_total 110`)
require.Contains(t, exposed, `test_packets_same_namespace_total 43000`)
require.Contains(t, exposed, `test_packets_different_namespace_total 210`)
}

func Test_ValueScale(t *testing.T) {
Expand Down

0 comments on commit ef20a06

Please sign in to comment.