Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pgsql scenario #3125

Merged
merged 12 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions api/buf.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ deps:
- remote: buf.build
owner: envoyproxy
repository: envoy
commit: 5b59168cb47246a3b40d27598b6d5909
digest: shake256:e219b11f3e40c9e2956286c5de5d2cb3ea6288228b5f6126be163dbe62b050e7accef81d13e5cf35b447e6903a3f21b82019e676ad8b858ca60c48ca8126e391
commit: 39f01805b8754956a78bc77bda4c3761
digest: shake256:a7e7c7675618056879597d6205e394e85b63b71fd1766818042e6fd9b5c4fd623bede2784a9c635dced61fb40a22610812f164ed40c7a0cecbe50c0ecc76952d
- remote: buf.build
owner: envoyproxy
repository: protoc-gen-validate
Expand Down
1 change: 0 additions & 1 deletion blueprints/concurrency-limiting/base/config.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -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: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
"parameters": {
"description": "Parameters.",
"default": {
"limit_by_label_key": "limit_by_label_key",
"max_inflight_duration": "__REQUIRED_FIELD__"
},
"type": "object",
Expand Down
1 change: 0 additions & 1 deletion blueprints/concurrency-limiting/base/gen/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 1 addition & 6 deletions blueprints/concurrency-scheduling/base/config.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -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__',
},
hdkshingala marked this conversation as resolved.
Show resolved Hide resolved
scheduler: {
tokens_label_key: 'tokens',
priority_label_key: 'priority',
workload_label_key: 'workload',
},
scheduler: {},
alerter: {
alert_name: 'Too many inflight requests',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
},
Expand Down
6 changes: 1 addition & 5 deletions blueprints/concurrency-scheduling/base/gen/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,14 @@ 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
# Required: True
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
Expand Down
7 changes: 1 addition & 6 deletions blueprints/quota-scheduling/base/config.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -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: {},
hdkshingala marked this conversation as resolved.
Show resolved Hide resolved
alerter: {
alert_name: 'More than 90% of requests are being rate limited',
},
Expand Down
9 changes: 2 additions & 7 deletions blueprints/quota-scheduling/base/gen/definitions.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
6 changes: 1 addition & 5 deletions blueprints/quota-scheduling/base/gen/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion blueprints/rate-limiting/base/config.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -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: {},
Expand Down
3 changes: 1 addition & 2 deletions blueprints/rate-limiting/base/gen/definitions.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion blueprints/rate-limiting/base/gen/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion docs/content/guides/assets/managing-quotas/policy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions docs/content/guides/assets/openai/policy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

