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

Custom monitor schedules always setting timezone to UTC for evaluation window #2617

Open
lognarly opened this issue Oct 11, 2024 · 0 comments
Labels

Comments

@lognarly
Copy link

lognarly commented Oct 11, 2024

Datadog Terraform Provider Version

v3.46.0

Terraform Version

v1.9.7

What resources or data sources are affected?

resource_datadog_monitor

Terraform Configuration Files

The below config is stripped of identifying info, so don't be surprised if the main and tfvars don't match up here. The code runs and creates the resources.
main.tf

locals {
  monitors = flatten([
    for interface_name, interface_data in var.interfaces : [
      for query_name, query_data in interface_data.queries : {
        interface_name = interface_name
        query_name     = query_name
        scope          = interface_data.scope
        timezone       = interface_data.timezone
        file_query     = interface_data.file_query
        extra_query    = query_data.extra_query
        rrule          = query_data.rrule
      }
    ]
  ])
}

resource "datadog_monitor" "main" {
  for_each = {
    for idx, monitor in local.monitors : format("%s - %s", monitor.interface_name, monitor.query_name) => monitor
  }
  name                   = format("%s - %s", each.value.interface_name, each.value.query_name)
  type                   = "log alert"
  message                = each.value.message
  query                  = each.value.query
  groupby_simple_monitor = false
  include_tags           = false
  scheduling_options {
    evaluation_window {
      day_starts = "00:00"
    }
    custom_schedule {
      recurrence {
        rrule    = each.value["rrule"]
        timezone = each.value["timezone"]
        start    = format("2024-10-11T%s:%s:00", regex("BYHOUR=([0-9]+)", each.value["rrule"])[0], regex("BYMINUTE=([0-9]+)", each.value["rrule"])[0])
      }
    }
  }
  monitor_thresholds {
    critical = 0
  }
  tags = []
}

terraform.tfvars sample

interfaces = {
  "MW E2Open AUS - DMD Unit (OUT)" = {
    day_starts = "00:00"
    timezone   = "Australia/Sydney"
    file_query = "*file*"
    scope      = "scope"
    queries = {
      Creation = {
        extra_query = "@action:create"
        rrule       = "FREQ=DAILY;BYDAY=SU,MO,TU,WE,TH,FR;BYHOUR=18;BYMINUTE=45"
      }
      Transfer = {
        extra_query = "@action:transfer"
        rrule       = "FREQ=DAILY;BYDAY=SU,MO,TU,WE,TH,FR;BYHOUR=19;BYMINUTE=00"
      }
    }
  }

Relevant debug or panic output

Sample monitor created, as you can see options.scheduling_options.evaluation_window.timezone is set to UTC:

{
	"id": 775746,
	"name": "MW E2Open AUS - Exception Reports - Transfer",
	"type": "log alert",
	"query": "logs(\"myquery\").index(\"*\").rollup(\"count\").current(\"1d\") == 0",
	"message": "my message",
	"tags": [],
	"options": {
		"thresholds": {
			"critical": 0
		},
		"enable_logs_sample": false,
		"notify_audit": false,
		"on_missing_data": "default",
		"include_tags": false,
		"require_full_window": false,
		"scheduling_options": {
			"custom_schedule": {
				"recurrences": [
					{
						"rrule": "FREQ=DAILY;INTERVAL=1;BYHOUR=04;BYMINUTE=30",
						"timezone": "Australia/Sydney"
					}
				]
			},
			"evaluation_window": {
				"day_starts": "00:00",
				"timezone": "UTC"
			}
		},
		"silenced": {}
	},
	"priority": null,
	"restriction_policy": {
		"bindings": []
	}
}

Expected Behavior

I would expect the monitor to inherit the timezone parameter from the recurrence block since there is no timezone parameter within evaluation_window

Actual Behavior

Timezone is getting set to UTC every time.

Steps to Reproduce

  1. terraform init
  2. terraform plan
  3. terraform apply -auto-approve

Important Factoids

No response

References

No response

@lognarly lognarly added the bug label Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant