Skip to content

Add the database monitoring agent Terraform module - #123

Merged
anchoo2kewl merged 8 commits into
masterfrom
feat/database-monitoring-module
Sep 24, 2026
Merged

anchoo2kewl merged 8 commits into
masterfrom
feat/database-monitoring-module

Conversation

@anchoo2kewl

@anchoo2kewl anchoo2kewl commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Adds database-monitoring/terraform: the module that runs the Elastio database monitoring agent on AWS Fargate (elastio/blue-stack#17072). It is published as aws-elastio-database-monitoring-agent 0.1.0, so the registry source is terraform.cloudsmith.io/public/elastio-database-monitoring-agent/aws.

Source: deploy/terraform/aws-fargate at tag agent-v0.1.3 in the old agent repository, adapted for this repo.

Changes from the source module

  • The image default is now public.ecr.aws/elastio/elastio-database-monitoring-agent:0.1.4. That image is not published yet.
  • All customer-visible names now use the elastio-dbmon prefix:
    • log group /elastio-dbmon/agent/<name>
    • secrets elastio-dbmon/<name>/{api-key,database-url,hash-secret}-*
    • roles elastio-dbmon-<name16>-{exec,task}-*
    • EFS security group elastio-dbmon-<name16>-efs-*
    • EFS Name tag elastio-dbmon-<name>-ledger
    • access point root /elastio-dbmon
    • inline policies read-elastio-dbmon-secrets and mount-elastio-dbmon-ledger
    • container elastio-dbmon-agent
    • resource descriptions
  • The name used in IAM role prefixes is cut to 16 characters. With the new prefix, the old 20-character cut exceeded IAM's 38-character limit for name_prefix.
  • The EFS creation_token is removed and the provider generates one. The old token was built from the full name, so it broke EFS's 64-character limit for long names.
  • IAM policies are now jsonencode, not data "aws_iam_policy_document", to follow this repo's convention (Replace data "aws_iam_policy_document" with manual jsonencode #109).
  • The log driver region is now read from the log group ARN. data.aws_region's name and id are both deprecated in AWS provider 6, and required_providers is now aws >= 5.0 / random >= 3.0 (the relaxed constraints from Relax TF provider version requirements #121). required_version is ~> 1.9.
  • Kept unchanged:
    • Variable names. The Elastio Portal renders a module call from them.
    • The QUELL_* environment variable names. They are the agent binary's configuration contract.
    • The in-container ledger path /var/lib/quell. It is the image's own volume, owned by the non-root user, and the ephemeral (non-EFS) mode depends on it.
  • There is no moved {} block. Resource addresses are the same as before; only the AWS-side names changed.
  • Added examples/basic (with its lock file, as the other examples have), a names_and_image test, and a region assertion.

Checks run locally

  • terraform init -backend=false && terraform validate: valid, no warnings (AWS provider 6.66.0)
  • terraform test: 4 passed, 0 failed
  • terraform validate in examples/basic: valid
  • terraform-docs v0.19.0, then prettier --check .: clean
  • tflint --recursive (repo .tflint.hcl): clean
  • typos: clean
  • terraform fmt: clean on the new files

Task size (commit 387bdde)

  • New inputs task_cpu (default 256) and task_memory (default 512, MiB). The product renders these names. Validation accepts only pairs that Fargate runs on ARM64: 256 with 512, 1024 or 2048; 512 with 1024 to 4096; 1024 with 2048 to 8192; 2048 with 4096 to 16384. Memory above 512 MiB goes in steps of 1024.
  • GOMEMLIMIT is floor(task_memory * 0.8) MiB. The agent's budget for one open transaction is 30% of that, so the budget follows the size.
  • The default image is now agent 0.1.6 (elastio/database-monitoring-agent#2). That release judges a transaction too large to hold from its row counts instead of crashing, and reports the task memory that would have held it. It also finds its memory limit on Fargate, which 0.1.5 did not. Tag agent-v0.1.6 before this module is released.
  • README gains a Sizing section: the presets small 256/512, medium 512/1024, large 1024/2048 and xlarge 2048/4096; about how large a transaction each holds; the monthly cost in us-east-1 for ARM Fargate ($7.21 / $14.42 / $28.84 / $57.67); and "the Elastio UI tells you when to size up".
  • Tests: 14 pass. Each preset and one in-between size are planned, with their GOMEMLIMIT. Pairs Fargate does not run are refused at plan. The default image is checked as 0.1.6.
  • Checks: terraform fmt, validate (module and example), test, tflint --recursive, terraform-docs v0.19.0 plus prettier, and typos, all clean.

Release

After merge, someone with write access runs the release workflow (workflow_dispatch) on master. It publishes only modules whose name-version tag doesn't exist yet, so only this module is published.

Moves the Fargate module for the Elastio database monitoring agent
(elastio/blue-stack#17072) here from its old repository, as
aws-elastio-database-monitoring-agent 0.1.0. The image defaults to
public.ecr.aws/elastio/elastio-database-monitoring-agent:0.1.4 and every
resource name uses the elastio-dbmon prefix. The variable names are
unchanged because the Elastio Portal renders a module call from them.
Copilot AI lite review requested due to automatic review settings September 24, 2026 00:55
@anchoo2kewl anchoo2kewl self-assigned this Sep 24, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

maksvet and others added 3 commits September 24, 2026 10:47
- Add an EFS file system policy: only the task role may mount, only
  through the access point, and only over TLS. Without it, any NFS client
  that reaches a mount target can mount the file system as root.
- Make the service depend on the IAM policies, secret versions, and the
  file system policy, so the first task does not start before it may read
  its secrets or mount the ledger, and destroy stops the task first.
- Validate that subnet_ids and security_group_ids are not empty, and that
  log_retention_days is a value CloudWatch Logs accepts.
Agent 0.1.5 reads ELASTIO_DBMON_* variables (QUELL_* still as a fallback)
and keeps its ledger under /var/lib/elastio-dbmon. The module sets the new
names, mounts the ledger there and names the path explicitly, so the EFS
access point's ledger is the same file as before. It also sets GOMEMLIMIT
to 80% of the task's memory: Go sets no memory limit from the container on
its own. The default image is 0.1.5, which this needs.
@anchoo2kewl

Copy link
Copy Markdown
Contributor Author

Pushed 98276af for agent 0.1.5 (elastio/database-monitoring-agent#1): the module now sets the ELASTIO_DBMON_* variables, mounts the ledger at /var/lib/elastio-dbmon and passes that path explicitly, so the EFS access point holds the same ledger file. It also sets GOMEMLIMIT=409MiB (80% of the 512 MiB task) and defaults the image to 0.1.5. The image needs 0.1.5 or later, since older agents read only QUELL_*. terraform test passes 5/5, and the README was regenerated with terraform-docs 0.19 and prettier.

maksvet and others added 4 commits September 24, 2026 12:02
EFS admits a client when either its identity policy or the file system
policy allows it, so an Allow alone does not keep out other roles with
EFS permissions. Add explicit Denies for every principal except the task
role and for every mount that does not use the access point.
EFS does not enforce aws:PrincipalArn for NFS clients, so the deny did not
restrict other principals and could refuse the agent itself. Keep only the
denies on the access point and TLS, which use keys EFS enforces, and state
that the EFS security group is the boundary against other roles with
their own EFS permissions.
The task was fixed at 0.25 vCPU and 512 MiB. What a larger task buys is
the largest transaction the agent holds in memory whole: agent 0.1.6
judges anything bigger from its row counts and reports an oversized
transaction with the smallest task memory that would have held it. So
the size is now two inputs, task_cpu (default 256) and task_memory
(default 512, MiB). They are validated as a pair Fargate runs on ARM64:
256 with 512, 1024 or 2048; 512 with 1024 to 4096; 1024 with 2048 to
8192; 2048 with 4096 to 16384; memory above 512 in steps of 1024.

GOMEMLIMIT follows task_memory at floor(task_memory * 0.8) MiB, so the
agent's transaction budget follows the size too. The default image is
0.1.6. The README has a Sizing section with the four sizes the product
offers, what each holds and costs in us-east-1, and how the Elastio UI
says when to size up. The tests plan each size and refuse pairs Fargate
does not run.
The comment said Fargate makes the bind mount writable for the container's
uid. It is writable when the image has a VOLUME at the ledger directory
owned by uid 65532, because ECS copies that VOLUME into the bind mount.
Also note that the task size is now configurable.

@maksvet maksvet left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked the 0.1.6 image (VOLUME and owner at /var/lib/elastio-dbmon) and ran this head in a test account: both ledger modes start and open the ledger, and the agent reads its limits from ECS metadata.

@anchoo2kewl
anchoo2kewl merged commit fdf264b into master Sep 24, 2026
22 checks passed
@anchoo2kewl
anchoo2kewl deleted the feat/database-monitoring-module branch September 24, 2026 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants