Skip to content

Commit

Permalink
feat(meshmetric): manually remove regex (#9793)
Browse files Browse the repository at this point in the history
* feat(meshmetric): manually remove regex

Signed-off-by: slonka <[email protected]>

* feat(meshmetric): manually remove regex from generated files

Signed-off-by: slonka <[email protected]>

* feat(meshmetric): add upgrade.md

Signed-off-by: slonka <[email protected]>

* feat(meshmetric): adjust tests

Signed-off-by: slonka <[email protected]>

* feat(meshmetric): adjust tests again

Signed-off-by: slonka <[email protected]>

---------

Signed-off-by: slonka <[email protected]>
  • Loading branch information
slonka authored Apr 3, 2024
1 parent 64dc392 commit a09430d
Show file tree
Hide file tree
Showing 25 changed files with 31 additions and 96 deletions.
24 changes: 24 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,30 @@ with `x.y.z` being the version you are planning to upgrade to.
If such a section does not exist, the upgrade you want to perform
does not have any particular instructions.

## Upgrade to `2.8.x`

### MeshMetric `sidecar.regex` is replaced by `sidecar.profiles.exclude`

If you're using `sidecar.regex` field it is getting replaced by `sidecar.profiles.exclude`.
Replace usages of:

```yaml
...
sidecar:
regex: "my_match.*"
...
```

with:

```yaml
sidecar:
profiles:
exclude:
- type: Regex
match: "my_match.*"
```
## Upgrade to `2.7.x`

### Setting `kuma.io/service` in tags of `MeshGatewayInstance` is deprecated
Expand Down
1 change: 0 additions & 1 deletion app/kuma-dp/pkg/dataplane/metrics/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ func AddSidecarParameters(sidecar *v1alpha12.Sidecar) func(queryParameters url.V
values := v1alpha1.EnvoyMetricsFilter(sidecar)

return func(queryParameters url.Values) url.Values {
queryParameters.Set("filter", values.Get("filter"))
queryParameters.Set("usedonly", values.Get("usedonly"))
return queryParameters
}
Expand Down
10 changes: 3 additions & 7 deletions app/kuma-dp/pkg/dataplane/metrics/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ import (
"github.com/kumahq/kuma/pkg/plugins/policies/meshmetric/api/v1alpha1"
)

var (
regex = "abc"
includeUnused = true
)
var includeUnused = true

var _ = Describe("Rewriting the metrics URL", func() {
type testCase struct {
Expand Down Expand Up @@ -58,17 +55,16 @@ var _ = Describe("Rewriting the metrics URL", func() {
address: "127.0.0.1",
input: "http://foo/bar?one=two&three=four",
adminPort: 80,
expected: "http://127.0.0.1:80/stats?filter=abc&one=two&three=four&usedonly=",
expected: "http://127.0.0.1:80/stats?one=two&three=four&usedonly=",
queryModifier: AddSidecarParameters(&v1alpha1.Sidecar{
Regex: &regex,
IncludeUnused: &includeUnused,
}),
}),
Entry("add default usedonly parameter", testCase{
address: "127.0.0.1",
input: "http://foo/bar?one=two&three=four",
adminPort: 80,
expected: "http://127.0.0.1:80/stats?filter=&one=two&three=four&usedonly=",
expected: "http://127.0.0.1:80/stats?one=two&three=four&usedonly=",
queryModifier: AddSidecarParameters(nil),
}),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2772,10 +2772,6 @@ spec:
type: object
type: array
type: object
regex:
description: Regex that will be used to filter sidecar metrics.
It uses Google RE2 engine https://github.com/google/re2
type: string
type: object
type: object
targetRef:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2772,10 +2772,6 @@ spec:
type: object
type: array
type: object
regex:
description: Regex that will be used to filter sidecar metrics.
It uses Google RE2 engine https://github.com/google/re2
type: string
type: object
type: object
targetRef:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2995,10 +2995,6 @@ spec:
type: object
type: array
type: object
regex:
description: Regex that will be used to filter sidecar metrics.
It uses Google RE2 engine https://github.com/google/re2
type: string
type: object
type: object
targetRef:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2792,10 +2792,6 @@ spec:
type: object
type: array
type: object
regex:
description: Regex that will be used to filter sidecar metrics.
It uses Google RE2 engine https://github.com/google/re2
type: string
type: object
type: object
targetRef:
Expand Down
4 changes: 0 additions & 4 deletions app/kumactl/cmd/install/testdata/install-crds.all.golden.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4246,10 +4246,6 @@ spec:
type: object
type: array
type: object
regex:
description: Regex that will be used to filter sidecar metrics.
It uses Google RE2 engine https://github.com/google/re2
type: string
type: object
type: object
targetRef:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4469,10 +4469,6 @@ spec:
type: object
type: array
type: object
regex:
description: Regex that will be used to filter sidecar metrics.
It uses Google RE2 engine https://github.com/google/re2
type: string
type: object
type: object
targetRef:
Expand Down
4 changes: 0 additions & 4 deletions deployments/charts/kuma/crds/kuma.io_meshmetrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,6 @@ spec:
type: object
type: array
type: object
regex:
description: Regex that will be used to filter sidecar metrics.
It uses Google RE2 engine https://github.com/google/re2
type: string
type: object
type: object
targetRef:
Expand Down
5 changes: 0 additions & 5 deletions docs/generated/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5787,11 +5787,6 @@ components:
type: object
type: array
type: object
regex:
description: >-
Regex that will be used to filter sidecar metrics. It
uses Google RE2 engine https://github.com/google/re2
type: string
type: object
type: object
targetRef:
Expand Down
4 changes: 0 additions & 4 deletions docs/generated/raw/crds/kuma.io_meshmetrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,6 @@ spec:
type: object
type: array
type: object
regex:
description: Regex that will be used to filter sidecar metrics.
It uses Google RE2 engine https://github.com/google/re2
type: string
type: object
type: object
targetRef:
Expand Down
2 changes: 0 additions & 2 deletions pkg/plugins/policies/meshmetric/api/v1alpha1/meshmetric.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ type Conf struct {
}

type Sidecar struct {
// Regex that will be used to filter sidecar metrics. It uses Google RE2 engine https://github.com/google/re2
Regex *string `json:"regex,omitempty"`
// Profiles allows to customize which metrics are published.
Profiles *Profiles `json:"profiles,omitempty"`
// IncludeUnused if false will scrape only metrics that has been by sidecar (counters incremented
Expand Down
3 changes: 0 additions & 3 deletions pkg/plugins/policies/meshmetric/api/v1alpha1/schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,6 @@ properties:
type: object
type: array
type: object
regex:
description: Regex that will be used to filter sidecar metrics. It uses Google RE2 engine https://github.com/google/re2
type: string
type: object
type: object
targetRef:
Expand Down
6 changes: 0 additions & 6 deletions pkg/plugins/policies/meshmetric/api/v1alpha1/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,6 @@ func validateSidecar(sidecar *Sidecar) validators.ValidationError {
if sidecar == nil {
return verr
}
if sidecar.Regex != nil {
_, err := regexp.Compile(*sidecar.Regex)
if err != nil {
verr.AddViolation("regex", "invalid regex")
}
}
if sidecar.Profiles != nil {
profiles := sidecar.Profiles
if profiles.Exclude != nil {
Expand Down
19 changes: 0 additions & 19 deletions pkg/plugins/policies/meshmetric/api/v1alpha1/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ targetRef:
name: svc-1
default:
sidecar:
regex: "http2_.*"
profiles:
appendProfiles:
- name: Basic
Expand Down Expand Up @@ -102,24 +101,6 @@ targetRef:
default:
applications:
- port: 95599
`),
ErrorCase(
"invalid regex",
validators.Violation{
Field: "spec.default.sidecar.regex",
Message: "invalid regex",
},
`
type: MeshMetric
mesh: mesh-1
name: metrics-1
targetRef:
kind: MeshService
name: svc-1
default:
sidecar:
regex: "())(!("
includeUnused: true
`),
ErrorCase(
"invalid exclude regexes",
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,6 @@ spec:
type: object
type: array
type: object
regex:
description: Regex that will be used to filter sidecar metrics.
It uses Google RE2 engine https://github.com/google/re2
type: string
type: object
type: object
targetRef:
Expand Down
3 changes: 0 additions & 3 deletions pkg/plugins/policies/meshmetric/plugin/v1alpha1/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,6 @@ func EnvoyMetricsFilter(sidecar *api.Sidecar) url.Values {
values.Set("usedonly", "")
return values
}
if pointer.Deref(sidecar.Regex) != "" {
values.Set("filter", pointer.Deref(sidecar.Regex))
}
if !pointer.Deref(sidecar.IncludeUnused) {
values.Set("usedonly", "")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ var _ = Describe("MeshMetric", func() {
Subset: []core_rules.Tag{},
Conf: api.Conf{
Sidecar: &api.Sidecar{
Regex: pointer.To("http.*"),
IncludeUnused: pointer.To(false),
},
Applications: &[]api.Application{
Expand Down Expand Up @@ -130,7 +129,6 @@ var _ = Describe("MeshMetric", func() {
Subset: []core_rules.Tag{},
Conf: api.Conf{
Sidecar: &api.Sidecar{
Regex: pointer.To("http.*"),
IncludeUnused: pointer.To(false),
},
Applications: &[]api.Application{
Expand Down Expand Up @@ -240,7 +238,6 @@ var _ = Describe("MeshMetric", func() {
Subset: []core_rules.Tag{},
Conf: api.Conf{
Sidecar: &api.Sidecar{
Regex: pointer.To("http.*"),
IncludeUnused: pointer.To(false),
},
Applications: &[]api.Application{
Expand Down Expand Up @@ -282,7 +279,6 @@ var _ = Describe("MeshMetric", func() {
Subset: []core_rules.Tag{},
Conf: api.Conf{
Sidecar: &api.Sidecar{
Regex: pointer.To("http.*"),
IncludeUnused: pointer.To(false),
},
Applications: &[]api.Application{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ resources:
routes:
- directResponse:
body:
inlineString: '{"observability":{"metrics":{"applications":[{"path":"/metrics","port":8080,"address":""}],"backends":[{"type":"Prometheus","name":null}],"sidecar":{"regex":"http.*","includeUnused":false}}}}'
inlineString: '{"observability":{"metrics":{"applications":[{"path":"/metrics","port":8080,"address":""}],"backends":[{"type":"Prometheus","name":null}],"sidecar":{"includeUnused":false}}}}'
status: 200
match:
prefix: /
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ resources:
routes:
- directResponse:
body:
inlineString: '{"observability":{"metrics":{"applications":[{"path":"/metrics","port":8080,"address":""}],"backends":[{"type":"OpenTelemetry","name":"otel-collector.observability.svc-4317","openTelemetry":{"endpoint":"/tmp/kuma-otel-otel-collector.observability.svc-4317.sock","refreshInterval":"1m0s"}},{"type":"OpenTelemetry","name":"second-collector.observability.svc-4317","openTelemetry":{"endpoint":"/tmp/kuma-otel-second-collector.observability.svc-4317.sock","refreshInterval":"1m0s"}}],"sidecar":{"regex":"http.*","includeUnused":false}}}}'
inlineString: '{"observability":{"metrics":{"applications":[{"path":"/metrics","port":8080,"address":""}],"backends":[{"type":"OpenTelemetry","name":"otel-collector.observability.svc-4317","openTelemetry":{"endpoint":"/tmp/kuma-otel-otel-collector.observability.svc-4317.sock","refreshInterval":"1m0s"}},{"type":"OpenTelemetry","name":"second-collector.observability.svc-4317","openTelemetry":{"endpoint":"/tmp/kuma-otel-second-collector.observability.svc-4317.sock","refreshInterval":"1m0s"}}],"sidecar":{"includeUnused":false}}}}'
status: 200
match:
prefix: /
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ resources:
routes:
- directResponse:
body:
inlineString: '{"observability":{"metrics":{"applications":[{"path":"/metrics","port":8080,"address":""}],"backends":[{"type":"Prometheus","name":null}],"sidecar":{"regex":"http.*","includeUnused":false}}}}'
inlineString: '{"observability":{"metrics":{"applications":[{"path":"/metrics","port":8080,"address":""}],"backends":[{"type":"Prometheus","name":null}],"sidecar":{"includeUnused":false}}}}'
status: 200
match:
prefix: /
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ resources:
routes:
- directResponse:
body:
inlineString: '{"observability":{"metrics":{"applications":[{"path":"/metrics","port":8080,"address":""}],"backends":[{"type":"Prometheus","name":null},{"type":"OpenTelemetry","name":"otel-collector.observability.svc-4317","openTelemetry":{"endpoint":"/tmp/kuma-otel-otel-collector.observability.svc-4317.sock","refreshInterval":"1m0s"}}],"sidecar":{"regex":"http.*","includeUnused":false}}}}'
inlineString: '{"observability":{"metrics":{"applications":[{"path":"/metrics","port":8080,"address":""}],"backends":[{"type":"Prometheus","name":null},{"type":"OpenTelemetry","name":"otel-collector.observability.svc-4317","openTelemetry":{"endpoint":"/tmp/kuma-otel-otel-collector.observability.svc-4317.sock","refreshInterval":"1m0s"}}],"sidecar":{"includeUnused":false}}}}'
status: 200
match:
prefix: /
Expand Down
1 change: 0 additions & 1 deletion test/e2e_env/kubernetes/meshmetric/meshmetric.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@ spec:
appendProfiles:
- name: All
sidecar:
regex: .*upstream.*
includeUnused: false
backends:
- type: OpenTelemetry
Expand Down

0 comments on commit a09430d

Please sign in to comment.