Skip to content

Add /dev/null id option and surface resume token update interval.#315

Merged
adiom-mark merged 1 commit intomainfrom
moreconfig
Sep 17, 2025
Merged

Add /dev/null id option and surface resume token update interval.#315
adiom-mark merged 1 commit intomainfrom
moreconfig

Conversation

@adiom-mark
Copy link
Collaborator

@adiom-mark adiom-mark commented Sep 17, 2025

Summary by CodeRabbit

  • New Features

    • Null connector now supports a user-defined ID; the ID is returned in connector info.
    • Added CLI flag --id for the null connector to set its ID.
    • Added a hidden CLI flag cdc-resume-token-interval to control resume token update frequency using duration values (e.g., “30s”, “5m”).
  • Chores

    • Updated example app and tests to use the new null connector initialization.
    • Reduced noisy debug logging in the Mongo connector.

@coderabbitai
Copy link

coderabbitai bot commented Sep 17, 2025

Walkthrough

The null connector gains an id field and exposes it via GetInfo. NewConn now requires an id string as the first parameter; all call sites and CLI wiring are updated, including a new --id flag. A hidden cdc-resume-token-interval duration flag is added. Mongo connector removes a debug log.

Changes

Cohort / File(s) Summary
Null connector ID and API update
connectors/null/connector.go, connectors/null/connector_test.go, cmd/grpcexample/main.go, internal/app/options/connectorflags.go
Add internal id to conn; GetInfo now returns Id. Change NewConn signature to NewConn(string, bool, time.Duration, time.Duration) and update all invocations. Add --id CLI flag and pass through to NewConn.
Mongo connector logging tweak
connectors/mongo/conn.go
Remove a slog.Debug call in convertChangeStreamEventToUpdate; no functional changes.
CLI duration flag addition and parsing
internal/app/options/flags.go, internal/app/options/options.go
Add hidden --cdc-resume-token-interval duration flag; switch option parsing to use duration value directly (no int-to-seconds conversion).

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant User
  participant CLI as CLI Options
  participant Factory as Connector Factory
  participant Null as Null Connector
  participant RPC as GetInfo RPC

  User->>CLI: Provide flags (--id, --log-json, --sleep, --sleep-jitter,<br/>--cdc-resume-token-interval)
  note right of CLI: New flag: cdc-resume-token-interval (duration)
  CLI->>Factory: Build config (id, logJson, sleep, sleepJitter)
  Factory->>Null: NewConn(id, logJson, sleep, sleepJitter)
  activate Null
  Null-->>Factory: conn{ id: string, ... }
  deactivate Null

  User->>RPC: GetInfo()
  RPC->>Null: GetInfo
  Note over Null: Returns Id from internal field
  Null-->>RPC: GetInfoResponse{ Id, ... }
  RPC-->>User: Response with Id
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • Fakesource #292 — Prior changes to the null connector’s NewConn signature and tests; this PR further evolves the same constructor by adding the id parameter and propagating it.

Poem

I nibble flags by moonlit screen,
New ids sprout where logs once preen.
A whisper: durations tell their tale,
The null bun hops along the trail.
GetInfo squeaks, “Here’s my name!” 🌙
Thump-thump—merged, and off I came. 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 55.56% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The PR title succinctly captures the two main changes: adding an id option for the /dev/null connector and surfacing the resume-token update interval. It is concise, specific to the modified areas, and readable for teammates scanning history.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch moreconfig

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@adiom-mark adiom-mark merged commit 6af041e into main Sep 17, 2025
1 of 2 checks passed
@adiom-mark adiom-mark deleted the moreconfig branch September 17, 2025 15:46
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (7)
internal/app/options/flags.go (1)

147-151: Clarify duration flag semantics (units, default).

Add a Usage to indicate expected format (Go duration) and that 0 disables periodic updates.

-		altsrc.NewDurationFlag(&cli.DurationFlag{
-			Name:     "cdc-resume-token-interval",
-			Required: false,
-			Hidden:   true,
-		}),
+		altsrc.NewDurationFlag(&cli.DurationFlag{
+			Name:     "cdc-resume-token-interval",
+			Usage:    "Interval to persist CDC resume token (e.g., 30s, 1m). Zero disables.",
+			Required: false,
+			Hidden:   true,
+		}),

Please confirm that existing configs (if any) already use Go duration strings; otherwise, we may need a migration note.

connectors/mongo/conn.go (1)

564-564: Remove commented-out debug or reintroduce with proper level gating.

Leaving commented logs adds noise. Prefer deletion or a structured debug gated by log level.

-	// slog.Debug(fmt.Sprintf("Converting change stream event %v", change))
internal/app/options/options.go (1)

69-69: Duration parsing change may break older configs using bare integers.

