google / google/slo-generator

💡 [REQUEST] - Add Cloud Run example(s) to Cloud Monitoring backends

Open
#303 2 comments 1 reaction 1 assignee Claimed by @lvaylet View on GitHub
backend docs documentation
Dominant language
Python
Stars
564
Forks
88
PR merge metrics
No merged PRs in 30d

Description

### Summary

We have examples for App Engine, Pub/Sub and Load Balancer. Cloud Run probably deserves its own example(s) too, as it is becoming more and more popular.

### Basic Example

Define your SLO in `slo_cloudrun_service_availability.yaml` (with MQL):

```yaml
apiVersion: sre.google.com/v2
kind: ServiceLevelObjective
metadata:
name: cloudrun-service-availability
labels:
service_name: cloudrun
feature_name: service
slo_name: availability
spec:
description: Availability of Cloud Run service
backend: cloud_monitoring_mql
method: good_bad_ratio
exporters:
- cloud_monitoring
service_level_indicator:
filter_good: >
fetch cloud_run_revision
| metric 'run.googleapis.com/request_count'
| filter resource.project_id == '${CLOUDRUN_PROJECT_ID}'
| filter resource.service_name == '${CLOUDRUN_SERVICE_NAME}'
| filter metric.response_code_class == '2xx'
filter_valid: >
fetch cloud_run_revision
| metric 'run.googleapis.com/request_count'
| filter resource.project_id == '${CLOUDRUN_PROJECT_ID}'
| filter resource.service_name == '${CLOUDRUN_SERVICE_NAME}'
goal: 0.85
```

Populate `${CLOUDRUN_PROJECT_ID}` and `${CLOUDRUN_SERVICE_NAME}` in `.env`:

```sh
export CLOUDRUN_PROJECT_ID=slo-generator-demo
export CLOUDRUN_SERVICE_NAME=cloud-run-randomly-fails
```

Run with:

```sh
$ source .env
$ slo-generator compute --slo-config=samples/cloud_monitoring_mql/slo_cloudrun_service_availability.yaml --config=samples/config.yaml
INFO - cloudrun-service-availability | 1 hour | SLI: 70.0 % | SLO: 85.0 % | Gap: -15.0 % | BR: 2.0 / 9.0 | Alert: 0 | Good: 42 | Bad: 18
INFO - cloudrun-service-availability | 12 hours | SLI: 76.1111 % | SLO: 85.0 % | Gap: -8.89 % | BR: 1.6 / 3.0 | Alert: 0 | Good: 548 | Bad: 172
INFO - cloudrun-service-availability | 7 days | SLI: 75.4186 % | SLO: 85.0 % | Gap: -9.58 % | BR: 1.6 / 1.5 | Alert: 1 | Good: 7612 | Bad: 2481
INFO - cloudrun-service-availability | 28 days | SLI: 75.0158 % | SLO: 85.0 % | Gap: -9.98 % | BR: 1.7 / 1.0 | Alert: 1 | Good: 23783 | Bad: 7921
INFO - Run finished successfully in 7.7s.
INFO - Run summary | SLO Configs: 1 | Duration: 7.7s
```

### Screenshots

```bash
![DESCRIPTION](LINK.png)
```

### Drawbacks

None.

### Unresolved questions

_No response_

### Code of Conduct

- [X] I agree to follow this project's Code of Conduct

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.