Skip to content

Commit

Permalink
use common string match for stats match
Browse files Browse the repository at this point in the history
Signed-off-by: huabing zhao <zhaohuabing@gmail.com>
  • Loading branch information
zhaohuabing committed Oct 30, 2023
1 parent 1372494 commit e79793a
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 71 deletions.
19 changes: 1 addition & 18 deletions api/v1alpha1/envoyproxy_metric_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type ProxyMetrics struct {
// `cluster.<cluster_name>.membership_degraded`,reference https://github.com/envoyproxy/envoy/issues/9856,
// https://github.com/envoyproxy/envoy/issues/14610
//
Matches []StatsMatch `json:"matches,omitempty"`
Matches []StringMatch `json:"matches,omitempty"`

// EnableVirtualHostStats enables envoy stat metrics for virtual hosts.
EnableVirtualHostStats bool `json:"enableVirtualHostStats,omitempty"`
Expand Down Expand Up @@ -58,20 +58,3 @@ type ProxyPrometheusProvider struct {
// Disable the Prometheus endpoint.
Disable bool `json:"disable,omitempty"`
}

// Match defines the stats match configuration.
type StatsMatch struct {
// MatcherType defines the stats matcher type
//
// +kubebuilder:validation:Enum=RegularExpression;Prefix;Suffix
Type StatsMatchType `json:"type"`
Value string `json:"value"`
}

type StatsMatchType string

const (
StatsMatchPrefix StatsMatchType = "Prefix"
StatsMatchRegularExpression StatsMatchType = "RegularExpression"
StatsMatchSuffix StatsMatchType = "Suffix"
)
21 changes: 4 additions & 17 deletions api/v1alpha1/zz_generated.deepcopy.go

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

16 changes: 12 additions & 4 deletions internal/xds/bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ type readyServerParameters struct {
}

type StatsMatcherParameters struct {
Exacts []string
Prefixs []string
Suffixs []string
RegularExpressions []string
Expand Down Expand Up @@ -154,12 +155,19 @@ func GetRenderedBootstrapConfig(proxyMetrics *egv1a1.ProxyMetrics) (string, erro
if proxyMetrics.Matches != nil {
// Add custom envoy proxy stats
for _, match := range proxyMetrics.Matches {
switch match.Type {
case egv1a1.StatsMatchPrefix:
// matchType default to exact
matchType := egv1a1.StringMatchExact
if match.Type != nil {
matchType = *match.Type
}
switch matchType {
case egv1a1.StringMatchExact:
StatsMatcher.Exacts = append(StatsMatcher.Exacts, match.Value)
case egv1a1.StringMatchPrefix:
StatsMatcher.Prefixs = append(StatsMatcher.Prefixs, match.Value)
case egv1a1.StatsMatchSuffix:
case egv1a1.StringMatchSuffix:
StatsMatcher.Suffixs = append(StatsMatcher.Suffixs, match.Value)
case egv1a1.StatsMatchRegularExpression:
case egv1a1.StringMatchRegularExpression:
StatsMatcher.RegularExpressions = append(StatsMatcher.RegularExpressions, match.Value)
}
}
Expand Down
3 changes: 3 additions & 0 deletions internal/xds/bootstrap/bootstrap.yaml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ stats_config:
stats_matcher:
inclusion_list:
patterns:
{{- range $_, $item := .StatsMatcher.Exacts }}
- exact: {{$item}}
{{- end}}
{{- range $_, $item := .StatsMatcher.Prefixs }}
- prefix: {{$item}}
{{- end}}
Expand Down
15 changes: 10 additions & 5 deletions internal/xds/bootstrap/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/stretchr/testify/assert"

egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1"
"github.com/envoyproxy/gateway/internal/utils/ptr"
)

func TestGetRenderedBootstrapConfig(t *testing.T) {
Expand Down Expand Up @@ -55,21 +56,25 @@ func TestGetRenderedBootstrapConfig(t *testing.T) {
{
name: "custom-stats-matcher",
proxyMetrics: &egv1a1.ProxyMetrics{
Matches: []egv1a1.StatsMatch{
Matches: []egv1a1.StringMatch{
{
Type: egv1a1.StatsMatchPrefix,
Type: ptr.To(egv1a1.StringMatchExact),
Value: "http.foo.bar.cluster.upstream_rq",
},
{
Type: ptr.To(egv1a1.StringMatchPrefix),
Value: "http",
},
{
Type: egv1a1.StatsMatchSuffix,
Type: ptr.To(egv1a1.StringMatchSuffix),
Value: "upstream_rq",
},
{
Type: egv1a1.StatsMatchRegularExpression,
Type: ptr.To(egv1a1.StringMatchRegularExpression),
Value: "virtual.*",
},
{
Type: egv1a1.StatsMatchPrefix,
Type: ptr.To(egv1a1.StringMatchPrefix),
Value: "cluster",
},
},
Expand Down
1 change: 1 addition & 0 deletions internal/xds/bootstrap/testdata/custom-stats-matcher.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ stats_config:
stats_matcher:
inclusion_list:
patterns:
- exact: http.foo.bar.cluster.upstream_rq
- prefix: http
- prefix: cluster
- suffix: upstream_rq
Expand Down
29 changes: 2 additions & 27 deletions site/content/en/latest/api/extension_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -1251,7 +1251,7 @@ _Appears in:_
| --- | --- |
| `prometheus` _[ProxyPrometheusProvider](#proxyprometheusprovider)_ | Prometheus defines the configuration for Admin endpoint `/stats/prometheus`. |
| `sinks` _[ProxyMetricSink](#proxymetricsink) array_ | Sinks defines the metric sinks where metrics are sent to. |
| `matches` _[StatsMatch](#statsmatch) array_ | Matches defines configuration for selecting specific metrics instead of generating all metrics stats that are enabled by default. This helps reduce CPU and memory overhead in Envoy, but eliminating some stats may after critical functionality. Here are the stats that we strongly recommend not disabling: `cluster_manager.warming_clusters`, `cluster.<cluster_name>.membership_total`,`cluster.<cluster_name>.membership_healthy`, `cluster.<cluster_name>.membership_degraded`,reference https://github.com/envoyproxy/envoy/issues/9856, https://github.com/envoyproxy/envoy/issues/14610 |
| `matches` _[StringMatch](#stringmatch) array_ | Matches defines configuration for selecting specific metrics instead of generating all metrics stats that are enabled by default. This helps reduce CPU and memory overhead in Envoy, but eliminating some stats may after critical functionality. Here are the stats that we strongly recommend not disabling: `cluster_manager.warming_clusters`, `cluster.<cluster_name>.membership_total`,`cluster.<cluster_name>.membership_healthy`, `cluster.<cluster_name>.membership_degraded`,reference https://github.com/envoyproxy/envoy/issues/9856, https://github.com/envoyproxy/envoy/issues/14610 |
| `enableVirtualHostStats` _boolean_ | EnableVirtualHostStats enables envoy stat metrics for virtual hosts. |


Expand Down Expand Up @@ -1583,32 +1583,6 @@ _Appears in:_



#### StatsMatch



Match defines the stats match configuration.

_Appears in:_
- [ProxyMetrics](#proxymetrics)

| Field | Description |
| --- | --- |
| `type` _[StatsMatchType](#statsmatchtype)_ | MatcherType defines the stats matcher type |
| `value` _string_ | |


#### StatsMatchType

_Underlying type:_ `string`



_Appears in:_
- [StatsMatch](#statsmatch)



#### StringMatch


Expand All @@ -1617,6 +1591,7 @@ StringMatch defines how to match any strings. This is a general purpose match co

_Appears in:_
- [CORS](#cors)
- [ProxyMetrics](#proxymetrics)

| Field | Description |
| --- | --- |
Expand Down

0 comments on commit e79793a

Please sign in to comment.