Skip to content

Commit

Permalink
Merge pull request #9 from AndrewPentsak/improvements
Browse files Browse the repository at this point in the history
Private or Public endpoints for Thanos
  • Loading branch information
loafoe authored Jan 5, 2021
2 parents 895f710 + cec75e1 commit cb67230
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 16 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ module "thanos" {
name_postfix = var.name_postfix
thanos_public_endpoints = false
// needed for paas_prometheus_exporter
environment = {
USERNAME = var.cf_username
Expand Down Expand Up @@ -74,12 +76,17 @@ module "thanos" {
| thanos\_image | Image to use for Thanos app | `string` | `"philipslabs/cf-thanos:latest"` | no |
| thanos\_query\_image | Image to use for Thanos query | `string` | `"philipslabs/cf-thanos:latest"` | no |
| thanos\_store\_image | Image to use for Thanos store | `string` | `"philipslabs/cf-thanos:latest"` | no |
| thanos\_public\_endpoints | Make Thanos endpoints private(false) or public (true) | `bool` | `true` | no |

## Outputs

| Name | Description |
|------|-------------|
| cluster\_id | Cluster ID of Tasy POC |
| thanos\_space\_id| CF space Id where Thanos deployed|
| thanos\_app\_id| CF app Id of deployed Thanos |
| thanos\_query\_app\_id| CF app Id of deployed Thanos |
| grafana\_app\_id| CF app Id of deployed Grafana |
| grafana\_endpoint | URL of Grafana deployment (optional) |
| thanos\_query\_endpoint | URL of Thanos deployment |

Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG prometheus_version=2.22.0
ARG prometheus_version=2.22.2
ARG thanos_version=0.15.0

FROM alpine:latest AS prometheus
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile_with_exporter
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG prometheus_version=2.22.0
ARG prometheus_version=2.22.2
ARG thanos_version=0.15.0

FROM golang:alpine as exporter
Expand Down
2 changes: 1 addition & 1 deletion docker/prometheus.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[program:prometheus]
command = /sidecars/bin/prometheus_targets.sh --config.file=/sidecars/etc/prometheus.yml --storage.tsdb.path=/prometheus --storage.tsdb.retention=2d --storage.tsdb.min-block-duration=30m --storage.tsdb.max-block-duration=30m --web.enable-lifecycle
command = sh /sidecars/bin/prometheus_targets.sh --config.file=/sidecars/etc/prometheus.yml --storage.tsdb.path=/prometheus --storage.tsdb.retention=2d --storage.tsdb.min-block-duration=30m --storage.tsdb.max-block-duration=30m --web.enable-lifecycle
autostart = true
autorestart = true
startsecs = 5
Expand Down
2 changes: 1 addition & 1 deletion grafana.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module "grafana" {
source = "philips-labs/grafana/cloudfoundry"
version = ">= 0.3.0"
version = ">= 0.5.0"

count = var.enable_grafana ? 1 : 0
enable_postgres = var.enable_grafana_postgres
Expand Down
12 changes: 11 additions & 1 deletion outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ output "cluster_id" {

output "thanos_query_endpoint" {
description = "URL of Thanos deployment"
value = cloudfoundry_route.thanos_query.endpoint
value = var.thanos_public_endpoints ? cloudfoundry_route.thanos_query.endpoint : "${cloudfoundry_route.thanos_query_internal.endpoint}:9090"
}

output "grafana_endpoint" {
Expand All @@ -21,4 +21,14 @@ output "thanos_space_id" {
output "thanos_app_id" {
description = "App id for Thanos"
value = cloudfoundry_app.thanos.id
}

output "grafana_app_id" {
description = "App id for Grafana"
value = join("", module.grafana.*.grafana_id)
}

output "thanos_query_app_id" {
description = "App id for Thanos Query"
value = cloudfoundry_app.thanos_query.id
}
15 changes: 9 additions & 6 deletions thanos.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
locals {
thanos_routes = var.thanos_public_endpoints ? [cloudfoundry_route.thanos.id, cloudfoundry_route.thanos_internal.id] : [cloudfoundry_route.thanos_internal.id]
}

resource "cloudfoundry_app" "thanos" {
name = "thanos"
space = cloudfoundry_space.space.id
Expand All @@ -10,16 +14,15 @@ resource "cloudfoundry_app" "thanos" {
}
environment = var.environment

routes {
route = cloudfoundry_route.thanos.id
}
routes {
route = cloudfoundry_route.thanos_internal.id
dynamic "routes" {
for_each = local.thanos_routes
content {
route = routes.value
}
}
service_binding {
service_instance = cloudfoundry_service_instance.s3.id
}

}

resource "cloudfoundry_route" "thanos" {
Expand Down
15 changes: 10 additions & 5 deletions thanos_query.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
locals {
thanos_query_routes = var.thanos_public_endpoints ? [cloudfoundry_route.thanos_query.id, cloudfoundry_route.thanos_query_internal.id] : [cloudfoundry_route.thanos_query_internal.id]
}

resource "cloudfoundry_app" "thanos_query" {
name = "thanos-query"
space = cloudfoundry_space.space.id
Expand All @@ -10,11 +14,12 @@ resource "cloudfoundry_app" "thanos_query" {
}
environment = var.environment
command = "/sidecars/bin/thanos query --grpc-address=0.0.0.0:10901 --http-address=0.0.0.0:9090 --store=${cloudfoundry_route.thanos_internal.endpoint}:19090 --store=${cloudfoundry_route.thanos_store_internal.endpoint}:19090"
routes {
route = cloudfoundry_route.thanos_query.id
}
routes {
route = cloudfoundry_route.thanos_query_internal.id

dynamic "routes" {
for_each = local.thanos_query_routes
content {
route = routes.value
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ variable "thanos_store_image" {
type = string
}

variable "thanos_public_endpoints" {
description = "Make Thanos public endpoint"
type = bool
default = true
}

variable "enable_grafana" {
description = "Adds a Grafana deployment when enabled"
Expand Down

0 comments on commit cb67230

Please sign in to comment.