Skip to content

Conversation

@KyleAMathews
Copy link
Contributor

@KyleAMathews KyleAMathews commented Jan 20, 2026

Plug to create a comprehensive snapshot of the source's metadata for debugging purposes.

Returns a JSON object containing:

Global Metadata

  • database: Current PostgreSQL snapshot information
    • xmin: Oldest visible transaction ID
    • xmax: Next transaction ID to be assigned
    • xip_list: List of in-progress transaction IDs
    • lsn: Current WAL log sequence number (as string)
  • status: Service connection status
  • shape_count: Total number of active shapes

Per-Shape Metadata (in shapes array)

  • handle: Unique shape identifier
  • definition: Shape definition including table, where clause, columns
  • status: Shape status (snapshot_started, snapshot_completed)
  • latest_offset: Current log offset for this shape
  • pg_snapshot: PostgreSQL snapshot at shape creation time (if available)
{
  "database": {
    "xmin": 12345,
    "xmax": 12347,
    "xip_list": [12346],
    "lsn": "100"
  },
  "status": {
    "connection": "up",
    "shape": "up"
  },
  "shape_count": 2,
  "shapes": [
    {
      "handle": "items-1234567890",
      "definition": {
        "table": "public.items",
        "root_table_id": 16385,
        "primary_key": ["id"],
        "replica": "default",
        "log_mode": "full",
        "where": "status = 'active'",
        "columns": ["id", "name", "status"],
        "storage": {"compaction": "disabled"},
        "flags": {},
        "dependency_handles": []
      },
      "status": {
        "snapshot_started": true,
        "snapshot_completed": true
      },
      "latest_offset": "0_0",
      "pg_snapshot": {
        "xmin": 12340,
        "xmax": 12342,
        "xip_list": [12341]
      }
    }
  ]
}

Add a new API endpoint `/v1/metadata-snapshot` that returns a snapshot of
the PostgreSQL source's metadata for debugging purposes.

The response includes:
- xmin: Oldest visible transaction ID
- xmax: Next transaction ID to be assigned
- xip_list: List of in-progress transaction IDs at the time of the snapshot
- database_lsn: Current WAL log sequence number (as string)

This endpoint is protected by the same authentication as the shape API
when ELECTRIC_SECRET is configured.
Significantly expand the /v1/metadata-snapshot endpoint to provide
comprehensive debugging information:

Global metadata:
- database: PostgreSQL snapshot info (xmin, xmax, xip_list, lsn)
- status: Service connection and shape subsystem status
- shape_count: Total number of active shapes

Per-shape metadata (in shapes array):
- handle: Unique shape identifier
- definition: Shape definition including:
  - table name and OID
  - primary key columns
  - where clause (if filtered)
  - selected columns (if specified)
  - replica mode and log mode
  - storage config
  - dependency handles (for subqueries)
- status: snapshot_started and snapshot_completed flags
- latest_offset: Current log offset for this shape
- pg_snapshot: PostgreSQL snapshot at shape creation time

This provides all the information needed to debug shape behavior,
replication state, and storage issues.
@KyleAMathews KyleAMathews marked this pull request as draft January 20, 2026 18:25
@coderabbitai
Copy link

coderabbitai bot commented Jan 20, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link

codecov bot commented Jan 20, 2026

❌ 1 Tests Failed:

Tests completed Failed Passed Skipped
2119 1 2118 0
View the top 2 failed test(s) by shortest run time
Elixir.Electric.Plug.MetadataSnapshotPlugTest::test /v1/metadata-snapshot GET returns comprehensive metadata snapshot
Stack Traces | 0.169s run time
6) test /v1/metadata-snapshot GET returns comprehensive metadata snapshot (Electric.Plug.MetadataSnapshotPlugTest)
     .../electric/plug/metadata_snapshot_plug_test.exs:30
     Assertion with < failed, both sides are exactly equal
     code: assert db["xmin"] < db["xmax"]
     left: 2192
     stacktrace:
       .../electric/plug/metadata_snapshot_plug_test.exs:51: (test)
Elixir.Electric.Plug.LowPrivilegeRouterTest::test /v1/shapes with manual publication management GET fails to create initial snapshot when Electric cannot read from the table
Stack Traces | 0.183s run time
2) test /v1/shapes with manual publication management GET fails to create initial snapshot when Electric cannot read from the table (Electric.Plug.LowPrivilegeRouterTest)
     .../electric/plug/low_privilege_router_test.exs:47
     Assertion with == failed
     code:  assert {503, %{"message" => "Unable to create initial snapshot: permission denied for table items"}} ==
              get_shape(ctx)
     left:  {503, %{"message" => "Unable to create initial snapshot: permission denied for table items"}}
     right: {409, [%{"headers" => %{"control" => "must-refetch"}}]}
     stacktrace:
       .../electric/plug/low_privilege_router_test.exs:65: (test)

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

@blacksmith-sh
Copy link
Contributor

blacksmith-sh bot commented Jan 20, 2026

Found 5 test failures on Blacksmith runners:

Failures

Test View Logs
Elixir.Electric.Plug.LowPrivilegeRouterTest/test /v1/
shapes with manual publication management GET fails to create initial snapshot when Ele
ctric cannot read from the table
View Logs
Elixir.Electric.Plug.MetadataSnapshotPlugTest/test /v1/
metadata-snapshot GET returns comprehensive metadata snapshot
View Logs
Elixir.Electric.Plug.MetadataSnapshotPlugTest/test /v1/
metadata-snapshot GET returns comprehensive metadata snapshot
View Logs
Elixir.Electric.Plug.MetadataSnapshotPlugTest/test /v1/
metadata-snapshot GET returns comprehensive metadata snapshot
View Logs
Elixir.Electric.Plug.MetadataSnapshotPlugTest/test /v1/
metadata-snapshot GET returns comprehensive metadata snapshot
View Logs

Fix in Cursor

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