## What & why S-19b-2, closing out ADR-0028's stated direction: **the read projection is now derived from the `RegisterRecord` in Objecten, not from ZGW zaak events.** Until now the subscriber listened on `zaken` and *inferred* register state from case events — a `zaak/create` meant INGEDIEND, and any `status/create` was assumed to be the approval (it may not read OpenZaak, so it could not tell statustypen apart). The reference wasn't in the notification at all, so every projection made a second hop to the ACL. The register — a fact about a person — was being reconstructed by guessing at the lifecycle of the case that produced it. - The subscriber's abonnement moves to the `objecten` kanaal (S-19b-1 made it publish). - An Objecten notification carries **no record data**, only the object URL, so the record is read back through the ACL (`POST /register-records/read`) — §8.1 applies to Objecten exactly as ADR-0028 established. - The record carries `id`, `status` and `reference`, so the row *is* the record: `IsZaakCreated`, `IsZaakStatusSet`, `ZaakUrl`, `ZaakId` and `ToEntry`'s `Resource == "status"` inference are all gone, and so is the ACL enrichment hop. - **The ACL now writes an INGEDIEND record on submit.** Without it, re-sourcing would silently drop every submitted registration from the public register, since only approval wrote a record. - `processed_notifications` holds the projected row (`register_id`, `status`, `reference`) instead of the ZGW event, so a rebuild is a replay with no mapping rules and no upstream reads at all. **ADR-0030** records it. ADR-0028's open caveat — record written but not yet read, "the two must agree" — is closed: there is one source now. Closes #153 ## Definition of Done - [x] Linked Gitea issue (above). - [x] Failing tests committed before the implementation — two red/green pairs, ACL side (06c0444→566ef7d) and subscriber side (142ed45→8af09b2). - [x] Refactor commit follows (b496ac9). - [x] Conventional Commits referencing the issue (`refs #153`). - [x] CI green — all six jobs onb30fa66, `verify-stack` end to end including the e2e. - [x] `docker compose up` from a fresh clone reaches green health checks within 3 minutes (`verify-stack`'s bring-up step — see the wait-healthy fix below). - [x] Docs updated — ADR-0030 added, ADR-0028's consequence + caveat annotated, BACKLOG.md, e2e header comment. - [x] ADR added in `docs/architecture/`. - [x] Demo note in `docs/demo-script.md` — n/a: no user-visible change. The openbaar register shows the same two statuses for the same registrations; only where they come from changed. ## Notes for reviewers **The decision I'd most like a second opinion on** is the one the issue didn't settle: what happens to INGEDIEND. Objecten held only INGESCHREVEN records, so re-sourcing forced a choice between (a) the ACL also writing on submit, (b) a public register that lists only actual registrations, or (c) a hybrid keeping both kanalen. I took (a): visible behaviour is unchanged and the register holds the whole lifecycle. (b) is arguably the better *semantics* for a public register but narrows what the portal shows and reads against PRD §68 ("~50 register entries with diverse statuses"); (c) leaves the projection half-derived from ZGW, which is the coupling ADR-0028 set out to remove. All three are laid out in ADR-0030. **The dedup key is the projected row**, `objecten:object:{url}:{status}:{reference}` — not the object URL (the ACL upserts *one object per registration*, so submit and approval notify about the same URL and the approval would be swallowed as a duplicate) and not URL+actie (a retried approval is a second `update`). Redeliveries collapse, genuine state changes don't. §8.6. **The migration drops columns rather than renaming them.** EF scaffolded renames — `resource` → `register_id`, `zaak_id` → `status` — which would have carried ZGW values into columns meaning something else, and a rebuild would then have projected that garbage. It also empties both tables: a pre-slice row describes a zaak event the new projector can't reproject, and those registrations have no RegisterRecord in Objecten either, so they're not re-derivable from the new source. Stated as a ceiling in the ADR — fine while stacks are ephemeral, backfill from Objecten if a long-lived environment ever needs it. **`run-projection-check.sh` now opens its zaak through the ACL** instead of straight against OpenZaak, because the ACL is what writes the record. A zaak created behind the ACL's back produces no projection row — that's the re-source working, not a gap. ## Three fixes CI found, none of them in the projection logic 1. **`wait-healthy.sh` matched the wrong container** (744f91a). Bring-up timed out with `TIMEOUT: 'objecten' not healthy (status=none)` while the `docker ps` it dumps showed objecten `Up 9 minutes (healthy)`. `--filter name=` is a substring match, so `objecten` also matches `objecten-db`/`objecten-redis`/`objecten-celery`, and `head -1` took whichever docker listed first — the celery worker has no healthcheck, hence `status=none`. Latent since those services landed and decided purely by listing order; `objecttypen` matches `objecttypen-db` the same way. Anchored on the compose replica suffix, which the verify scripts already do. 2. **The ACL had to be repointed at OpenZaak's IP** (7e0897a). Opening the zaak through the ACL put this check in the same bind run-domain-check.sh already handles: `400 {"name":"zaaktype","code":"bad-url","reason":"Voer een geldige URL in."}`. OpenZaak reflects the request Host into the zaaktype URL and then rejects it on zaak-create when single-label — the mechanism compose already documents on `ACL_OPENZAAK_BASEURL`. 3. **Approval arrives as `partial_update`, not `update`** (0dd26a7→b30fa66) — the one real bug in the slice. The ACL upserts with PATCH; DRF routes it through the notifying `update()` but names the action `partial_update`, so the projector dropped every approval. Only the e2e could catch it: `verify-projection` drives a submit, and per ADR-0028 the e2e is the only check that drives a *real* approval. `verify-tracing` also failed once (run 722) on a path this PR doesn't touch, and passed on a plain re-run of the same commit. Tempo logged `pusher failed to consume trace data` / `distributor_pool failing healthcheck` — it dropped spans under runner load rather than the trace chain being broken. Filed as **#156** rather than absorbed here. **Correction to the #152 PR notes:** I wrote there that celery concurrency was "the next knob" if verify-stack got tight. It isn't — `CELERY_WORKER_CONCURRENCY` already defaults to 1 in the Maykin image, so `objecten-celery` is already a single-process worker. Noted in #156. **Possible follow-up, deliberately not done here:** an `openzaak.local` network alias mirroring `objecten.local` would remove the ACL-repoint dance from both run-domain-check.sh and run-projection-check.sh. It changes the host in every zaak URL the system produces, which is too broad a ripple to land inside an unrelated slice — worth its own issue. **Known costs, all in the ADR:** submission is now two writes across two modules and eventually consistent (same posture ADR-0028 accepted for approval); projecting now depends on the ACL being reachable on the main path, not just for enrichment (NRC retries, so it converges); and OpenZaak still publishes to `zaken` with nothing in the product listening — kept because `verify-nrc` asserts that path.Reviewed-on: #155
150 lines
7.6 KiB
C#
150 lines
7.6 KiB
C#
using Acl.Application;
|
|
using Acl.Infrastructure;
|
|
using OpenTelemetry.Metrics;
|
|
using OpenTelemetry.Resources;
|
|
using OpenTelemetry.Trace;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
// OpenTelemetry tracing (S-16b, ADR-0023): auto-instrument incoming ASP.NET Core requests and
|
|
// outgoing HttpClient calls (the ACL → OpenZaak hop), exported over OTLP to Tempo. Service name +
|
|
// OTLP endpoint come from OTEL_* env (compose); the exporter no-ops when Tempo is unreachable.
|
|
builder.Services.AddOpenTelemetry()
|
|
.ConfigureResource(r => r.AddService(
|
|
builder.Configuration["OTEL_SERVICE_NAME"] ?? builder.Environment.ApplicationName))
|
|
.WithTracing(tracing => tracing
|
|
.AddAspNetCoreInstrumentation(o => o.Filter = ctx => ctx.Request.Path != "/health")
|
|
.AddHttpClientInstrumentation()
|
|
.AddOtlpExporter())
|
|
// OpenTelemetry metrics (S-16c, ADR-0023): golden signals for the request path —
|
|
// http.server.request.duration (traffic/errors/latency) + http.client.* for downstream hops, plus
|
|
// the built-in System.Runtime meter for saturation (GC, CPU, thread pool). Prometheus scrapes these
|
|
// from /metrics (mapped below); metrics aren't pushed over OTLP, so no collector hop (ADR-0023).
|
|
.WithMetrics(metrics => metrics
|
|
.AddAspNetCoreInstrumentation()
|
|
.AddHttpClientInstrumentation()
|
|
.AddMeter("System.Runtime")
|
|
.AddPrometheusExporter());
|
|
|
|
builder.Services.AddSingleton<IClock, SystemClock>();
|
|
builder.Services.AddSingleton(sp => sp.GetRequiredService<IConfiguration>()
|
|
.GetSection("Acl:Defaults").Get<AclDefaults>()
|
|
?? throw new InvalidOperationException("Missing configuration section 'Acl:Defaults'"));
|
|
builder.Services.AddSingleton(sp => sp.GetRequiredService<IConfiguration>()
|
|
.GetSection("Acl:OpenZaak").Get<OpenZaakOptions>()
|
|
?? throw new InvalidOperationException("Missing configuration section 'Acl:OpenZaak'"));
|
|
// The default-fill values are held in a runtime-mutable store (S-15b, ADR-0026), seeded from the
|
|
// configured Acl:Defaults. The beheer portal edits it; the worker reads it per zaak. The S-27
|
|
// resolution keys stay on AclDefaults (static) — see DefaultFillSettings.
|
|
builder.Services.AddSingleton<IDefaultFillStore>(sp =>
|
|
{
|
|
var d = sp.GetRequiredService<AclDefaults>();
|
|
return new InMemoryDefaultFillStore(
|
|
new DefaultFillSettings(d.Bronorganisatie, d.VerantwoordelijkeOrganisatie, d.Vertrouwelijkheidaanduiding));
|
|
});
|
|
builder.Services.AddSingleton(sp => sp.GetRequiredService<IConfiguration>()
|
|
.GetSection("Acl:Objecten").Get<ObjectenOptions>()
|
|
?? throw new InvalidOperationException("Missing configuration section 'Acl:Objecten'"));
|
|
builder.Services.AddHttpClient<IZaakGateway, OpenZaakGateway>();
|
|
// The Objecten hop that writes the register record on approval (S-19a, ADR-0028).
|
|
builder.Services.AddHttpClient<IRegisterRecordGateway, ObjectenGateway>();
|
|
// Singleton so the resolved zaaktype/informatieobjecttype URLs are cached across requests (S-27).
|
|
builder.Services.AddSingleton<IZaaktypeCatalog, CachedZaaktypeCatalog>();
|
|
builder.Services.AddScoped<AclService>();
|
|
|
|
var app = builder.Build();
|
|
|
|
app.MapGet("/health", () => "Healthy");
|
|
|
|
// Prometheus scrape endpoint (S-16c): exposes the OTel metrics above in Prometheus text format.
|
|
app.MapPrometheusScrapingEndpoint();
|
|
|
|
// The ACL's single operation, exposed as a service endpoint.
|
|
app.MapPost("/zaken", async (OpenZaakRequest body, AclService acl, CancellationToken ct) =>
|
|
{
|
|
var zaakUrl = await acl.OpenZaakAsync(new DomainRegistration(body.Bsn, body.Reference), ct);
|
|
return Results.Ok(new { zaakUrl = zaakUrl.ToString() });
|
|
});
|
|
|
|
// Approve a zaak: set it to its zaaktype's eindstatus (S-09b). The domain hands over only the zaak
|
|
// URL; the ACL owns the ZGW statustype resolution (§8.1).
|
|
app.MapPost("/statussen", async (SetStatusRequest body, AclService acl, CancellationToken ct) =>
|
|
{
|
|
await acl.ApproveZaakAsync(new Uri(body.ZaakUrl), ct);
|
|
return Results.NoContent();
|
|
});
|
|
|
|
// Cancel a zaak on document-timeout expiry (S-10c): set it to its zaaktype's cancellation statustype
|
|
// + resultaat. The domain hands over only the zaak URL; the ACL owns the ZGW resolution (§8.1).
|
|
app.MapPost("/annuleringen", async (CancelZaakRequest body, AclService acl, CancellationToken ct) =>
|
|
{
|
|
await acl.CancelZaakAsync(new Uri(body.ZaakUrl), ct);
|
|
return Results.NoContent();
|
|
});
|
|
|
|
// Read a zaak's public-safe reference (its identificatie). The Event Subscriber calls this to enrich
|
|
// the read projection without reading ZGW itself (§8.1, #78).
|
|
app.MapPost("/zaken/reference", async (ZaakReferenceRequest body, AclService acl, CancellationToken ct) =>
|
|
{
|
|
var reference = await acl.GetZaakReferenceAsync(new Uri(body.ZaakUrl), ct);
|
|
return Results.Ok(new { reference });
|
|
});
|
|
|
|
// Read the register record an object in Objecten holds. The Event Subscriber projects a register
|
|
// write from the notification NRC delivers, which carries only the object URL, and may not talk to
|
|
// Objecten itself (§8.1, ADR-0028/ADR-0030). 404 when the object holds no record — the subscriber
|
|
// treats that as "nothing to project" rather than an error (§8.6).
|
|
app.MapPost("/register-records/read", async (RegisterRecordReadRequest body, AclService acl, CancellationToken ct) =>
|
|
{
|
|
var record = await acl.GetRegisterRecordAsync(new Uri(body.ObjectUrl), ct);
|
|
return record is null ? Results.NotFound() : Results.Ok(record);
|
|
});
|
|
|
|
// Store an uploaded diploma against a zaak (S-10b): the domain sends the file as base64; the ACL
|
|
// creates the ZGW enkelvoudiginformatieobject and relates it to the zaak (§8.1). Returns its URL.
|
|
app.MapPost("/documenten", async (StoreDocumentRequest body, AclService acl, CancellationToken ct) =>
|
|
{
|
|
var url = await acl.StoreDiplomaAsync(
|
|
new Uri(body.ZaakUrl), Convert.FromBase64String(body.ContentBase64), body.FileName, body.ContentType, ct);
|
|
return Results.Ok(new { informatieobjectUrl = url.ToString() });
|
|
});
|
|
|
|
// List the published zaaktypen — the read-only catalogus the beheer portal shows (S-15a). The BFF
|
|
// proxies this behind medewerker-realm + beheerder authorization; the ACL trusts its callers (§8.3)
|
|
// and is the only code allowed to read the ZGW Catalogi API (§8.1).
|
|
app.MapGet("/catalogi/zaaktypen", async (AclService acl, CancellationToken ct) =>
|
|
Results.Ok(await acl.ListZaaktypenAsync(ct)));
|
|
|
|
// Read the current default-fill settings (beheer config viewer, S-15b).
|
|
app.MapGet("/default-fill", (AclService acl) => Results.Ok(acl.GetDefaultFill()));
|
|
|
|
// Update the default-fill settings from the beheer portal (S-15b). Behind beheerder authorization at
|
|
// the BFF; the ACL validates the values are present (the three ZGW-mandatory fields).
|
|
app.MapPut("/default-fill", (DefaultFillSettings body, AclService acl) =>
|
|
{
|
|
if (string.IsNullOrWhiteSpace(body.Bronorganisatie) ||
|
|
string.IsNullOrWhiteSpace(body.VerantwoordelijkeOrganisatie) ||
|
|
string.IsNullOrWhiteSpace(body.Vertrouwelijkheidaanduiding))
|
|
return Results.BadRequest(new { error = "bronorganisatie, verantwoordelijkeOrganisatie and vertrouwelijkheidaanduiding are all required." });
|
|
|
|
acl.UpdateDefaultFill(body);
|
|
return Results.NoContent();
|
|
});
|
|
|
|
app.Run();
|
|
|
|
public sealed record OpenZaakRequest(string Bsn, string Reference);
|
|
|
|
public sealed record SetStatusRequest(string ZaakUrl);
|
|
|
|
public sealed record CancelZaakRequest(string ZaakUrl);
|
|
|
|
public sealed record ZaakReferenceRequest(string ZaakUrl);
|
|
|
|
/// <summary>The object whose register record the Event Subscriber wants read back (S-19b-2).</summary>
|
|
public sealed record RegisterRecordReadRequest(string ObjectUrl);
|
|
|
|
public sealed record StoreDocumentRequest(string ZaakUrl, string ContentBase64, string FileName, string ContentType);
|
|
|
|
public partial class Program;
|