cli.Duration requires unit-suffixed values (e.g., "30s"). If existing YAML/env used plain integers for seconds, they'll now parse as 0.

If back-compat is required, consider a hidden legacy seconds flag as fallback or accept numeric strings by custom parsing before defaulting to c.Duration("cdc-resume-token-interval").

cmd/grpcexample/main.go (1)

35-35: Use a non-empty example id for clarity.

Demonstrates intent and surfaces the new field in GetInfo.

-	nullConn := null.NewConn("", false, 0, 0)
+	nullConn := null.NewConn("grpcexample", false, 0, 0)
connectors/null/connector_test.go (1)

22-23: Add a focused test asserting id propagation via GetInfo.

Covers the new constructor arg and API surface.

Example test (new file or appended):

func TestNullConnector_GetInfo_Id(t *testing.T) {
	h := NewConn("test-id", false, 0, 0)
	_, handler := adiomv1connect.NewConnectorServiceHandler(h)
	srv, err := memhttp.New(handler)
	if err != nil { t.Fatal(err) }
	client := adiomv1connect.NewConnectorServiceClient(srv.Client(), srv.URL())

	resp, err := client.GetInfo(context.Background(), connect.NewRequest(&adiomv1.GetInfoRequest{}))
	if err != nil { t.Fatal(err) }
	if got := resp.Msg.GetId(); got != "test-id" {
		t.Fatalf("Id = %q, want %q", got, "test-id")
	}
}

Also applies to: 29-30

internal/app/options/connectorflags.go (1)

291-294: Allow setting id via env var; confirm empty id is acceptable downstream.

Expose DSYNC_CONNECTOR_ID for non-interactive use. Also verify that an empty id is safe for all consumers of GetInfo().Id.

 				&cli.StringFlag{
 					Name:  "id",
 					Usage: "A fixed id for the connector",
+					EnvVars: []string{"DSYNC_CONNECTOR_ID"},
 				},
 ...
-				return null.NewConn(c.String("id"), c.Bool("log-json"), c.Duration("sleep"), c.Duration("sleep-jitter")), nil
+				return null.NewConn(c.String("id"), c.Bool("log-json"), c.Duration("sleep"), c.Duration("sleep-jitter")), nil

Also applies to: 296-296

connectors/null/connector.go (1)

37-47: GetInfo now exposes Id — OK; consider stable ordering of SupportedDataTypes

Exposing Id: c.id is fine. Optional: build all in a stable, deterministic order (e.g., sort by enum value) to avoid nondeterministic diffs/logs across runs.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e5d5efd and 6f82340.

📒 Files selected for processing (7)
  • cmd/grpcexample/main.go (1 hunks)
  • connectors/mongo/conn.go (1 hunks)
  • connectors/null/connector.go (3 hunks)
  • connectors/null/connector_test.go (1 hunks)
  • internal/app/options/connectorflags.go (1 hunks)
  • internal/app/options/flags.go (1 hunks)
  • internal/app/options/options.go (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (4)
internal/app/options/connectorflags.go (1)
connectors/null/connector.go (1)
  • NewConn (148-150)
cmd/grpcexample/main.go (1)
connectors/null/connector.go (1)
  • NewConn (148-150)
connectors/null/connector_test.go (3)
connectors/common/base.go (1)
  • NewLocalConnector (884-896)
connectors/null/connector.go (1)
  • NewConn (148-150)
pkg/test/connector.go (2)
  • NewConnectorTestSuite (39-41)
  • ClientFromHandler (30-37)
connectors/null/connector.go (5)
connectors/mongo/conn.go (1)
  • NewConn (933-941)
connectors/cosmos/conn.go (1)
  • NewConn (515-552)
connectors/testconn/connector.go (1)
  • NewConn (388-394)
connectors/dynamodb/conn.go (1)
  • NewConn (381-403)
connectors/random/connector.go (1)
  • NewConn (124-138)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (2)
connectors/null/connector.go (2)

24-28: Adding id field to conn looks good

No functional concerns. This enables plumbing the connector id cleanly.


148-150: Prefer keyed struct literal and tighten signature

Replace the unkeyed composite literal with a keyed one and combine identical time.Duration parameters; call sites already pass four args so no call-site changes are needed.

File: connectors/null/connector.go (around lines 148–150)

-func NewConn(id string, logJson bool, sleep time.Duration, sleepJitter time.Duration) adiomv1connect.ConnectorServiceHandler {
-	return &conn{id, logJson, sleep, sleepJitter}
+func NewConn(id string, logJson bool, sleep, sleepJitter time.Duration) adiomv1connect.ConnectorServiceHandler {
+	return &conn{
+		id:          id,
+		logJson:     logJson,
+		sleep:       sleep,
+		sleepJitter: sleepJitter,
+	}
 }

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.

1 participant