Skip to content

Commit 42f65f7

Browse files
authored
Add Backend Service Custom Metrics. (#13205)
Signed-off-by: Misha Efimov <[email protected]>
1 parent 4b2f171 commit 42f65f7

File tree

5 files changed

+412
-2
lines changed

5 files changed

+412
-2
lines changed

mmv1/products/compute/BackendService.yaml

+76-2
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,14 @@ examples:
120120
primary_resource_id: 'default'
121121
vars:
122122
backend_service_name: 'backend-service'
123+
- name: 'backend_service_custom_metrics'
124+
primary_resource_id: 'default'
125+
min_version: 'beta'
126+
vars:
127+
backend_service_name: 'backend-service'
128+
default_neg_name: 'network-endpoint'
129+
health_check_name: 'health-check'
130+
network_name: 'network'
123131
parameters:
124132
properties:
125133
- name: 'affinityCookieTtlSec'
@@ -147,8 +155,8 @@ properties:
147155
Specifies the balancing mode for this backend.
148156
149157
For global HTTP(S) or TCP/SSL load balancing, the default is
150-
UTILIZATION. Valid values are UTILIZATION, RATE (for HTTP(S))
151-
and CONNECTION (for TCP/SSL).
158+
UTILIZATION. Valid values are UTILIZATION, RATE (for HTTP(S)),
159+
CUSTOM_METRICS (for HTTP(s)) and CONNECTION (for TCP/SSL).
152160
153161
See the [Backend Services Overview](https://cloud.google.com/load-balancing/docs/backend-service#balancing-mode)
154162
for an explanation of load balancing modes.
@@ -157,6 +165,7 @@ properties:
157165
- 'UTILIZATION'
158166
- 'RATE'
159167
- 'CONNECTION'
168+
- 'CUSTOM_METRICS'
160169
- name: 'capacityScaler'
161170
type: Double
162171
description: |
@@ -261,6 +270,38 @@ properties:
261270
Used when balancingMode is UTILIZATION. This ratio defines the
262271
CPU utilization target for the group. Valid range is [0.0, 1.0].
263272
default_from_api: true
273+
- name: 'customMetrics'
274+
type: Array
275+
description: |
276+
The set of custom metrics that are used for <code>CUSTOM_METRICS</code> BalancingMode.
277+
item_type:
278+
type: NestedObject
279+
properties:
280+
- name: 'name'
281+
type: String
282+
required: true
283+
description: |
284+
Name of a custom utilization signal. The name must be 1-64 characters
285+
long and match the regular expression [a-z]([-_.a-z0-9]*[a-z0-9])? which
286+
means the first character must be a lowercase letter, and all following
287+
characters must be a dash, period, underscore, lowercase letter, or
288+
digit, except the last character, which cannot be a dash, period, or
289+
underscore. For usage guidelines, see Custom Metrics balancing mode. This
290+
field can only be used for a global or regional backend service with the
291+
loadBalancingScheme set to <code>EXTERNAL_MANAGED</code>,
292+
<code>INTERNAL_MANAGED</code> <code>INTERNAL_SELF_MANAGED</code>.
293+
- name: 'dryRun'
294+
type: Boolean
295+
required: true
296+
description: |
297+
If true, the metric data is collected and reported to Cloud
298+
Monitoring, but is not used for load balancing.
299+
- name: 'maxUtilization'
300+
type: Double
301+
description: |
302+
Optional parameter to define a target utilization for the Custom Metrics
303+
balancing mode. The valid range is <code>[0.0, 1.0]</code>.
304+
default_value: 0.8
264305
- name: 'circuitBreakers'
265306
type: NestedObject
266307
description: |
@@ -840,6 +881,13 @@ properties:
840881
UNAVAILABLE_WEIGHT. Otherwise, Load Balancing remains
841882
equal-weight.
842883
884+
* `WEIGHTED_ROUND_ROBIN`: Per-endpoint weighted round-robin Load Balancing using weights computed
885+
from Backend reported Custom Metrics. If set, the Backend Service
886+
responses are expected to contain non-standard HTTP response header field
887+
X-Endpoint-Load-Metrics. The reported metrics
888+
to use for computing the weights are specified via the
889+
backends[].customMetrics fields.
890+
843891
locality_lb_policy is applicable to either:
844892
845893
* A regional backend service with the service_protocol set to HTTP, HTTPS, or HTTP2,
@@ -863,6 +911,7 @@ properties:
863911
- 'ORIGINAL_DESTINATION'
864912
- 'MAGLEV'
865913
- 'WEIGHTED_MAGLEV'
914+
- 'WEIGHTED_ROUND_ROBIN'
866915
- name: 'localityLbPolicies'
867916
type: Array
868917
description: |
@@ -960,6 +1009,31 @@ properties:
9601009
description: |
9611010
An optional, arbitrary JSON object with configuration data, understood
9621011
by a locally installed custom policy implementation.
1012+
- name: 'customMetrics'
1013+
type: Array
1014+
description: |
1015+
List of custom metrics that are used for the WEIGHTED_ROUND_ROBIN locality_lb_policy.
1016+
item_type:
1017+
type: NestedObject
1018+
properties:
1019+
- name: 'name'
1020+
type: String
1021+
required: true
1022+
description: |
1023+
Name of a custom utilization signal. The name must be 1-64 characters
1024+
long and match the regular expression [a-z]([-_.a-z0-9]*[a-z0-9])? which
1025+
means the first character must be a lowercase letter, and all following
1026+
characters must be a dash, period, underscore, lowercase letter, or
1027+
digit, except the last character, which cannot be a dash, period, or
1028+
underscore. For usage guidelines, see Custom Metrics balancing mode. This
1029+
field can only be used for a global or regional backend service with the
1030+
loadBalancingScheme set to <code>EXTERNAL_MANAGED</code>,
1031+
<code>INTERNAL_MANAGED</code> <code>INTERNAL_SELF_MANAGED</code>.
1032+
- name: 'dryRun'
1033+
type: Boolean
1034+
required: true
1035+
description: |
1036+
If true, the metric data is not used for load balancing.
9631037
- name: 'name'
9641038
type: String
9651039
description: |

mmv1/products/compute/RegionBackendService.yaml

+74
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@ examples:
121121
vars:
122122
region_backend_service_name: 'region-service'
123123
health_check_name: 'rbs-health-check'
124+
- name: 'region_backend_service_ilb_custom_metrics'
125+
primary_resource_id: 'default'
126+
min_version: 'beta'
127+
vars:
128+
region_backend_service_name: 'region-service'
129+
default_neg_name: 'network-endpoint'
130+
health_check_name: 'rbs-health-check'
131+
network_name: 'network'
124132
parameters:
125133
- name: 'region'
126134
type: ResourceRef
@@ -165,6 +173,7 @@ properties:
165173
- 'UTILIZATION'
166174
- 'RATE'
167175
- 'CONNECTION'
176+
- 'CUSTOM_METRICS'
168177
- name: 'capacityScaler'
169178
type: Double
170179
description: |
@@ -280,6 +289,38 @@ properties:
280289
Used when balancingMode is UTILIZATION. This ratio defines the
281290
CPU utilization target for the group. Valid range is [0.0, 1.0].
282291
Cannot be set for INTERNAL backend services.
292+
- name: 'customMetrics'
293+
type: Array
294+
description: |
295+
The set of custom metrics that are used for <code>CUSTOM_METRICS</code> BalancingMode.
296+
item_type:
297+
type: NestedObject
298+
properties:
299+
- name: 'name'
300+
type: String
301+
required: true
302+
description: |
303+
Name of a custom utilization signal. The name must be 1-64 characters
304+
long and match the regular expression [a-z]([-_.a-z0-9]*[a-z0-9])? which
305+
means the first character must be a lowercase letter, and all following
306+
characters must be a dash, period, underscore, lowercase letter, or
307+
digit, except the last character, which cannot be a dash, period, or
308+
underscore. For usage guidelines, see Custom Metrics balancing mode. This
309+
field can only be used for a global or regional backend service with the
310+
loadBalancingScheme set to <code>EXTERNAL_MANAGED</code>,
311+
<code>INTERNAL_MANAGED</code> <code>INTERNAL_SELF_MANAGED</code>.
312+
- name: 'dryRun'
313+
type: Boolean
314+
required: true
315+
description: |
316+
If true, the metric data is collected and reported to Cloud
317+
Monitoring, but is not used for load balancing.
318+
- name: 'maxUtilization'
319+
type: Double
320+
description: |
321+
Optional parameter to define a target utilization for the Custom Metrics
322+
balancing mode. The valid range is <code>[0.0, 1.0]</code>.
323+
default_value: 0.8
283324
- name: 'circuitBreakers'
284325
type: NestedObject
285326
description: |
@@ -851,6 +892,13 @@ properties:
851892
UNAVAILABLE_WEIGHT. Otherwise, Load Balancing remains
852893
equal-weight.
853894
895+
* `WEIGHTED_ROUND_ROBIN`: Per-endpoint weighted round-robin Load Balancing using weights computed
896+
from Backend reported Custom Metrics. If set, the Backend Service
897+
responses are expected to contain non-standard HTTP response header field
898+
X-Endpoint-Load-Metrics. The reported metrics
899+
to use for computing the weights are specified via the
900+
backends[].customMetrics fields.
901+
854902
locality_lb_policy is applicable to either:
855903
856904
* A regional backend service with the service_protocol set to HTTP, HTTPS, or HTTP2,
@@ -874,6 +922,7 @@ properties:
874922
- 'ORIGINAL_DESTINATION'
875923
- 'MAGLEV'
876924
- 'WEIGHTED_MAGLEV'
925+
- 'WEIGHTED_ROUND_ROBIN'
877926
- name: 'name'
878927
type: String
879928
description: |
@@ -886,6 +935,31 @@ properties:
886935
character, which cannot be a dash.
887936
required: true
888937
immutable: true
938+
- name: 'customMetrics'
939+
type: Array
940+
description: |
941+
List of custom metrics that are used for the WEIGHTED_ROUND_ROBIN locality_lb_policy.
942+
item_type:
943+
type: NestedObject
944+
properties:
945+
- name: 'name'
946+
type: String
947+
required: true
948+
description: |
949+
Name of a custom utilization signal. The name must be 1-64 characters
950+
long and match the regular expression [a-z]([-_.a-z0-9]*[a-z0-9])? which
951+
means the first character must be a lowercase letter, and all following
952+
characters must be a dash, period, underscore, lowercase letter, or
953+
digit, except the last character, which cannot be a dash, period, or
954+
underscore. For usage guidelines, see Custom Metrics balancing mode. This
955+
field can only be used for a global or regional backend service with the
956+
loadBalancingScheme set to <code>EXTERNAL_MANAGED</code>,
957+
<code>INTERNAL_MANAGED</code> <code>INTERNAL_SELF_MANAGED</code>.
958+
- name: 'dryRun'
959+
type: Boolean
960+
required: true
961+
description: |
962+
If true, the metric data is not used for load balancing.
889963
- name: 'outlierDetection'
890964
type: NestedObject
891965
description: |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
resource "google_compute_network" "default" {
2+
provider = google-beta
3+
name = "{{index $.Vars "network_name"}}"
4+
}
5+
6+
// Zonal NEG with GCE_VM_IP_PORT
7+
resource "google_compute_network_endpoint_group" "default" {
8+
provider = google-beta
9+
name = "{{index $.Vars "default_neg_name"}}"
10+
network = google_compute_network.default.id
11+
default_port = "90"
12+
zone = "us-central1-a"
13+
network_endpoint_type = "GCE_VM_IP_PORT"
14+
}
15+
16+
resource "google_compute_backend_service" "{{$.PrimaryResourceId}}" {
17+
provider = google-beta
18+
name = "{{index $.Vars "backend_service_name"}}"
19+
health_checks = [google_compute_health_check.default.id]
20+
21+
# WEIGHTED_ROUND_ROBIN and CUSTOM_METRICS require EXTERNAL_MANAGED.
22+
load_balancing_scheme = "EXTERNAL_MANAGED"
23+
locality_lb_policy = "WEIGHTED_ROUND_ROBIN"
24+
custom_metrics {
25+
name = "orca.application_utilization"
26+
# At least one metric should be not dry_run.
27+
dry_run = false
28+
}
29+
backend {
30+
group = google_compute_network_endpoint_group.default.id
31+
balancing_mode = "CUSTOM_METRICS"
32+
custom_metrics {
33+
name = "orca.cpu_utilization"
34+
max_utilization = 0.9
35+
dry_run = true
36+
}
37+
custom_metrics {
38+
name = "orca.named_metrics.foo"
39+
# At least one metric should be not dry_run.
40+
dry_run = false
41+
}
42+
}
43+
}
44+
45+
resource "google_compute_health_check" "default" {
46+
provider = google-beta
47+
name = "{{index $.Vars "health_check_name"}}"
48+
timeout_sec = 1
49+
check_interval_sec = 1
50+
51+
tcp_health_check {
52+
port = "80"
53+
}
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
resource "google_compute_network" "default" {
2+
provider = google-beta
3+
name = "{{index $.Vars "network_name"}}"
4+
}
5+
6+
// Zonal NEG with GCE_VM_IP_PORT
7+
resource "google_compute_network_endpoint_group" "default" {
8+
provider = google-beta
9+
name = "{{index $.Vars "default_neg_name"}}"
10+
network = google_compute_network.default.id
11+
default_port = "90"
12+
zone = "us-central1-a"
13+
network_endpoint_type = "GCE_VM_IP_PORT"
14+
}
15+
16+
resource "google_compute_region_backend_service" "{{$.PrimaryResourceId}}" {
17+
provider = google-beta
18+
19+
region = "us-central1"
20+
name = "{{index $.Vars "region_backend_service_name"}}"
21+
health_checks = [google_compute_health_check.health_check.id]
22+
load_balancing_scheme = "INTERNAL_MANAGED"
23+
locality_lb_policy = "WEIGHTED_ROUND_ROBIN"
24+
custom_metrics {
25+
name = "orca.application_utilization"
26+
# At least one metric should be not dry_run.
27+
dry_run = false
28+
}
29+
backend {
30+
group = google_compute_network_endpoint_group.default.id
31+
balancing_mode = "CUSTOM_METRICS"
32+
custom_metrics {
33+
name = "orca.cpu_utilization"
34+
max_utilization = 0.9
35+
dry_run = true
36+
}
37+
custom_metrics {
38+
name = "orca.named_metrics.foo"
39+
# At least one metric should be not dry_run.
40+
dry_run = false
41+
}
42+
}
43+
}
44+
45+
resource "google_compute_health_check" "health_check" {
46+
provider = google-beta
47+
name = "{{index $.Vars "health_check_name"}}"
48+
http_health_check {
49+
port = 80
50+
}
51+
}

0 commit comments

Comments
 (0)