Skip to content

Commit

Permalink
Add ingress gateway metrics
Browse files Browse the repository at this point in the history
Signed-off-by: Raul Sevilla <rsevilla@redhat.com>
  • Loading branch information
rsevilla87 committed Jan 31, 2024
1 parent e0799ab commit 36cb598
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
9 changes: 4 additions & 5 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ import (
func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
type ConfigDefaulted Config
defaultCfg := ConfigDefaulted{
Warmup: false, // Disable warmup by default
RequestTimeout: time.Second,
Procs: 1,
Keepalive: true,
PrometheusMetrics: prometheusQueries,
Warmup: false, // Disable warmup by default
RequestTimeout: time.Second,
Procs: 1,
Keepalive: true,
}
if err := unmarshal(&defaultCfg); err != nil {
return err
Expand Down
4 changes: 1 addition & 3 deletions pkg/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ type Config struct {
Warmup bool `yaml:"warmup" json:"-"`
// RequestTimeout defines the tool request timeout
RequestTimeout time.Duration `yaml:"requestTimeout" json:"requestTimeout"`
// Prometheus metrics
PrometheusMetrics map[string]string `json:"-"`
// RequestRate defines the amount of requests to run in parallel
RequestRate int `yaml:"requestRate" json:"requestRate"`
// Keepalive use keepalived connections
Expand All @@ -56,7 +54,7 @@ type Config struct {
HTTP2 bool `yaml:"http2" json:"http2"`
}

var prometheusQueries = map[string]string{
var PrometheusQueries = map[string]string{
"avg_cpu_usage_router_pods": "avg(avg_over_time(sum(irate(container_cpu_usage_seconds_total{name!='', namespace='openshift-ingress', pod=~'router-default.+'}[2m])) by (pod)[ELAPSED:]))",
"avg_memory_usage_router_pods_bytes": "avg(avg_over_time(sum(container_memory_working_set_bytes{name!='', namespace='openshift-ingress', pod=~'router-default.+'}) by (pod)[ELAPSED:]))",
"avg_cpu_usage_router_nodes": "avg(avg_over_time(sum(irate(node_cpu_seconds_total{mode!~'idle|steal'}[2m]) and on (instance) label_replace(kube_pod_info{namespace='openshift-ingress'},'instance', '$1', 'node', '(.+)')) by (instance)[ELAPSED:]))",
Expand Down
2 changes: 1 addition & 1 deletion pkg/runner/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func runBenchmark(cfg config.Config, clusterMetadata tools.ClusterMetadata, p *p
timeouts += result.Timeouts
httpErrors += result.HTTPErrors
elapsed := fmt.Sprintf("%ds", int(time.Since(sampleTs).Seconds()))
for field, query := range cfg.PrometheusMetrics {
for field, query := range config.PrometheusQueries {
promQuery := strings.ReplaceAll(query, "ELAPSED", elapsed)
log.Debugf("Running query: %s", promQuery)
value, err := p.Query(promQuery, time.Time{}.UTC())
Expand Down
4 changes: 4 additions & 0 deletions pkg/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ func WithServiceMesh(enable bool, igNamespace string) OptsFunctions {
return func(r *Runner) {
r.serviceMesh = enable
r.igNamespace = igNamespace
config.PrometheusQueries["avg_cpu_usage_ingress_gateway_pods"] =
fmt.Sprintf("avg(avg_over_time(sum(irate(container_cpu_usage_seconds_total{name!='', namespace='%s', pod=~'istio-ingressgateway.+'}[2m])) by (pod)[ELAPSED:]))", igNamespace)
config.PrometheusQueries["avg_memory_usage_ingress_gateway_pods_bytes"] =
fmt.Sprintf("avg(avg_over_time(sum(container_memory_working_set_bytes{name!='', namespace='%s', pod=~'istio-ingressgateway.+'}) by (pod)[ELAPSED:]))", igNamespace)
}
}

Expand Down

0 comments on commit 36cb598

Please sign in to comment.