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

Group the services in a serverless NEG and put them all behind a load balancer #8

Merged
merged 1 commit into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ To use these services, in your ISLE `docker-compose.yml` you can point to the Cl
alpaca-prod: &alpaca-prod
<<: [*prod, *alpaca]
environment:
ALPACA_DERIVATIVE_FITS_URL: https://CR_URL
ALPACA_DERIVATIVE_HOMARUS_URL: https://CR_URL
ALPACA_DERIVATIVE_HOUDINI_URL: https://CR_URL
ALPACA_DERIVATIVE_OCR_URL: https://CR_URL
ALPACA_DERIVATIVE_FITS_URL: https://microservice.libops.site/crayfits
ALPACA_DERIVATIVE_HOMARUS_URL: https://microservice.libops.site/homarus
ALPACA_DERIVATIVE_HOUDINI_URL: https://microservice.libops.site/houdini
ALPACA_DERIVATIVE_OCR_URL: https://microservice.libops.site/hypercube
```
12 changes: 12 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,15 @@ EOT
docker = docker.local
}
}

module "lb" {
source = "./modules/lb"

project = var.project
backends = {
"homarus" = module.homarus.backend,
"houdini" = module.houdini.backend,
"hypercube" = module.hypercube.backend,
"crayfits" = module.crayfits.backend
}
}
35 changes: 35 additions & 0 deletions modules/cloudrun/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,38 @@ resource "google_cloud_run_service_iam_member" "invoker" {
role = "roles/run.invoker"
member = "allUsers"
}

# create a serverless NEG for this set of regional services
resource "google_compute_region_network_endpoint_group" "neg" {
count = length(var.regions)

name = "libops-neg-${google_cloud_run_service.cloudrun[count.index].name}"
network_endpoint_type = "SERVERLESS"
region = google_cloud_run_service.cloudrun[count.index].location
project = var.project

cloud_run {
service = google_cloud_run_service.cloudrun[count.index].name
}
}

resource "google_compute_backend_service" "backend" {
project = var.project
name = "libops-backend-${var.name}"

load_balancing_scheme = "EXTERNAL_MANAGED"
protocol = "HTTPS"

dynamic "backend" {
for_each = google_compute_region_network_endpoint_group.neg

content {
group = backend.value.id
}
}

log_config {
enable = true
sample_rate = 1.0
}
}
3 changes: 3 additions & 0 deletions modules/cloudrun/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "backend" {
value = google_compute_backend_service.backend.id
}
306 changes: 306 additions & 0 deletions modules/lb/dashboard.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,306 @@
{
"displayName": "Cloud CDN",
"mosaicLayout": {
"columns": 12,
"tiles": [
{
"height": 4,
"widget": {
"title": "Request Count by Continent",
"xyChart": {
"chartOptions": {
"mode": "COLOR"
},
"dataSets": [
{
"plotType": "STACKED_AREA",
"timeSeriesQuery": {
"timeSeriesQueryLanguage": "fetch https_lb_rule\n| metric 'loadbalancing.googleapis.com/https/request_count'\n| align rate(1m)\n| every 1m\n| group_by [metric.proxy_continent],\n [row_count: row_count()]"
}
}
],
"timeshiftDuration": "0s",
"yAxis": {
"scale": "LINEAR"
}
}
},
"width": 6,
"yPos": 8
},
{
"height": 4,
"widget": {
"title": "Cache Hit Response Bytes by Continent",
"xyChart": {
"chartOptions": {
"mode": "COLOR"
},
"dataSets": [
{
"plotType": "STACKED_BAR",
"timeSeriesQuery": {
"timeSeriesQueryLanguage": "fetch https_lb_rule\n| metric 'loadbalancing.googleapis.com/https/response_bytes_count'\n| filter (metric.cache_result = 'HIT')\n| align rate(1m)\n| every 1m\n| group_by [metric.proxy_continent],\n [value_response_bytes_count_aggregate:\n aggregate(value.response_bytes_count)]"
}
}
],
"timeshiftDuration": "0s",
"yAxis": {
"scale": "LINEAR"
}
}
},
"width": 6,
"xPos": 6,
"yPos": 4
},
{
"height": 4,
"widget": {
"title": "Cache Status by Count",
"xyChart": {
"chartOptions": {
"mode": "COLOR"
},
"dataSets": [
{
"plotType": "LINE",
"timeSeriesQuery": {
"timeSeriesQueryLanguage": "fetch https_lb_rule\n| metric 'loadbalancing.googleapis.com/https/request_count'\n| align rate(1m)\n| every 1m\n| group_by [metric.cache_result],\n [row_count: row_count()]\n"
}
}
],
"timeshiftDuration": "0s",
"yAxis": {
"scale": "LINEAR"
}
}
},
"width": 6,
"yPos": 4
},
{
"height": 4,
"widget": {
"title": "Response Egress by Cache Status",
"xyChart": {
"chartOptions": {
"mode": "COLOR"
},
"dataSets": [
{
"plotType": "STACKED_AREA",
"timeSeriesQuery": {
"timeSeriesQueryLanguage": "fetch https_lb_rule\n| metric 'loadbalancing.googleapis.com/https/response_bytes_count'\n| align rate(1m)\n| every 1m\n| group_by [metric.cache_result],\n [value_response_bytes_count_aggregate:\n aggregate(value.response_bytes_count)]"
}
}
],
"timeshiftDuration": "0s",
"yAxis": {
"scale": "LINEAR"
}
}
},
"width": 6,
"xPos": 6
},
{
"height": 4,
"widget": {
"title": "Latency by Continent 95%",
"xyChart": {
"chartOptions": {
"mode": "COLOR"
},
"dataSets": [
{
"plotType": "LINE",
"timeSeriesQuery": {
"timeSeriesQueryLanguage": "fetch https_lb_rule\n| metric 'loadbalancing.googleapis.com/https/frontend_tcp_rtt'\n| group_by 1m,\n [value_frontend_tcp_rtt_aggregate: aggregate(value.frontend_tcp_rtt)]\n| every 1m\n| group_by [metric.proxy_continent],\n [value_frontend_tcp_rtt_aggregate_percentile:\n percentile(value_frontend_tcp_rtt_aggregate, 95)]"
}
}
],
"timeshiftDuration": "0s",
"yAxis": {
"scale": "LINEAR"
}
}
},
"width": 6,
"yPos": 12
},
{
"height": 4,
"widget": {
"title": "Client Response Code",
"xyChart": {
"chartOptions": {
"mode": "COLOR"
},
"dataSets": [
{
"plotType": "STACKED_AREA",
"timeSeriesQuery": {
"timeSeriesQueryLanguage": "fetch https_lb_rule\n| metric 'loadbalancing.googleapis.com/https/request_count'\n| group_by 1h, [row_count: row_count()]\n| every 1h\n| group_by [metric.response_code_class],\n [row_count_aggregate: aggregate(row_count)]"
}
}
],
"timeshiftDuration": "0s",
"yAxis": {
"scale": "LINEAR"
}
}
},
"width": 6,
"xPos": 6,
"yPos": 8
},
{
"height": 4,
"widget": {
"title": "Non 2xx Error Codes",
"xyChart": {
"chartOptions": {
"mode": "COLOR"
},
"dataSets": [
{
"plotType": "STACKED_AREA",
"timeSeriesQuery": {
"timeSeriesQueryLanguage": "fetch https_lb_rule\n| metric 'loadbalancing.googleapis.com/https/request_count'\n| filter (metric.response_code_class != 200)\n| group_by 1h, [row_count: row_count()]\n| every 1h\n| group_by [metric.response_code_class],\n [row_count_aggregate: aggregate(row_count)]"
}
}
],
"timeshiftDuration": "0s",
"yAxis": {
"scale": "LINEAR"
}
}
},
"width": 6,
"xPos": 6,
"yPos": 12
},
{
"height": 2,
"widget": {
"scorecard": {
"timeSeriesQuery": {
"timeSeriesFilter": {
"aggregation": {
"alignmentPeriod": "60s",
"crossSeriesReducer": "REDUCE_SUM",
"perSeriesAligner": "ALIGN_SUM"
},
"filter": "metric.type=\"loadbalancing.googleapis.com/https/request_count\" resource.type=\"https_lb_rule\""
}
}
},
"title": "Total Requests"
},
"width": 3
},
{
"height": 2,
"widget": {
"scorecard": {
"timeSeriesQuery": {
"timeSeriesFilter": {
"aggregation": {
"alignmentPeriod": "60s",
"crossSeriesReducer": "REDUCE_SUM",
"perSeriesAligner": "ALIGN_SUM"
},
"filter": "metric.type=\"loadbalancing.googleapis.com/https/response_bytes_count\" resource.type=\"https_lb_rule\""
}
}
},
"title": "Total Egress"
},
"width": 3,
"xPos": 3
},
{
"height": 2,
"widget": {
"scorecard": {
"timeSeriesQuery": {
"timeSeriesFilter": {
"aggregation": {
"alignmentPeriod": "60s",
"crossSeriesReducer": "REDUCE_SUM",
"perSeriesAligner": "ALIGN_SUM"
},
"filter": "metric.type=\"loadbalancing.googleapis.com/https/response_bytes_count\" resource.type=\"https_lb_rule\" metric.label.\"cache_result\"=\"HIT\""
}
}
},
"title": "Cache Hit Egress"
},
"width": 3,
"yPos": 2
},
{
"height": 2,
"widget": {
"scorecard": {
"timeSeriesQuery": {
"timeSeriesFilter": {
"aggregation": {
"alignmentPeriod": "60s",
"crossSeriesReducer": "REDUCE_SUM",
"perSeriesAligner": "ALIGN_SUM"
},
"filter": "metric.type=\"loadbalancing.googleapis.com/https/response_bytes_count\" resource.type=\"https_lb_rule\" metric.label.\"cache_result\"=\"MISS\""
}
}
},
"title": "Cache Miss Egress"
},
"width": 3,
"xPos": 3,
"yPos": 2
},
{
"height": 4,
"widget": {
"title": "Request Count by Country",
"xyChart": {
"chartOptions": {
"mode": "COLOR"
},
"dataSets": [
{
"minAlignmentPeriod": "60s",
"plotType": "STACKED_AREA",
"timeSeriesQuery": {
"timeSeriesFilter": {
"aggregation": {
"alignmentPeriod": "60s",
"perSeriesAligner": "ALIGN_RATE"
},
"filter": "metric.type=\"loadbalancing.googleapis.com/https/request_count\" resource.type=\"https_lb_rule\"",
"secondaryAggregation": {
"alignmentPeriod": "60s",
"crossSeriesReducer": "REDUCE_SUM",
"groupByFields": [
"metric.label.\"client_country\""
],
"perSeriesAligner": "ALIGN_SUM"
}
}
}
}
],
"timeshiftDuration": "0s",
"yAxis": {
"scale": "LINEAR"
}
}
},
"width": 6,
"yPos": 16
}
]
}
}
Loading
Loading