Skip to content

Flare: add identity database, cold storage, Resources page and image overrides - #2610

Open
aminparsa18 wants to merge 3 commits into
CommunityToolkit:mainfrom
aminparsa18:feature/flare-hosting-parity
Open

aminparsa18 wants to merge 3 commits into
CommunityToolkit:mainfrom
aminparsa18:feature/flare-hosting-parity

Conversation

@aminparsa18

Copy link
Copy Markdown
Contributor

Closes #2609

Adds the deployment options from the original Flare.Hosting.Aspire package that the integration didn't have yet. Each one is opt-in, and the defaults of AddFlare are unchanged. The three commits can be reviewed one at a time.

WithIdentityDatabase(database)

Sets Identity__Provider=Postgres and Identity__ConnectionString on the ingest service and the query API, and makes both wait for the database. The alert worker doesn't read identity and is left as it is. Use it for a Kubernetes cluster with more than one node, where the volume WithDataVolume() shares usually can't be mounted by both workloads. The parameter is IResourceWithConnectionString, so there's no dependency on the PostgreSQL integration.

var identity = builder.AddPostgres("postgres").WithDataVolume().AddDatabase("flare-identity");
var flare = builder.AddFlare("flare", clickhouse, redis).WithIdentityDatabase(identity);

WithColdStorage(endpoint, accessKey, secretKey)

Adds an S3-compatible bucket to the ClickHouse server passed to AddFlare as a cold tier. A config.d file added with WithContainerFiles defines an S3 disk and the flare_tiered policy, and the endpoint and keys go in as environment variables, which the file reads with from_env. The bucket is passed in rather than created, so any S3-compatible store works. The README shows local use with the RustFS integration.

var rustfs = builder.AddRustFs("rustfs").WithDataVolume();
var bucket = rustfs.AddBucket("flare-cold");
var clickhouse = builder.AddClickHouse("clickhouse").WaitFor(bucket);

var flare = builder.AddFlare("flare", clickhouse, redis)
                   .WithColdStorage(
                       ReferenceExpression.Create($"{rustfs.Resource.PrimaryEndpoint}/flare-cold/"),
                       builder.CreateResourceBuilder(rustfs.Resource.AccessKey),
                       builder.CreateResourceBuilder(rustfs.Resource.SecretKey));

WithResourceGraph()

Turns on the dashboard's Resources page. It adds flare.resource, flare.role and flare.relationships labels to the Flare containers, ClickHouse and Redis, and gives the query API read-only access to the container runtime:

  • Under aspire run and in Docker Compose output: a tecnativa/docker-socket-proxy:3.4 container with the Docker socket mounted read-only and only CONTAINERS=1 allowed. The query API talks to the proxy, never to the socket.
  • When publishing to a Kubernetes environment: no proxy. The query API runs under its own ServiceAccount, bound to a Role that can only get, list and watch pods and services in the release namespace. Relationships go in a pod annotation, because label values can't contain : or ,.

The Compose and Kubernetes settings are added in BeforeStartEvent, once the whole app model is built. Two reasons: PublishAsDockerComposeService makes publishing fail when there's no Compose environment, and an environment added after WithResourceGraph() still has to count. This adds dependencies on Aspire.Hosting.Docker and Aspire.Hosting.Kubernetes.

WithFlareImageRegistry(registry) and WithFlareImages(ingest, api, alertWorker, dashboard)

These set the registry of all four images (for example a private mirror), or replace any of the images. Replaced images keep the shared tag and registry, whatever order the calls come in.

PR Checklist

  • Created a feature/dev branch in your fork (vs. submitting directly from a commit on main)
  • Based off latest main branch of toolkit
  • PR doesn't include merge commits (always rebase on top of our main, if needed)
  • Tests for the changes have been added (for bug fixes / features) (if applicable)
  • Contains NO breaking changes
  • Every new API (including internal ones) has full XML docs
  • Code follows all style conventions

Other information

Tested by hand against the published Flare images. In each case I temporarily changed the example AppHost and didn't commit the change, so the example stays minimal:

  • Identity database: with Postgres added, ingest and the API came up healthy and created Flare's 23 identity tables in the database.
  • Cold storage: with a RustFS bucket, ClickHouse listed the cold disk and the flare_tiered policy. A table using the policy moved its part to the cold volume and read it back correctly.
  • Resources page, aspire run: the API's /api/resources/snapshot returned the graph from Docker with all six containers and their dependency edges.
  • Resources page, Kubernetes publish: the chart had the ServiceAccount, Role and RoleBinding, the API pod used the service account, every workload carried the labels, and there was no proxy. helm lint and helm template passed. I haven't deployed it to a real cluster.
  • Resources page, Docker Compose publish: every service carried the labels, and the proxy was included with the socket mounted read-only.

Known limits, documented in the README:

  • The Kubernetes publisher doesn't handle WithContainerFiles yet, so cold storage isn't configured in Kubernetes output. Flare then reports cold storage as unavailable.
  • For cold storage the bucket must exist before ClickHouse starts. AddBucket creates it only in run mode.
  • The socket proxy lists every container on the Docker host, so other Flare stacks on the same host also appear in the graph.

WithIdentityDatabase and WithColdStorage are marked [AspireExport] with IResourceBuilder<IResourceWithConnectionString> and ReferenceExpression parameters. I haven't tried them from a TypeScript or Go AppHost, and can switch either to [AspireExportIgnore] if you prefer.

Stores Flare's identity database in PostgreSQL instead of a SQLite file
shared by the ingest service and the query API through one volume. A
volume mounted by two workloads usually can't be attached on different
nodes, so this is what a multi-node Kubernetes deployment needs.
Adds an S3-compatible bucket to Flare's ClickHouse server as a cold
storage tier, so retention can move older telemetry off the local disk.
The disk and the flare_tiered storage policy are added as a ClickHouse
config file; the endpoint and keys are passed as environment variables.
…ation

WithResourceGraph turns on the Flare dashboard's Resources page. It labels
the Flare containers, ClickHouse and Redis, and gives the query API
read-only access to the container runtime: a Docker socket proxy locally
and in Docker Compose output, or a service account with a read-only role
when publishing to Kubernetes.

WithFlareImageRegistry and WithFlareImages change where the four Flare
images come from, keeping the shared tag.
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/CommunityToolkit/Aspire/main/eng/scripts/dogfood-pr.sh | bash -s -- 2610

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/CommunityToolkit/Aspire/main/eng/scripts/dogfood-pr.ps1) } 2610"

This branch has not been deployed

No deployments
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.

Flare: add the deployment options from the original Flare.Hosting.Aspire package

1 participant