Skip to content

Commit

Permalink
feat(fastly): Add honeycomb logging
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwilson committed Jul 2, 2024
1 parent 31d1e39 commit 3ab74c7
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 6 deletions.
1 change: 1 addition & 0 deletions terraform/environments/prod.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ fastly_backends = [
ssl_cert_hostname = "alexwilson.github.io"
}
]
fastly_honeycomb_dataset = "fastly:request"
1 change: 1 addition & 0 deletions terraform/environments/test.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ fastly_backends = [
ssl_cert_hostname = "alexwilson.github.io"
}
]
fastly_honeycomb_dataset = "fastly:request"
14 changes: 8 additions & 6 deletions terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@ terraform {
}

module "fastly" {
source = "./modules/fastly"
domains = var.fastly_domains
backends = var.fastly_backends
environment = terraform.workspace
source = "./modules/fastly"
domains = var.fastly_domains
backends = var.fastly_backends
environment = terraform.workspace
honeycomb_token = var.fastly_honeycomb_token
honeycomb_dataset = var.fastly_honeycomb_dataset
}

module "cloudflare_antoligycom" {
source = "./modules/cloudflare"
account_id = ""
account_id = var.cloudflare_account_id
count = terraform.workspace == "prod" ? 1 : 0
zone = "antoligy.com"
redirect_rules = [{
Expand All @@ -31,7 +33,7 @@ module "cloudflare_antoligycom" {

module "cloudflare_axgy" {
source = "./modules/cloudflare"
account_id = ""
account_id = var.cloudflare_account_id
count = terraform.workspace == "prod" ? 1 : 0
zone = "ax.gy"
redirect_rules = [{
Expand Down
1 change: 1 addition & 0 deletions terraform/modules/cloudflare/variables.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
variable "account_id" {
description = "Account ID"
type = string
sensitive = true
}

variable "zone" {
Expand Down
30 changes: 30 additions & 0 deletions terraform/modules/fastly/honeycomb/format.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"time":"%{begin:%Y-%m-%dT%H:%M:%SZ}t",
"data": {
"service_id":"%{req.service_id}V",
"time_elapsed":%D,
"request":"%m",
"host":"%{if(req.http.Fastly-Orig-Host, req.http.Fastly-Orig-Host, req.http.Host)}V",
"url":"%{cstr_escape(req.url)}V",
"protocol":"%H",
"is_ipv6":%{if(req.is_ipv6, "true", "false")}V,
"is_tls":%{if(req.is_ssl, "true", "false")}V,
"is_h2":%{if(fastly_info.is_h2, "true", "false")}V,
"client_ip":"%h",
"geo_city":"%{client.geo.city.utf8}V",
"geo_country_code":"%{client.geo.country_code}V",
"server_datacenter":"%{server.datacenter}V",
"request_referer":"%{Referer}i",
"request_user_agent":"%{User-Agent}i",
"request_accept_content":"%{Accept}i",
"request_accept_language":"%{Accept-Language}i",
"request_accept_charset":"%{Accept-Charset}i",
"cache_status":"%{regsub(fastly_info.state, "^(HIT-(SYNTH)|(HITPASS|HIT|MISS|PASS|ERROR|PIPE)).*", "\\2\\3") }V",
"status":"%s",
"content_type":"%{Content-Type}o",
"req_header_size":%{req.header_bytes_read}V,
"req_body_size":%{req.body_bytes_read}V,
"resp_header_size":%{resp.header_bytes_written}V,
"resp_body_size":%{resp.body_bytes_written}V
}
}
7 changes: 7 additions & 0 deletions terraform/modules/fastly/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,11 @@ resource "fastly_service_vcl" "cdn" {
})
}
}

logging_honeycomb {
dataset = var.honeycomb_dataset
name = "fastly-${var.environment}"
token = var.honeycomb_token
format = file("${path.module}/honeycomb/format.json")
}
}
11 changes: 11 additions & 0 deletions terraform/modules/fastly/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,14 @@ variable "backends" {
variable "environment" {
description = "The environment name"
}

variable "honeycomb_dataset" {
description = "Name of dataset to stream to in Honeycomb"
type = string
}

variable "honeycomb_token" {
description = "Name of dataset to stream to in Honeycomb"
sensitive = true
type = string
}
12 changes: 12 additions & 0 deletions terraform/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,19 @@ variable "fastly_backends" {
}))
}

variable "fastly_honeycomb_dataset" {
description = "Honeycomb Dataset for streaming Fastly logs to"
type = string
}

variable "fastly_honeycomb_token" {
description = "Write token for Fastly to stream to Honeycomb"
type = string
sensitive = true
}

variable "cloudflare_account_id" {
description = "Cloudflare Account ID"
type = string
sensitive = true
}

0 comments on commit 3ab74c7

Please sign in to comment.