Skip to content

Commit f4fac2a

Browse files
authored
Add custom labels for Machine Learning Forecasting (#894)
Add support for adding custom labels on forecasting. Using the updated machine-learning-go-client v0.5.0
1 parent 3d6234f commit f4fac2a

File tree

6 files changed

+16
-3
lines changed

6 files changed

+16
-3
lines changed

docs/resources/machine_learning_job.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ A job defines the queries and model parameters for a machine learning task.
2424

2525
### Optional
2626

27+
- `custom_labels` (Map of String) An object representing the custom labels added on the forecast.
2728
- `datasource_id` (Number) The id of the datasource to query.
2829
- `datasource_uid` (String) The uid of the datasource to query.
2930
- `description` (String) A description of the job.

examples/resources/grafana_machine_learning_job/tuned_job.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@ resource "grafana_machine_learning_job" "test_job" {
1010
daily_seasonality = 15
1111
weekly_seasonality = 10
1212
}
13+
custom_labels = {
14+
example_label = "example_value"
15+
}
1316
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/Masterminds/semver/v3 v3.2.1
77
github.com/grafana/amixr-api-go-client v0.0.7
88
github.com/grafana/grafana-api-golang-client v0.19.0
9-
github.com/grafana/machine-learning-go-client v0.4.0
9+
github.com/grafana/machine-learning-go-client v0.5.0
1010
github.com/grafana/synthetic-monitoring-agent v0.14.3
1111
github.com/grafana/synthetic-monitoring-api-go-client v0.7.0
1212
github.com/hashicorp/go-cleanhttp v0.5.2

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ github.com/grafana/amixr-api-go-client v0.0.7 h1:U6W6yKxMMybI+Qz4zl+Vih48o6CczLa
7474
github.com/grafana/amixr-api-go-client v0.0.7/go.mod h1:N6x26XUrM5zGtK5zL5vNJnAn2JFMxLFPPLTw/6pDkFE=
7575
github.com/grafana/grafana-api-golang-client v0.19.0 h1:4z8voB2nv/bMiP4WbCKdhCym2mltSDFUzOrDqzohrw0=
7676
github.com/grafana/grafana-api-golang-client v0.19.0/go.mod h1:24W29gPe9yl0/3A9X624TPkAOR8DpHno490cPwnkv8E=
77-
github.com/grafana/machine-learning-go-client v0.4.0 h1:UAkJPE7xujzFTm0d9ctbX/FsCID8rqejWjnkRPGNM6E=
78-
github.com/grafana/machine-learning-go-client v0.4.0/go.mod h1:QFfZz8NkqVF8++skjkKQXJEZfpCYd8S0yTWJUpsLLTA=
77+
github.com/grafana/machine-learning-go-client v0.5.0 h1:Q1K+MPSy8vfMm2jsk3WQ7O77cGr2fM5hxwtPSoPc5NU=
78+
github.com/grafana/machine-learning-go-client v0.5.0/go.mod h1:QFfZz8NkqVF8++skjkKQXJEZfpCYd8S0yTWJUpsLLTA=
7979
github.com/grafana/synthetic-monitoring-agent v0.14.3 h1:M7HZmTJKJLF53Fv7KZeb2KyzHSx7gbHiJ3Mr/ApfCRA=
8080
github.com/grafana/synthetic-monitoring-agent v0.14.3/go.mod h1:izjAJZb+Q+/GZogJ8Nls6HQlmIUaHUfCtinPCU3HhSw=
8181
github.com/grafana/synthetic-monitoring-api-go-client v0.7.0 h1:3ZfQzmXDBPcQTTgMAIIiTw5Dwxm/B4lzf34Sto0d0YY=

internal/resources/machinelearning/resource_job.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ A job defines the queries and model parameters for a machine learning task.
6969
Type: schema.TypeMap,
7070
Required: true,
7171
},
72+
"custom_labels": {
73+
Description: "An object representing the custom labels added on the forecast.",
74+
Type: schema.TypeMap,
75+
Optional: true,
76+
Default: nil,
77+
},
7278
"interval": {
7379
Description: "The data interval in seconds to train the data on.",
7480
Type: schema.TypeInt,
@@ -148,6 +154,7 @@ func ResourceJobRead(ctx context.Context, d *schema.ResourceData, meta interface
148154
d.Set("query_params", job.QueryParams)
149155
d.Set("interval", job.Interval)
150156
d.Set("hyper_params", job.HyperParams)
157+
d.Set("custom_labels", job.CustomLabels)
151158
d.Set("training_window", job.TrainingWindow)
152159
d.Set("holidays", job.Holidays)
153160

@@ -196,6 +203,7 @@ func makeMLJob(d *schema.ResourceData, meta interface{}) (mlapi.Job, error) {
196203
Interval: uint(d.Get("interval").(int)),
197204
Algorithm: "grafana_prophet_1_0_1",
198205
HyperParams: d.Get("hyper_params").(map[string]interface{}),
206+
CustomLabels: d.Get("custom_labels").(map[string]interface{}),
199207
TrainingWindow: uint(d.Get("training_window").(int)),
200208
TrainingFrequency: uint(24 * time.Hour / time.Second),
201209
Holidays: common.ListToStringSlice(d.Get("holidays").([]interface{})),

internal/resources/machinelearning/resource_job_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ func TestAccResourceJob(t *testing.T) {
6161
resource.TestCheckResourceAttr("grafana_machine_learning_job.test_job", "training_window", "7776000"),
6262
resource.TestCheckResourceAttr("grafana_machine_learning_job.test_job", "hyper_params.daily_seasonality", "15"),
6363
resource.TestCheckResourceAttr("grafana_machine_learning_job.test_job", "hyper_params.weekly_seasonality", "10"),
64+
resource.TestCheckResourceAttr("grafana_machine_learning_job.test_job", "custom_labels.example_label", "example_value"),
6465
),
6566
},
6667
{

0 commit comments

Comments
 (0)