This blueprint provides a concurrency limiting policy and a dashboard. This
policy uses the
[`ConcurrencyLimiter`](/reference/configuration/spec.md#concurrency-limiter)

Check warning on line 12 in docs/content/reference/blueprints/concurrency-limiting/base.md

View workflow job for this annotation

GitHub Actions / languagetool

[LanguageTool] reported by reviewdog 🐶 This sentence does not start with an uppercase letter. (UPPERCASE_SENTENCE_START) Suggestions: `Component` URL: https://languagetool.org/insights/post/spelling-capital-letters/ Rule: https://community.languagetool.org/rule/show/UPPERCASE_SENTENCE_START?lang=en-US Category: CASING Raw Output: docs/content/reference/blueprints/concurrency-limiting/base.md:12:77: This sentence does not start with an uppercase letter. (UPPERCASE_SENTENCE_START) Suggestions: `Component` URL: https://languagetool.org/insights/post/spelling-capital-letters/ Rule: https://community.languagetool.org/rule/show/UPPERCASE_SENTENCE_START?lang=en-US Category: CASING
component.

<!-- Configuration Marker -->
Expand Down Expand Up @@ -121,7 +121,7 @@
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__"}'
/>

<!-- vale on -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

This blueprint provides a concurrency scheduling policy and a dashboard. This
policy uses the
[`ConcurrencyScheduler`](/reference/configuration/spec.md#concurrency-scheduler)

Check warning on line 12 in docs/content/reference/blueprints/concurrency-scheduling/base.md

View workflow job for this annotation

GitHub Actions / languagetool

[LanguageTool] reported by reviewdog 🐶 This sentence does not start with an uppercase letter. (UPPERCASE_SENTENCE_START) Suggestions: `Component` URL: https://languagetool.org/insights/post/spelling-capital-letters/ Rule: https://community.languagetool.org/rule/show/UPPERCASE_SENTENCE_START?lang=en-US Category: CASING Raw Output: docs/content/reference/blueprints/concurrency-scheduling/base.md:12:81: This sentence does not start with an uppercase letter. (UPPERCASE_SENTENCE_START) Suggestions: `Component` URL: https://languagetool.org/insights/post/spelling-capital-letters/ Rule: https://community.languagetool.org/rule/show/UPPERCASE_SENTENCE_START?lang=en-US Category: CASING
component.

<!-- Configuration Marker -->
Expand Down Expand Up @@ -107,7 +107,7 @@
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__"}'
/>

<!-- vale on -->
Expand Down Expand Up @@ -135,7 +135,7 @@
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='{}'
/>

<!-- vale on -->
Expand Down
4 changes: 2 additions & 2 deletions docs/content/reference/blueprints/quota-scheduling/base.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
## Introduction

This blueprint provides a
[token bucket](https://en.wikipedia.org/wiki/Token_bucket) based quota scheduler

Check warning on line 11 in docs/content/reference/blueprints/quota-scheduling/base.md

View workflow job for this annotation

GitHub Actions / languagetool

[LanguageTool] reported by reviewdog 🐶 This expression is usually spelled with a hyphen. (BASED_HYPHEN[1]) Suggestions: `bucket-based` Rule: https://community.languagetool.org/rule/show/BASED_HYPHEN?lang=en-US&subId=1 Category: COMPOUNDING Raw Output: docs/content/reference/blueprints/quota-scheduling/base.md:11:7: This expression is usually spelled with a hyphen. (BASED_HYPHEN[1]) Suggestions: `bucket-based` Rule: https://community.languagetool.org/rule/show/BASED_HYPHEN?lang=en-US&subId=1 Category: COMPOUNDING
policy and a dashboard. This policy uses the
[`QuotaScheduler`](/reference/configuration/spec.md#quota-scheduler) component.

Expand Down Expand Up @@ -135,7 +135,7 @@
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__"}'
/>

<!-- vale on -->
Expand All @@ -149,7 +149,7 @@
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='{}'
/>

<!-- vale on -->
Expand Down
2 changes: 1 addition & 1 deletion docs/content/reference/blueprints/rate-limiting/base.md
Original file line number Diff line number Diff line change
Expand Up @@ -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__"}'
hdkshingala marked this conversation as resolved.
Show resolved Hide resolved
/>

<!-- vale on -->
Expand Down
25 changes: 25 additions & 0 deletions pkg/scheduler/wfq.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
hdkshingala marked this conversation as resolved.
Show resolved Hide resolved
}

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")
hdkshingala marked this conversation as resolved.
Show resolved Hide resolved
}
observer, err := summary.GetMetricWith(metricsLabels)
if err != nil {
log.Error().Err(err).Msg("Failed to get workload preempted tokens summary")
Expand All @@ -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")
}
hdkshingala marked this conversation as resolved.
Show resolved Hide resolved
counter, err := counterVec.GetMetricWith(metricsLabels)
if err != nil {
log.Error().Err(err).Msg("Failed to get workload on time counter")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { randomIntBetween } from "https://jslib.k6.io/k6-utils/1.4.0/index.js";
import { check, sleep } from "k6";
import { vu } from "k6/execution";
import http from "k6/http";

export let vuStages = [
{ duration: "10s", target: 10 },
{ duration: "2m", target: 50 },
{ duration: "10s", target: 10 },
];

export let options = {
discardResponseBodies: true,
scenarios: {
guests: {
executor: "ramping-vus",
stages: vuStages,
env: { USER_TYPE: "guest" },
},
subscribers: {
executor: "ramping-vus",
stages: vuStages,
env: { USER_TYPE: "subscriber" },
},
},
};

export default function () {
let userType = __ENV.USER_TYPE;
let userId = vu.idInTest;
const url = "http://localhost:8099/postgres";
const headers = {
"Content-Type": "application/json",
Cookie:
"session=eyJ1c2VyIjoia2Vub2JpIn0.YbsY4Q.kTaKRTyOIfVlIbNB48d9YH6Q0wo",
"User-Type": userType,
"User-Id": userId,
};
const body = {}
let res = http.request("POST", url, JSON.stringify(body), {
headers: headers,
});
const ret = check(res, {
"http status was 200": res.status === 200,
});
if (!ret) {
// sleep for 10ms to 25ms
sleep(randomIntBetween(0.01, 0.025));
}
}
26 changes: 26 additions & 0 deletions playground/scenarios/postgres-concurrency/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"renderer": "tanka",
"tkenv": "playground/tanka/apps/aperture-go-example",
"needs": ["postgresql"],
"aperture_policies": [
{
"policy_name": "concurrency-scheduling",
"values_file": "policies/concurrency-scheduling.yaml"
}
],
"images": [
{
"ref": "aperture-go-example",
"context": "sdks/aperture-go",
"dockerfile": "Dockerfile.manual",
"ssh": "default"
}
],
"child_resources": [
{
"workload": "aperture-go-example",
"resource_deps": ["cluster-bootstrap", "postgresql"],
"extra_objects": ["aperture-go-example:serviceaccount"]
}
]
}
Loading
Loading