Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request #117 from STCLab-Inc/107-create-a-variety-of-metri…
Browse files Browse the repository at this point in the history
…c-usage-examples

feat: Create a variety of metric usage examples
  • Loading branch information
pueding authored Jul 27, 2023
2 parents 0286fee + eac9c5e commit 5ae9167
Show file tree
Hide file tree
Showing 18 changed files with 140 additions and 106 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ core/wave-cli/vector*
# core/wave-metrics
core/wave-metrics/telegraf*
core/wave-metrics/vector*
telegraf*/
vector*/

# VSCode
.vscode/
7 changes: 5 additions & 2 deletions .moon/tasks/rust.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
tasks:
clean:
clean-cargo:
command: "cargo clean"
platform: "system"
clean-db:
command: "find . -type f -name 'wave.db' -exec rm {} + > /dev/null"
platform: "system"
inputs:
Expand All @@ -19,7 +22,7 @@ tasks:
test:
deps:
- "lint"
- "clean"
- "clean-db"
run:
deps:
- "test"
Expand Down
20 changes: 19 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,25 @@
$ moon sync hooks
```


## Development

### When you work on core/wave-autoscale
```bash
# Run
moon run controller:[test|run]

# If you need a situation that metrics are sent to the database and your plan responses to the metrics
# Edit core/wave-autoscale/tests/simulation.rs for your situation
moon run controller:test-simulation
```

### When you work on core/wave-metrics
- Telegraf Tips
```toml
# Print metrics to stdout
[[outputs.file]]
files = ["stdout"]
```
## Coding Rules

### Rust
Expand Down
20 changes: 1 addition & 19 deletions core/wave-autoscale/moon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,7 @@ tasks:
- "@globs(tests)"
env:
RUST_LOG: wave_autoscale=debug
# Run
run-help:
command: "cargo watch -c -x 'run -- --help'"
deps:
- "lint"
inputs:
- "@globs(sources)"
env:
RUST_LOG: debug
run-autoscaling-history-retention:
# command: "cargo watch -c -x 'run -- --autoscaling-history-retention=1d'"
command: "cargo run -- --autoscaling-history-retention=1d"
deps:
- "lint"
inputs:
- "@globs(sources)"
env:
RUST_LOG: wave_controller=debug
test-metrics-simulation:
test-simulation:
command: "cargo nextest run -p wave-autoscale test_simulation --no-capture"
deps:
- "data-layer:lint"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mod metrics_test {
mod simulation_test {
use data_layer::data_layer::DataLayer;
use log::debug;
use serde_json::json;
Expand Down
15 changes: 0 additions & 15 deletions core/wave-autoscale/tests/yaml/metric_cloudwatch_data.yaml

This file was deleted.

22 changes: 0 additions & 22 deletions core/wave-autoscale/tests/yaml/metric_cloudwatch_statistics.yaml

This file was deleted.

23 changes: 0 additions & 23 deletions core/wave-autoscale/tests/yaml/metric_prometheus.yaml

This file was deleted.

5 changes: 3 additions & 2 deletions core/wave-cli/moon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ tasks:
- "--config"
- "../../tests/config/wave-config.yaml"
- "--definition"
- "../wave-metrics/tests/yaml/cloudwatch-definition.yaml"
- "../wave-metrics/tests/metrics-examples/vector-host-metrics.yaml"
- "--collectors-info"
- "../wave-metrics/tests/yaml/collectors.yaml"
- "../wave-metrics/tests/collectors/collectors.yaml"
deps:
# TODO: Build web-app
- "copy-wave-controller"
Expand All @@ -54,6 +54,7 @@ tasks:
- "wave-api-server"
- "wave-metrics"
- "wave-web-app/**/*"
- "tests/db/wave.db"
env:
RUST_LOG: wave_cli=debug
options:
Expand Down
6 changes: 4 additions & 2 deletions core/wave-metrics/moon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ tasks:
- "--config"
- "./tests/config/wave-config.yaml"
- "--definition"
- "./core/wave-metrics/tests/yaml/cloudwatch-definition.yaml"
- "./core/wave-metrics/tests/metrics-examples/vector-host-metrics.yaml"
- "--collectors-info"
- "./core/wave-metrics/tests/yaml/collectors.yaml"
- "./core/wave-metrics/tests/collectors/collectors.yaml"
env:
RUST_LOG: wave_metrics=debug
inputs:
- "@globs(tests)"
# Build for Production
# Linux
build-aarch64-unknown-linux-gnu:
Expand Down
4 changes: 2 additions & 2 deletions core/wave-metrics/src/metric_collector_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,8 +542,8 @@ mod tests {
let _ = std::fs::remove_file("./wave.db");

MetricCollectorManager::new(
"./tests/yaml/collectors.yaml",
"http://localhost:8081/api/metrics-receiver",
"./tests/collectors/collectors.yaml",
"http://localhost:3024/api/metrics-receiver",
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# https://github.com/influxdata/telegraf/blob/master/plugins/inputs/cloudwatch/README.md
---
kind: Metric
id: cloudwatch_dynamodb_metric
id: cloudwatch_dynamodb_metrics
collector: telegraf
metric_kind: cloudwatch
metadata:
Expand All @@ -28,7 +28,7 @@ metadata:
# Output in the database will be like this:
# [
# {
# "name": "cloudwatch_dynamodb_metric_consumed_write_capacity_units_sample_count",
# "name": "cloudwatch_dynamodb_metrics_consumed_write_capacity_units_sample_count",
# "tags": {
# "host": "Hwansoos-Laptop.local",
# "region": "ap-northeast-3",
Expand All @@ -48,7 +48,7 @@ metadata:
# # JavaScript expression that returns a boolean value.
# expression: >
# get({
# name: 'cloudwatch_dynamodb_metric_consumed_write_capacity_units_sample_count'
# name: 'cloudwatch_dynamodb_metrics_consumed_write_capacity_units_sample_count'
# }) > 30
# # Higher priority values will be checked first.
# priority: 1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# References - Telegraf Stackdriver Google Cloud Monitoring Input Plugin
# https://github.com/influxdata/telegraf/blob/release-1.27/plugins/inputs/stackdriver/README.md
---
kind: Metric
id: google_cloud_monitoring_mig_metrics
collector: telegraf
metric_kind: stackdriver
metadata:
project: wave-autoscale-test
## Include timeseries that start with the given metric type.
metric_type_prefix_include: ["compute.googleapis.com/instance/cpu/utilization"]
interval: "1m"

# Output in the database will be like this:
# [
# {
# "name": "google_cloud_monitoring_mig_metrics_utilization",
# "tags": {
# "host": "local",
# "instance_id": "3137596874116707338",
# "instance_name": "test-instance-group-1-lp73",
# "project_id": "wave-autoscale-test",
# "resource_type": "gce_instance",
# "zone": "asia-northeast2-a"
# },
# "value": 0.009973257744559306
# },
# {
# "name": "google_cloud_monitoring_mig_metrics_utilization",
# "tags": {
# "host": "local",
# "instance_id": "8022840066979737199",
# "instance_name": "instance-group-2-r32v",
# "project_id": "wave-autoscale-test",
# "resource_type": "gce_instance",
# "zone": "asia-northeast2-a"
# },
# "value": 0.04300702278317961
# },
# {
# "name": "google_cloud_monitoring_mig_metrics_utilization",
# "tags": {
# "host": "local",
# "instance_id": "851205196260609218",
# "instance_name": "instance-group-2-wpng",
# "project_id": "wave-autoscale-test",
# "resource_type": "gce_instance",
# "zone": "asia-northeast2-a"
# },
# "value": 0.0171343613359871
# }
# ]


# ---
# kind: ScalingPlan
# id: google_scaling_plan
# title: "Scaling Plan for Google VM Instance"
# plans:
# - id: scale-up-plan-1
# description: "Scale up"
# # JavaScript expression that returns a boolean value.
# expression: >
# get({
# name: 'google_cloud_monitoring_mig_metrics_utilization'
# }) > 0.04
# # Higher priority values will be checked first.
# priority: 1
# scaling_components:
# ...
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# https://github.com/influxdata/telegraf/blob/master/plugins/inputs/mem/README.md
---
kind: Metric
id: telegraf_mem_metrics
collector: telegraf
metric_kind: mem
metadata:
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# https://vector.dev/docs/reference/configuration/sources/host_metrics/
---
kind: Metric
id: vector_host_metrics
collector: vector
metric_kind: host_metrics
metadata:
namespace: host
scrape_interval_secs: 5
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# https://vector.dev/docs/reference/configuration/sources/prometheus_scrape/#query
---
kind: Metric
id: vector_host_metrics
collector: vector
metric_kind: prometheus_scrape
metadata:
endpoints:
- http://localhost:9090/metrics
query:
"match[]":
- '{job="somejob"}'
- '{__name__=~"job:.*"}'
scrape_interval_secs: 15
14 changes: 0 additions & 14 deletions core/wave-metrics/tests/yaml/definition.yaml

This file was deleted.

0 comments on commit 5ae9167

Please sign in to comment.