Skip to content

Commit

Permalink
add e2e for MetricDefinition (istio#42563) (istio#42924)
Browse files Browse the repository at this point in the history
* add e2e for MetricDefinition

* fix lint

* send http traffic only

* fix prom query

Co-authored-by: zirain <hejianpeng2@huawei.com>
  • Loading branch information
kyessenov and zirain authored Jan 20, 2023
1 parent cedd3af commit 40a7bea
Showing 1 changed file with 82 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,46 @@ const (
registryPasswd = "passwd"
)

func TestMetricDefinitions(t *testing.T) {
framework.NewTest(t).
Label(label.IPv4). // https://github.com/istio/istio/issues/35835
Features("observability.telemetry.stats.prometheus.customize-metric").
Run(func(t framework.TestContext) {
t.Cleanup(func() {
if t.Failed() {
util.PromDump(t.Clusters().Default(), promInst, prometheus.Query{Metric: "istio_custom_total"})
}
})
urlPath := "/custom_path"
httpSourceQuery := buildCustomQuery(urlPath)
cluster := t.Clusters().Default()
retry.UntilSuccessOrFail(t, func() error {
if err := sendHTTPTraffic(urlPath); err != nil {
t.Log("failed to send traffic")
return err
}
if _, err := util.QueryPrometheus(t, cluster, httpSourceQuery, promInst); err != nil {
util.PromDiff(t, promInst, cluster, httpSourceQuery)
return err
}
return nil
}, retry.Delay(1*time.Second), retry.Timeout(300*time.Second))
util.ValidateMetric(t, cluster, promInst, httpSourceQuery, 1)
})
}

func buildCustomQuery(urlPath string) (destinationQuery prometheus.Query) {
labels := map[string]string{
"url_path": urlPath,
"response_status": "200",
}
sourceQuery := prometheus.Query{}
sourceQuery.Metric = "istio_custom_total"
sourceQuery.Labels = labels

return sourceQuery
}

func TestCustomizeMetrics(t *testing.T) {
framework.NewTest(t).
Label(label.IPv4). // https://github.com/istio/istio/issues/35835
Expand Down Expand Up @@ -217,6 +257,14 @@ func setupConfig(_ resource.Context, cfg *istio.Config) {
return
}
cfValue := `
meshConfig:
defaultConfig:
proxyStatsMatcher:
inclusionPrefixes:
- istio_custom_total
extraStatTags:
- url_path
- response_status
values:
telemetry:
v2:
Expand All @@ -234,6 +282,16 @@ values:
custom_dimension: "'test'"
tags_to_remove:
- %s
outboundSidecar:
definitions:
- name: custom_total
type: "COUNTER"
value: "1"
metrics:
- name: custom_total
dimensions:
url_path: request.url_path
response_status: string(response.code)
`
cfg.ControlPlaneValues = fmt.Sprintf(cfValue, removedTag)
cfg.RemoteClusterValues = cfg.ControlPlaneValues
Expand Down Expand Up @@ -266,6 +324,30 @@ func setupWasmExtension(ctx resource.Context) error {
return nil
}

func sendHTTPTraffic(urlPath string) error {
for _, cltInstance := range client {
httpOpts := echo.CallOptions{
To: server,
Port: echo.Port{
Name: "http",
},
HTTP: echo.HTTP{
Path: urlPath,
Method: "GET",
},
Retry: echo.Retry{
NoRetry: true,
},
}

if _, err := cltInstance.Call(httpOpts); err != nil {
return err
}
}

return nil
}

func sendTraffic() error {
for _, cltInstance := range client {
httpOpts := echo.CallOptions{
Expand Down

0 comments on commit 40a7bea

Please sign in to comment.