From 3de6e40495a99b84eb62d636686549b5674146bd Mon Sep 17 00:00:00 2001 From: Hasit Mistry Date: Thu, 4 Jan 2024 18:29:15 -0800 Subject: [PATCH] Remove limit_by_label_key from rate-limiting and concurrency-limiting configurations --- .../base/config.libsonnet | 1 - .../base/gen/definitions.json | 1 - .../concurrency-limiting/base/gen/values.yaml | 1 - .../base/config.libsonnet | 7 +----- .../base/gen/definitions.json | 7 +----- .../base/gen/values.yaml | 6 +---- .../quota-scheduling/base/config.libsonnet | 7 +----- .../base/gen/definitions.json | 9 ++----- .../quota-scheduling/base/gen/values.yaml | 6 +---- .../rate-limiting/base/config.libsonnet | 1 - .../rate-limiting/base/gen/definitions.json | 3 +-- blueprints/rate-limiting/base/gen/values.yaml | 1 - .../inter-service-rate-limiting/policy.yaml | 3 --- .../guides/assets/managing-quotas/policy.yaml | 1 - docs/content/guides/assets/openai/policy.yaml | 2 -- .../policies/assets/raw_values.yaml | 1 - .../blueprints/concurrency-limiting/base.md | 2 +- .../blueprints/concurrency-scheduling/base.md | 4 +-- .../blueprints/quota-scheduling/base.md | 4 +-- .../blueprints/rate-limiting/base.md | 2 +- pkg/scheduler/wfq.go | 25 +++++++++++++++++++ .../policies/concurrency-scheduler-cr.yaml | 3 --- .../policies/concurrency-scheduling-cr.yaml | 4 +-- .../policies/concurrency-scheduling.yaml | 2 +- .../policies/quota-scheduler-cr.yaml | 3 --- sdks/aperture-go/examples/manual/go.mod | 2 +- sdks/aperture-go/examples/manual/go.sum | 4 +-- sdks/aperture-go/examples/manual/main.go | 15 +++++++---- 28 files changed, 54 insertions(+), 73 deletions(-) diff --git a/blueprints/concurrency-limiting/base/config.libsonnet b/blueprints/concurrency-limiting/base/config.libsonnet index ef45b52a75..da2ca52d15 100644 --- a/blueprints/concurrency-limiting/base/config.libsonnet +++ b/blueprints/concurrency-limiting/base/config.libsonnet @@ -13,7 +13,6 @@ commonConfig { max_concurrency: '__REQUIRED_FIELD__', selectors: commonConfig.selectors_defaults, parameters: { - limit_by_label_key: 'limit_by_label_key', max_inflight_duration: '__REQUIRED_FIELD__', }, request_parameters: {}, diff --git a/blueprints/concurrency-limiting/base/gen/definitions.json b/blueprints/concurrency-limiting/base/gen/definitions.json index bfd9947efb..c13412fe4b 100644 --- a/blueprints/concurrency-limiting/base/gen/definitions.json +++ b/blueprints/concurrency-limiting/base/gen/definitions.json @@ -67,7 +67,6 @@ "parameters": { "description": "Parameters.", "default": { - "limit_by_label_key": "limit_by_label_key", "max_inflight_duration": "__REQUIRED_FIELD__" }, "type": "object", diff --git a/blueprints/concurrency-limiting/base/gen/values.yaml b/blueprints/concurrency-limiting/base/gen/values.yaml index 2d6fb53eb2..df065c97f7 100644 --- a/blueprints/concurrency-limiting/base/gen/values.yaml +++ b/blueprints/concurrency-limiting/base/gen/values.yaml @@ -29,7 +29,6 @@ policy: # Type: aperture.spec.v1.ConcurrencyLimiterParameters # Required: True parameters: - limit_by_label_key: "limit_by_label_key" max_inflight_duration: __REQUIRED_FIELD__ # Request Parameters. # Type: aperture.spec.v1.ConcurrencyLimiterRequestParameters diff --git a/blueprints/concurrency-scheduling/base/config.libsonnet b/blueprints/concurrency-scheduling/base/config.libsonnet index 3f88e008e1..50a4851940 100644 --- a/blueprints/concurrency-scheduling/base/config.libsonnet +++ b/blueprints/concurrency-scheduling/base/config.libsonnet @@ -13,14 +13,9 @@ commonConfig { max_concurrency: '__REQUIRED_FIELD__', selectors: commonConfig.selectors_defaults, concurrency_limiter: { - limit_by_label_key: 'limit_by_label_key', max_inflight_duration: '__REQUIRED_FIELD__', }, - scheduler: { - tokens_label_key: 'tokens', - priority_label_key: 'priority', - workload_label_key: 'workload', - }, + scheduler: {}, alerter: { alert_name: 'Too many inflight requests', }, diff --git a/blueprints/concurrency-scheduling/base/gen/definitions.json b/blueprints/concurrency-scheduling/base/gen/definitions.json index 81afa83720..988b45e953 100644 --- a/blueprints/concurrency-scheduling/base/gen/definitions.json +++ b/blueprints/concurrency-scheduling/base/gen/definitions.json @@ -61,7 +61,6 @@ "concurrency_limiter": { "description": "Concurrency Limiter Parameters.", "default": { - "limit_by_label_key": "limit_by_label_key", "max_inflight_duration": "__REQUIRED_FIELD__" }, "type": "object", @@ -75,11 +74,7 @@ }, "scheduler": { "description": "Scheduler configuration.", - "default": { - "priority_label_key": "priority", - "tokens_label_key": "tokens", - "workload_label_key": "workload" - }, + "default": {}, "type": "object", "$ref": "../../../gen/jsonschema/_definitions.json#/definitions/Scheduler" }, diff --git a/blueprints/concurrency-scheduling/base/gen/values.yaml b/blueprints/concurrency-scheduling/base/gen/values.yaml index a59ce455bd..8e0f4dc89d 100644 --- a/blueprints/concurrency-scheduling/base/gen/values.yaml +++ b/blueprints/concurrency-scheduling/base/gen/values.yaml @@ -25,7 +25,6 @@ policy: # Type: aperture.spec.v1.ConcurrencyLimiterParameters # Required: True concurrency_limiter: - limit_by_label_key: "limit_by_label_key" max_inflight_duration: __REQUIRED_FIELD__ # Max concurrency. # Type: float64 @@ -33,10 +32,7 @@ policy: max_concurrency: __REQUIRED_FIELD__ # Scheduler configuration. # Type: aperture.spec.v1.Scheduler - scheduler: - priority_label_key: "priority" - tokens_label_key: "tokens" - workload_label_key: "workload" + scheduler: {} # Flow selectors to match requests against. # Type: []aperture.spec.v1.Selector # Required: True diff --git a/blueprints/quota-scheduling/base/config.libsonnet b/blueprints/quota-scheduling/base/config.libsonnet index c7ea95f588..b1530677c4 100644 --- a/blueprints/quota-scheduling/base/config.libsonnet +++ b/blueprints/quota-scheduling/base/config.libsonnet @@ -15,14 +15,9 @@ commonConfig { fill_amount: '__REQUIRED_FIELD__', selectors: commonConfig.selectors_defaults, rate_limiter: { - limit_by_label_key: 'limit_key', interval: '__REQUIRED_FIELD__', }, - scheduler: { - tokens_label_key: 'tokens', - priority_label_key: 'priority', - workload_label_key: 'workload', - }, + scheduler: {}, alerter: { alert_name: 'More than 90% of requests are being rate limited', }, diff --git a/blueprints/quota-scheduling/base/gen/definitions.json b/blueprints/quota-scheduling/base/gen/definitions.json index 5bb9048839..97c841de2a 100644 --- a/blueprints/quota-scheduling/base/gen/definitions.json +++ b/blueprints/quota-scheduling/base/gen/definitions.json @@ -78,19 +78,14 @@ "rate_limiter": { "description": "Rate Limiter Parameters.", "default": { - "interval": "__REQUIRED_FIELD__", - "limit_by_label_key": "limit_key" + "interval": "__REQUIRED_FIELD__" }, "type": "object", "$ref": "../../../gen/jsonschema/_definitions.json#/definitions/RateLimiterParameters" }, "scheduler": { "description": "Scheduler configuration.", - "default": { - "priority_label_key": "priority", - "tokens_label_key": "tokens", - "workload_label_key": "workload" - }, + "default": {}, "type": "object", "$ref": "../../../gen/jsonschema/_definitions.json#/definitions/Scheduler" }, diff --git a/blueprints/quota-scheduling/base/gen/values.yaml b/blueprints/quota-scheduling/base/gen/values.yaml index 90b1967ecb..3758adf906 100644 --- a/blueprints/quota-scheduling/base/gen/values.yaml +++ b/blueprints/quota-scheduling/base/gen/values.yaml @@ -34,13 +34,9 @@ policy: # Required: True rate_limiter: interval: __REQUIRED_FIELD__ - limit_by_label_key: "limit_key" # Scheduler configuration. # Type: aperture.spec.v1.Scheduler - scheduler: - priority_label_key: "priority" - tokens_label_key: "tokens" - workload_label_key: "workload" + scheduler: {} # Flow selectors to match requests against. # Type: []aperture.spec.v1.Selector # Required: True diff --git a/blueprints/rate-limiting/base/config.libsonnet b/blueprints/rate-limiting/base/config.libsonnet index 2c8a24c3c6..01c88eff09 100644 --- a/blueprints/rate-limiting/base/config.libsonnet +++ b/blueprints/rate-limiting/base/config.libsonnet @@ -15,7 +15,6 @@ commonConfig { fill_amount: '__REQUIRED_FIELD__', selectors: commonConfig.selectors_defaults, parameters: { - limit_by_label_key: 'limit_key', interval: '__REQUIRED_FIELD__', }, request_parameters: {}, diff --git a/blueprints/rate-limiting/base/gen/definitions.json b/blueprints/rate-limiting/base/gen/definitions.json index 48de2877f8..244a1bd2ab 100644 --- a/blueprints/rate-limiting/base/gen/definitions.json +++ b/blueprints/rate-limiting/base/gen/definitions.json @@ -78,8 +78,7 @@ "parameters": { "description": "Parameters.", "default": { - "interval": "__REQUIRED_FIELD__", - "limit_by_label_key": "limit_key" + "interval": "__REQUIRED_FIELD__" }, "type": "object", "$ref": "../../../gen/jsonschema/_definitions.json#/definitions/RateLimiterParameters" diff --git a/blueprints/rate-limiting/base/gen/values.yaml b/blueprints/rate-limiting/base/gen/values.yaml index 691f746fdf..3eea9e97c4 100644 --- a/blueprints/rate-limiting/base/gen/values.yaml +++ b/blueprints/rate-limiting/base/gen/values.yaml @@ -34,7 +34,6 @@ policy: # Required: True parameters: interval: __REQUIRED_FIELD__ - limit_by_label_key: "limit_key" # Request Parameters. # Type: aperture.spec.v1.RateLimiterRequestParameters request_parameters: {} diff --git a/docs/content/aperture-for-infra/guides/api-quota-management/assets/inter-service-rate-limiting/policy.yaml b/docs/content/aperture-for-infra/guides/api-quota-management/assets/inter-service-rate-limiting/policy.yaml index ec8e6cdc92..1baf23bb0f 100644 --- a/docs/content/aperture-for-infra/guides/api-quota-management/assets/inter-service-rate-limiting/policy.yaml +++ b/docs/content/aperture-for-infra/guides/api-quota-management/assets/inter-service-rate-limiting/policy.yaml @@ -26,9 +26,6 @@ spec: num_sync: 4 limit_by_label_key: api_key scheduler: - priority_label_key: priority - tokens_label_key: tokens - workload_label_key: workload workloads: - label_matcher: match_labels: diff --git a/docs/content/guides/assets/managing-quotas/policy.yaml b/docs/content/guides/assets/managing-quotas/policy.yaml index 0797259d12..e16e241b7f 100644 --- a/docs/content/guides/assets/managing-quotas/policy.yaml +++ b/docs/content/guides/assets/managing-quotas/policy.yaml @@ -24,7 +24,6 @@ spec: limit_by_label_key: user_id scheduler: priority_label_key: priority - tokens_label_key: tokens workload_label_key: workload selectors: - control_point: quota-scheduling-feature diff --git a/docs/content/guides/assets/openai/policy.yaml b/docs/content/guides/assets/openai/policy.yaml index 63750eeaa4..a20200d372 100644 --- a/docs/content/guides/assets/openai/policy.yaml +++ b/docs/content/guides/assets/openai/policy.yaml @@ -24,8 +24,6 @@ spec: limit_by_label_key: api_key scheduler: priority_label_key: priority - tokens_label_key: tokens - workload_label_key: workload selectors: - control_point: openai label_matcher: diff --git a/docs/content/reference/aperture-cli/policies/assets/raw_values.yaml b/docs/content/reference/aperture-cli/policies/assets/raw_values.yaml index 691f746fdf..3eea9e97c4 100644 --- a/docs/content/reference/aperture-cli/policies/assets/raw_values.yaml +++ b/docs/content/reference/aperture-cli/policies/assets/raw_values.yaml @@ -34,7 +34,6 @@ policy: # Required: True parameters: interval: __REQUIRED_FIELD__ - limit_by_label_key: "limit_key" # Request Parameters. # Type: aperture.spec.v1.RateLimiterRequestParameters request_parameters: {} diff --git a/docs/content/reference/blueprints/concurrency-limiting/base.md b/docs/content/reference/blueprints/concurrency-limiting/base.md index 0c2bfeddc4..f1ee1f92c4 100644 --- a/docs/content/reference/blueprints/concurrency-limiting/base.md +++ b/docs/content/reference/blueprints/concurrency-limiting/base.md @@ -121,7 +121,7 @@ href={`https://github.com/fluxninja/aperture/tree/${aver}/blueprints/concurrency description='Parameters.' type='Object (aperture.spec.v1.ConcurrencyLimiterParameters)' reference='../../configuration/spec#concurrency-limiter-parameters' - value='{"limit_by_label_key": "limit_by_label_key", "max_inflight_duration": "__REQUIRED_FIELD__"}' + value='{"max_inflight_duration": "__REQUIRED_FIELD__"}' /> diff --git a/docs/content/reference/blueprints/concurrency-scheduling/base.md b/docs/content/reference/blueprints/concurrency-scheduling/base.md index 4afd98aa04..d64011e9b9 100644 --- a/docs/content/reference/blueprints/concurrency-scheduling/base.md +++ b/docs/content/reference/blueprints/concurrency-scheduling/base.md @@ -107,7 +107,7 @@ href={`https://github.com/fluxninja/aperture/tree/${aver}/blueprints/concurrency description='Concurrency Limiter Parameters.' type='Object (aperture.spec.v1.ConcurrencyLimiterParameters)' reference='../../configuration/spec#concurrency-limiter-parameters' - value='{"limit_by_label_key": "limit_by_label_key", "max_inflight_duration": "__REQUIRED_FIELD__"}' + value='{"max_inflight_duration": "__REQUIRED_FIELD__"}' /> @@ -135,7 +135,7 @@ href={`https://github.com/fluxninja/aperture/tree/${aver}/blueprints/concurrency description='Scheduler configuration.' type='Object (aperture.spec.v1.Scheduler)' reference='../../configuration/spec#scheduler' - value='{"priority_label_key": "priority", "tokens_label_key": "tokens", "workload_label_key": "workload"}' + value='{}' /> diff --git a/docs/content/reference/blueprints/quota-scheduling/base.md b/docs/content/reference/blueprints/quota-scheduling/base.md index 687b340032..2d31e57c77 100644 --- a/docs/content/reference/blueprints/quota-scheduling/base.md +++ b/docs/content/reference/blueprints/quota-scheduling/base.md @@ -135,7 +135,7 @@ href={`https://github.com/fluxninja/aperture/tree/${aver}/blueprints/quota-sched description='Rate Limiter Parameters.' type='Object (aperture.spec.v1.RateLimiterParameters)' reference='../../configuration/spec#rate-limiter-parameters' - value='{"interval": "__REQUIRED_FIELD__", "limit_by_label_key": "limit_key"}' + value='{"interval": "__REQUIRED_FIELD__"}' /> @@ -149,7 +149,7 @@ href={`https://github.com/fluxninja/aperture/tree/${aver}/blueprints/quota-sched description='Scheduler configuration.' type='Object (aperture.spec.v1.Scheduler)' reference='../../configuration/spec#scheduler' - value='{"priority_label_key": "priority", "tokens_label_key": "tokens", "workload_label_key": "workload"}' + value='{}' /> diff --git a/docs/content/reference/blueprints/rate-limiting/base.md b/docs/content/reference/blueprints/rate-limiting/base.md index c5aca5e1d5..5af13ac4d6 100644 --- a/docs/content/reference/blueprints/rate-limiting/base.md +++ b/docs/content/reference/blueprints/rate-limiting/base.md @@ -135,7 +135,7 @@ href={`https://github.com/fluxninja/aperture/tree/${aver}/blueprints/rate-limiti description='Parameters.' type='Object (aperture.spec.v1.RateLimiterParameters)' reference='../../configuration/spec#rate-limiter-parameters' - value='{"interval": "__REQUIRED_FIELD__", "limit_by_label_key": "limit_key"}' + value='{"interval": "__REQUIRED_FIELD__"}' /> diff --git a/pkg/scheduler/wfq.go b/pkg/scheduler/wfq.go index 4779e1e218..0d198379b3 100644 --- a/pkg/scheduler/wfq.go +++ b/pkg/scheduler/wfq.go @@ -528,11 +528,32 @@ func (pMetrics *preemptionMetrics) onQueueEntry(request *Request, qRequest *queu // Update metrics for preemption and delay // WARNING: Unsafe and should be called with scheduler lock. func (pMetrics *preemptionMetrics) onQueueExit(request *Request, qRequest *queuedRequest, allowed bool) { + initMetrics := func(labels prometheus.Labels) error { + var err error + _, err = pMetrics.workloadPreemptedTokensSummary.GetMetricWith(labels) + if err != nil { + return fmt.Errorf("%w: failed to get workload_preempted_tokens summary", err) + } + _, err = pMetrics.workloadDelayedTokensSummary.GetMetricWith(labels) + if err != nil { + return fmt.Errorf("%w: failed to get workload_delayed_tokens summary", err) + } + _, err = pMetrics.workloadOnTimeCounter.GetMetricWith(labels) + if err != nil { + return fmt.Errorf("%w: failed to get workload_on_time_total counter", err) + } + return nil + } + publishSummary := func(summary *prometheus.SummaryVec, value float64) { if summary == nil { return } metricsLabels := appendWorkloadLabel(pMetrics.metricsLabels, request.FairnessLabel) + err := initMetrics(metricsLabels) + if err != nil { + log.Error().Err(err).Msg("Failed to initialize metrics") + } observer, err := summary.GetMetricWith(metricsLabels) if err != nil { log.Error().Err(err).Msg("Failed to get workload preempted tokens summary") @@ -546,6 +567,10 @@ func (pMetrics *preemptionMetrics) onQueueExit(request *Request, qRequest *queue return } metricsLabels := appendWorkloadLabel(pMetrics.metricsLabels, request.FairnessLabel) + err := initMetrics(metricsLabels) + if err != nil { + log.Error().Err(err).Msg("Failed to initialize metrics") + } counter, err := counterVec.GetMetricWith(metricsLabels) if err != nil { log.Error().Err(err).Msg("Failed to get workload on time counter") diff --git a/playground/scenarios/concurrency-scheduler/policies/concurrency-scheduler-cr.yaml b/playground/scenarios/concurrency-scheduler/policies/concurrency-scheduler-cr.yaml index a73a9f0f69..b9b6bb55ab 100644 --- a/playground/scenarios/concurrency-scheduler/policies/concurrency-scheduler-cr.yaml +++ b/playground/scenarios/concurrency-scheduler/policies/concurrency-scheduler-cr.yaml @@ -20,9 +20,6 @@ spec: accept_percentage: signal_name: ACCEPT_PERCENTAGE scheduler: - priority_label_key: priority - tokens_label_key: tokens - workload_label_key: workload workloads: - label_matcher: match_labels: diff --git a/playground/scenarios/postgres-concurrency/policies/concurrency-scheduling-cr.yaml b/playground/scenarios/postgres-concurrency/policies/concurrency-scheduling-cr.yaml index 941be02f17..fc67c6ab45 100644 --- a/playground/scenarios/postgres-concurrency/policies/concurrency-scheduling-cr.yaml +++ b/playground/scenarios/postgres-concurrency/policies/concurrency-scheduling-cr.yaml @@ -10,20 +10,18 @@ spec: - flow_control: concurrency_scheduler: concurrency_limiter: - limit_by_label_key: limit_by_label_key max_idle_time: 7200s max_inflight_duration: 60s in_ports: max_concurrency: constant_signal: - value: 10 + value: 2 out_ports: accept_percentage: signal_name: ACCEPT_PERCENTAGE scheduler: denied_response_status_code: BadRequest priority_label_key: priority - tokens_label_key: tokens workload_label_key: userType selectors: - agent_group: default diff --git a/playground/scenarios/postgres-concurrency/policies/concurrency-scheduling.yaml b/playground/scenarios/postgres-concurrency/policies/concurrency-scheduling.yaml index 268ae277a7..b296a7bd07 100644 --- a/playground/scenarios/postgres-concurrency/policies/concurrency-scheduling.yaml +++ b/playground/scenarios/postgres-concurrency/policies/concurrency-scheduling.yaml @@ -17,7 +17,7 @@ policy: concurrency_limiter: max_inflight_duration: 60s max_idle_time: "7200s" - max_concurrency: 10 + max_concurrency: 2 scheduler: workload_label_key: "userType" priority_label_key: "priority" diff --git a/playground/scenarios/quota-scheduler/policies/quota-scheduler-cr.yaml b/playground/scenarios/quota-scheduler/policies/quota-scheduler-cr.yaml index d49442a87d..bab0394a59 100644 --- a/playground/scenarios/quota-scheduler/policies/quota-scheduler-cr.yaml +++ b/playground/scenarios/quota-scheduler/policies/quota-scheduler-cr.yaml @@ -26,9 +26,6 @@ spec: num_sync: 4 limit_by_label_key: http.request.header.api_key scheduler: - priority_label_key: priority - tokens_label_key: tokens - workload_label_key: workload workloads: - label_matcher: match_labels: diff --git a/sdks/aperture-go/examples/manual/go.mod b/sdks/aperture-go/examples/manual/go.mod index a9029c61e1..524de5badb 100644 --- a/sdks/aperture-go/examples/manual/go.mod +++ b/sdks/aperture-go/examples/manual/go.mod @@ -12,7 +12,7 @@ require ( require ( github.com/cenkalti/backoff/v4 v4.2.1 // indirect github.com/envoyproxy/protoc-gen-validate v1.0.2 // indirect - github.com/fluxninja/aperture/api/v2 v2.0.0-20240101092959-235caef8dbad // indirect + github.com/fluxninja/aperture/api/v2 v2.0.0-20240104011105-0680993ed282 // indirect github.com/go-logr/logr v1.3.0 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/golang/protobuf v1.5.3 // indirect diff --git a/sdks/aperture-go/examples/manual/go.sum b/sdks/aperture-go/examples/manual/go.sum index a854b00355..b35b4b9e4c 100644 --- a/sdks/aperture-go/examples/manual/go.sum +++ b/sdks/aperture-go/examples/manual/go.sum @@ -4,8 +4,8 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1 github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/envoyproxy/protoc-gen-validate v1.0.2 h1:QkIBuU5k+x7/QXPvPPnWXWlCdaBFApVqftFV6k087DA= github.com/envoyproxy/protoc-gen-validate v1.0.2/go.mod h1:GpiZQP3dDbg4JouG/NNS7QWXpgx6x8QiMKdmN72jogE= -github.com/fluxninja/aperture/api/v2 v2.0.0-20240101092959-235caef8dbad h1:J4SgDerz6NPEARbKEXvR5nAjSN1DWJ2J3NnzJKM+JcU= -github.com/fluxninja/aperture/api/v2 v2.0.0-20240101092959-235caef8dbad/go.mod h1:KSjIteqXmGJl1WOxQeBF9/K6/0sMHfKsRl5VOQkxyNg= +github.com/fluxninja/aperture/api/v2 v2.0.0-20240104011105-0680993ed282 h1:3UK/8Z97YO2o6WutDRmKiWLeURT/x5+aFTBIIf/fh4Q= +github.com/fluxninja/aperture/api/v2 v2.0.0-20240104011105-0680993ed282/go.mod h1:KSjIteqXmGJl1WOxQeBF9/K6/0sMHfKsRl5VOQkxyNg= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY= github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= diff --git a/sdks/aperture-go/examples/manual/main.go b/sdks/aperture-go/examples/manual/main.go index da8e76473f..9926dcb129 100644 --- a/sdks/aperture-go/examples/manual/main.go +++ b/sdks/aperture-go/examples/manual/main.go @@ -5,6 +5,7 @@ import ( "crypto/tls" "crypto/x509" "database/sql" + "encoding/json" "log" "net" "net/http" @@ -79,11 +80,8 @@ func main() { DialOptions: grpcOptions(apertureAgentInsecureBool, apertureAgentSkipVerifyBool), } - ctxTimeout, cancel := context.WithTimeout(ctx, 10*time.Second) - defer cancel() - // initialize Aperture Client with the provided options. - apertureClient, err := aperture.NewClient(ctxTimeout, opts) + apertureClient, err := aperture.NewClient(ctx, opts) if err != nil { log.Fatalf("failed to create client: %v", err) } @@ -229,8 +227,11 @@ func (a *app) PostgresHandler(w http.ResponseWriter, r *http.Request) { RampMode: false, } + ctxTimeout, cancel := context.WithTimeout(r.Context(), 10*time.Second) + defer cancel() + log.Printf("Starting flow with params: %+v", flowParams) - flow := a.apertureClient.StartFlow(r.Context(), "postgres", flowParams) + flow := a.apertureClient.StartFlow(ctxTimeout, "postgres", flowParams) if flow.ShouldRun() { time.Sleep(2 * time.Second) @@ -250,6 +251,10 @@ func (a *app) PostgresHandler(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusForbidden) } + checkResponse := flow.CheckResponse() + checkResponseBytes, _ := json.Marshal(checkResponse) + log.Printf("Flow check response: %+v", string(checkResponseBytes)) + endResponse := flow.End() if endResponse.Error != nil { log.Printf("Failed to end flow: %+v", endResponse.Error)