diff --git a/docs/resources/machine_learning_job.md b/docs/resources/machine_learning_job.md index ab072160b..67a0070fa 100644 --- a/docs/resources/machine_learning_job.md +++ b/docs/resources/machine_learning_job.md @@ -96,6 +96,44 @@ resource "grafana_machine_learning_job" "test_job" { } ``` +### Rescaled Forecast + +This forecast has had the data transformed using a power transformation in order to avoid negative lower predictions. + +```terraform +resource "grafana_data_source" "foo" { + type = "prometheus" + name = "prometheus-ds-test" + uid = "prometheus-ds-test-uid" + url = "https://my-instance.com" + basic_auth_enabled = true + basic_auth_username = "username" + + json_data_encoded = jsonencode({ + httpMethod = "POST" + prometheusType = "Mimir" + prometheusVersion = "2.4.0" + }) + + secure_json_data_encoded = jsonencode({ + basicAuthPassword = "password" + }) +} + +resource "grafana_machine_learning_job" "test_job" { + name = "Test Job" + metric = "tf_test_job" + datasource_type = "prometheus" + datasource_uid = grafana_data_source.foo.uid + query_params = { + expr = "grafanacloud_grafana_instance_active_user_count" + } + hyper_params = { + transformation_id = "power" + } +} +``` + ### Forecast with Holidays This forecast has holidays which will be taken into account when training the model. diff --git a/examples/resources/grafana_machine_learning_job/transformed_job.tf b/examples/resources/grafana_machine_learning_job/transformed_job.tf new file mode 100644 index 000000000..12a2acf5f --- /dev/null +++ b/examples/resources/grafana_machine_learning_job/transformed_job.tf @@ -0,0 +1,31 @@ +resource "grafana_data_source" "foo" { + type = "prometheus" + name = "prometheus-ds-test" + uid = "prometheus-ds-test-uid" + url = "https://my-instance.com" + basic_auth_enabled = true + basic_auth_username = "username" + + json_data_encoded = jsonencode({ + httpMethod = "POST" + prometheusType = "Mimir" + prometheusVersion = "2.4.0" + }) + + secure_json_data_encoded = jsonencode({ + basicAuthPassword = "password" + }) +} + +resource "grafana_machine_learning_job" "test_job" { + name = "Test Job" + metric = "tf_test_job" + datasource_type = "prometheus" + datasource_uid = grafana_data_source.foo.uid + query_params = { + expr = "grafanacloud_grafana_instance_active_user_count" + } + hyper_params = { + transformation_id = "power" + } +} \ No newline at end of file diff --git a/internal/resources/machinelearning/resource_job_test.go b/internal/resources/machinelearning/resource_job_test.go index 201d5deea..618f18a06 100644 --- a/internal/resources/machinelearning/resource_job_test.go +++ b/internal/resources/machinelearning/resource_job_test.go @@ -81,6 +81,22 @@ func TestAccResourceJob(t *testing.T) { resource.TestCheckResourceAttrSet("grafana_machine_learning_job.test_job", "holidays.0"), ), }, + { + Config: testutils.TestAccExampleWithReplace(t, "resources/grafana_machine_learning_job/transformed_job.tf", map[string]string{ + "Test Job": randomName, + }), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("grafana_machine_learning_job.test_job", "id"), + resource.TestCheckResourceAttr("grafana_machine_learning_job.test_job", "name", randomName), + resource.TestCheckResourceAttr("grafana_machine_learning_job.test_job", "metric", "tf_test_job"), + resource.TestCheckResourceAttr("grafana_machine_learning_job.test_job", "datasource_type", "prometheus"), + resource.TestCheckResourceAttr("grafana_machine_learning_job.test_job", "datasource_uid", "prometheus-ds-test-uid"), + resource.TestCheckResourceAttr("grafana_machine_learning_job.test_job", "query_params.expr", "grafanacloud_grafana_instance_active_user_count"), + resource.TestCheckResourceAttr("grafana_machine_learning_job.test_job", "interval", "300"), + resource.TestCheckResourceAttr("grafana_machine_learning_job.test_job", "training_window", "7776000"), + resource.TestCheckResourceAttr("grafana_machine_learning_job.test_job", "hyper_params.transformation_id", "power"), + ), + }, }, }) } diff --git a/templates/resources/machine_learning_job.md.tmpl b/templates/resources/machine_learning_job.md.tmpl index c0981260c..a13c1f3ad 100644 --- a/templates/resources/machine_learning_job.md.tmpl +++ b/templates/resources/machine_learning_job.md.tmpl @@ -26,6 +26,12 @@ This forecast has tuned hyperparameters to improve the accuracy of the model. {{ tffile "examples/resources/grafana_machine_learning_job/tuned_job.tf" }} +### Rescaled Forecast + +This forecast has had the data transformed using a power transformation in order to avoid negative lower predictions. + +{{ tffile "examples/resources/grafana_machine_learning_job/transformed_job.tf" }} + ### Forecast with Holidays This forecast has holidays which will be taken into account when training the model.