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

created custom metrics auto scraping #88

Merged
merged 3 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions aks/application/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ If `azure_enable_monitoring` is `true`, it’s expected that the following resou
- A resource group named `${azure_resource_prefix}-${service_short}-mn-rg` (where `mn` stands for monitoring and `rg` stands for resource group).
- A monitor action group named `${azure_resource_prefix}-${service_name}` within the above resource group.

If `enable_prometheus_monitoring` is `true` then custom metrics are scraped for the application

## Outputs

### `hostname`
Expand Down
8 changes: 8 additions & 0 deletions aks/application/resources.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ locals {
http_probe_enabled = var.is_web && var.probe_path != null
exec_probe_enabled = !var.is_web && length(var.probe_command) != 0
probe_enabled = local.http_probe_enabled || local.exec_probe_enabled
prometheus_scrape_annotations = {
"prometheus.io/scrape" = "true"
"prometheus.io/path" = "/metrics"
"prometheus.io/port" = var.web_port
}
}

resource "kubernetes_deployment" "main" {
Expand All @@ -27,6 +32,9 @@ resource "kubernetes_deployment" "main" {
labels = {
app = local.app_name
}

annotations = var.enable_prometheus_monitoring ? local.prometheus_scrape_annotations : {}

}

spec {
Expand Down
1 change: 1 addition & 0 deletions aks/application/tfdocs.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ No modules.
| <a name="input_cluster_configuration_map"></a> [cluster\_configuration\_map](#input\_cluster\_configuration\_map) | Configuration map for the cluster | <pre>object({<br> resource_group_name = string,<br> resource_prefix = string,<br> dns_zone_prefix = optional(string),<br> cpu_min = number<br> })</pre> | n/a | yes |
| <a name="input_command"></a> [command](#input\_command) | Custom command that overwrites Docker image | `list(string)` | `[]` | no |
| <a name="input_docker_image"></a> [docker\_image](#input\_docker\_image) | Path to the docker image | `string` | n/a | yes |
| <a name="input_enable_prometheus_monitoring"></a> [enable\_prometheus\_monitoring](#input\_enable\_prometheus\_monitoring) | a boolean to indicate whether to scrape(true) custom metrics for application or not(false) | `bool` | `false` | no |
| <a name="input_environment"></a> [environment](#input\_environment) | Current application environment | `string` | n/a | yes |
| <a name="input_github_personal_access_token"></a> [github\_personal\_access\_token](#input\_github\_personal\_access\_token) | Github Personal Access Token (PAT) of github\_username | `string` | `null` | no |
| <a name="input_github_username"></a> [github\_username](#input\_github\_username) | Github user authorised to access the private registry | `string` | `null` | no |
Expand Down
6 changes: 6 additions & 0 deletions aks/application/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ variable "probe_path" {
description = "Path for the liveness and startup probe. The probe can be disabled by setting this to null."
}

variable "enable_prometheus_monitoring" {
type = bool
default = false
description = " a boolean to indicate whether to scrape(true) custom metrics for application or not(false)"
}

variable "probe_command" {
type = list(string)
nullable = false
Expand Down
Loading