Skip to content

Fixes #28152: Add NATS JetStream Messaging Connector - #28153

Closed
rafaelmgrecco wants to merge 29 commits into
open-metadata:mainfrom
rafaelmgrecco:feature/nats-connector
Closed

rafaelmgrecco wants to merge 29 commits into
open-metadata:mainfrom
rafaelmgrecco:feature/nats-connector

Conversation

@rafaelmgrecco

@rafaelmgrecco rafaelmgrecco commented May 15, 2026 •

Copy link
Copy Markdown
Contributor

Describe your changes:

FIxes: #28152

Adds a new NATS JetStream connector for the Messaging service type.

NATS is a high-performance open-source messaging system. This connector ingests JetStream streams as OpenMetadata Topics, including stream configuration metadata, schema definitions, and sample data — without depending on any Kafka/Confluent ecosystem component.

What was built:

  • Python connector (ingestion/src/metadata/ingestion/source/messaging/nats/):

    • connection.py — async NATS client with TLS cert management and event loop handling
    • metadata.py — NatsSource extending MessagingServiceSource; paginates the JetStream stream list and maps stream config/state to OpenMetadata Topic fields
    • models.py — Pydantic v2 models for JetStream stream config and state
    • service_spec.py — service spec registration
  • Schema-native schema ingestion — instead of Confluent Schema Registry, schemas are fetched from a JetStream KV bucket. The connector auto-detects the format (Avro JSON, JSON Schema, or Protobuf .proto text) from the stored value.

  • Authentication support: basic auth (username/password), token, NKey seed, and TLS mutual auth.

  • JSON Schema (openmetadata-spec/.../natsConnection.json) with all connection properties.

  • Test connection steps: GetTopics (validates JetStream access) and CheckSchemaKvBucket (optional, validates schema bucket).

  • UI integration: connection form schema, service icon, in-app field documentation (Nats.md), MessagingServiceUtils.ts case, ServiceIconUtils.ts entry.

  • Workflow example: ingestion/src/metadata/examples/workflows/nats.yaml.

  • Tests: 66 unit tests covering connection options, topic listing/pagination, schema type detection, sample data fetching, and error handling. Integration tests with testcontainers spinning up a real NATS server.

Supported metadata:

Field Source
Topics (streams) $JS.API.STREAM.NAMES + $JS.API.STREAM.INFO.*
Subjects, retention, storage, replicas Stream config
Message count, consumer count, sequence range Stream state
Schema (Avro / JSON Schema / Protobuf) JetStream KV bucket
Sample data $JS.API.STREAM.MSG.GET.* (last N messages)
Source URL NATS monitoring endpoint (/jsz?stream=...)
Topic filter pattern Applied by base class

Type of change:

  • Bug fix
  • Improvement
  • New feature
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation

Checklist:

  • I have read the CONTRIBUTING document.
  • I have commented on my code, particularly in hard-to-understand areas.
  • For JSON Schema changes: I updated the migration scripts or explained why it is not needed.

    The new natsConnection.json schema is additive — no existing records are affected and no migration is required.

  • The issue properly describes why the new feature is needed, what's the goal, and how we are building it. Any discussion or decision-making process is reflected in the issue.
  • I have updated the documentation.
  • I have added tests around the new logic.

Greptile Summary

This PR adds a new NATS JetStream messaging connector that ingests JetStream streams as OpenMetadata Topics, with support for schema detection from a KV bucket, sample data fetching, and four authentication methods (basic, token, NKey, TLS mutual auth).

  • Python connector (connection.py, metadata.py, models.py, service_spec.py) with paginated stream listing, nanosecond-to-millisecond retention conversion, and schema auto-detection (Avro / JSON Schema / Protobuf) from a configurable JetStream KV bucket.
  • Schema and UI wiring: new natsConnection.json spec, generated TypeScript types, lazy-loaded connection form schema, service icon, and in-app field docs — all following the existing connector patterns.
  • Tests: 66 unit tests covering connection options, pagination, schema detection, sample data, and error paths; integration tests using testcontainers with a pinned nats:2.10 image.

Confidence Score: 5/5

Safe to merge; the new connector is fully additive with no impact on existing connectors or data.

The connector introduces a new service type without touching any shared code paths. The resource-management concern flagged in a prior review round has been addressed in the current code with a proper try/except/cleanup block in get_connection. The only remaining item is a dead constant (_JS_PAGE_SIZE) that has no runtime impact.

No files require special attention; the unused page-size constant in metadata.py is the only loose end.

Important Files Changed

Filename Overview
ingestion/src/metadata/ingestion/source/messaging/nats/metadata.py Core ingestion logic: maps JetStream streams to OpenMetadata Topics with schema detection, sample data fetching, and paginated stream listing. The _JS_PAGE_SIZE constant is defined but never included in the pagination request payload.
ingestion/src/metadata/ingestion/source/messaging/nats/connection.py NATS async client wrapper with TLS cert management. get_connection now correctly wraps both _build_connect_opts and the connect call in a try/except that cleans up the event loop and temp cert files on failure.
ingestion/src/metadata/ingestion/source/messaging/nats/models.py Pydantic v2 models for JetStream stream config and state with extra="allow" to handle unknown server fields gracefully.
ingestion/tests/integration/nats/conftest.py Integration test fixtures using testcontainers with a pinned nats:2.10 image. The max_age=86400 value passed to js.add_stream() is treated as raw nanoseconds by nats-py, making the retention effectively ~86µs rather than 24h.
ingestion/tests/unit/source/messaging/test_nats.py 66 unit tests covering connection opts, topic listing/pagination, schema detection, sample data, and error paths. Well-structured with good coverage of edge cases.
openmetadata-spec/src/main/resources/json/schema/entity/services/connections/messaging/natsConnection.json Additive JSON Schema for NATS connection config; required fields and property definitions look correct. No migration needed as it introduces a new service type.
openmetadata-ui/src/main/resources/ui/src/utils/MessagingServiceUtils.ts Adds Nats to the lazy-loaded schema loaders map; follows the same pattern as other messaging connectors.
openmetadata-ui/src/main/resources/ui/src/utils/ServiceIconUtils.ts Adds the NATS service icon entry alongside existing messaging connectors.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant W as MetadataWorkflow
    participant NS as NatsSource
    participant NC as NatsClient
    participant JS as NATS JetStream API
    participant KV as KV Bucket (schemas)
    participant OM as OpenMetadata

    W->>NS: get_topic_list()
    loop Paginate streams
        NS->>NC: "request($JS.API.STREAM.NAMES, {offset})"
        NC->>JS: NATS request
        JS-->>NC: "{streams: [...], total: N}"
        NC-->>NS: parsed dict
        NS->>NC: "request($JS.API.STREAM.INFO.{name})"
        NC->>JS: NATS request
        JS-->>NC: "{config, state}"
        NC-->>NS: BrokerTopicDetails
    end
    W->>NS: yield_topic(details)
    NS->>NC: "request($JS.API.STREAM.MSG.GET.KV_{bucket})"
    NC->>KV: fetch schema key
    KV-->>NC: base64-encoded schema text
    NC-->>NS: schema text
    NS->>NS: _detect_schema_type()
    NS-->>W: Either[CreateTopicRequest]
    W->>OM: upsert Topic
    W->>NS: yield_topic_sample_data(details)
    loop Last N messages
        NS->>NC: "request($JS.API.STREAM.MSG.GET.{name}, {seq})"
        NC->>JS: NATS request
        JS-->>NC: base64 message data
        NC-->>NS: decoded message
    end
    NS-->>W: Either[OMetaTopicSampleData]
    W->>OM: upsert sample data
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant W as MetadataWorkflow
    participant NS as NatsSource
    participant NC as NatsClient
    participant JS as NATS JetStream API
    participant KV as KV Bucket (schemas)
    participant OM as OpenMetadata

    W->>NS: get_topic_list()
    loop Paginate streams
        NS->>NC: "request($JS.API.STREAM.NAMES, {offset})"
        NC->>JS: NATS request
        JS-->>NC: "{streams: [...], total: N}"
        NC-->>NS: parsed dict
        NS->>NC: "request($JS.API.STREAM.INFO.{name})"
        NC->>JS: NATS request
        JS-->>NC: "{config, state}"
        NC-->>NS: BrokerTopicDetails
    end
    W->>NS: yield_topic(details)
    NS->>NC: "request($JS.API.STREAM.MSG.GET.KV_{bucket})"
    NC->>KV: fetch schema key
    KV-->>NC: base64-encoded schema text
    NC-->>NS: schema text
    NS->>NS: _detect_schema_type()
    NS-->>W: Either[CreateTopicRequest]
    W->>OM: upsert Topic
    W->>NS: yield_topic_sample_data(details)
    loop Last N messages
        NS->>NC: "request($JS.API.STREAM.MSG.GET.{name}, {seq})"
        NC->>JS: NATS request
        JS-->>NC: base64 message data
        NC-->>NS: decoded message
    end
    NS-->>W: Either[OMetaTopicSampleData]
    W->>OM: upsert sample data
Loading

Reviews (8): Last reviewed commit: "Update generated TypeScript types" | Re-trigger Greptile

@rafaelmgrecco
rafaelmgrecco requested review from a team as code owners May 15, 2026 15:27
@github-actions

Copy link
Copy Markdown
Contributor

Hi there 👋 Thanks for your contribution!

The OpenMetadata team will review the PR shortly! Once it has been labeled as safe to test, the CI workflows
will start executing and we'll be able to make sure everything is working as expected.

Let us know if you need any help!

@harshach harshach added the safe to test Add this label to run secure Github workflows on PRs label May 15, 2026
@harshach

Copy link
Copy Markdown
Collaborator

hi @rafaelmgrecco thanks for the contribution

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ TypeScript Types Need Update

The generated TypeScript types are out of sync with the JSON schema changes.

Since this is a pull request from a forked repository, the types cannot be automatically committed.
Please generate and commit the types manually:

cd openmetadata-ui/src/main/resources/ui
./json2ts-generate-all.sh -l true
git add src/generated/
git commit -m "Update generated TypeScript types"
git push

After pushing the changes, this check will pass automatically.

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ TypeScript Types Need Update

The generated TypeScript types are out of sync with the JSON schema changes.

Since this is a pull request from a forked repository, the types cannot be automatically committed.
Please generate and commit the types manually:

cd openmetadata-ui/src/main/resources/ui
./json2ts-generate-all.sh -l true
git add src/generated/
git commit -m "Update generated TypeScript types"
git push

After pushing the changes, this check will pass automatically.

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ TypeScript Types Need Update

The generated TypeScript types are out of sync with the JSON schema changes.

Since this is a pull request from a forked repository, the types cannot be automatically committed.
Please generate and commit the types manually:

cd openmetadata-ui/src/main/resources/ui
./json2ts-generate-all.sh -l true
git add src/generated/
git commit -m "Update generated TypeScript types"
git push

After pushing the changes, this check will pass automatically.

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

⚠️ TypeScript Types Need Update

The generated TypeScript types are out of sync with the JSON schema changes.

Since this is a pull request from a forked repository, the types cannot be automatically committed.
Please generate and commit the types manually:

cd openmetadata-ui/src/main/resources/ui
./json2ts-generate-all.sh -l true
git add src/generated/
git commit -m "Update generated TypeScript types"
git push

After pushing the changes, this check will pass automatically.

@sonarqubecloud

sonarqubecloud Bot commented Jul 8, 2026

Copy link
Copy Markdown

@sonarqubecloud

sonarqubecloud Bot commented Jul 8, 2026

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

This PR has had no activity for 30 days and will be closed in 7 days if no further activity occurs.
Feel free to reopen it if you'd like to continue working on it.

# Conflicts:
#	ingestion/.basedpyright/baseline.json
#	openmetadata-ui/src/main/resources/ui/src/generated/api/automations/createWorkflow.ts
#	openmetadata-ui/src/main/resources/ui/src/generated/api/services/ingestionPipelines/createIngestionPipeline.ts
#	openmetadata-ui/src/main/resources/ui/src/generated/entity/automations/testServiceConnection.ts
#	openmetadata-ui/src/main/resources/ui/src/generated/entity/automations/workflow.ts
#	openmetadata-ui/src/main/resources/ui/src/generated/entity/services/connections/serviceConnection.ts
#	openmetadata-ui/src/main/resources/ui/src/generated/entity/services/ingestionPipelines/ingestionPipeline.ts
#	openmetadata-ui/src/main/resources/ui/src/generated/entity/services/ingestionPipelines/serviceProgressEvent.ts
#	openmetadata-ui/src/main/resources/ui/src/generated/metadataIngestion/testSuitePipeline.ts
#	openmetadata-ui/src/main/resources/ui/src/generated/metadataIngestion/workflow.ts
@github-actions

Copy link
Copy Markdown
Contributor

Hi there 👋 Thanks for your contribution!

The OpenMetadata team will review the PR shortly! Once it has been labeled as safe to test, the CI workflows
will start executing and we'll be able to make sure everything is working as expected.

Let us know if you need any help!

@rafaelmgrecco

Copy link
Copy Markdown
Contributor Author

@harshach Sorry, I got involved with a project at work, but I've already resolved the existing conflicts. Is there anything else needed to perform the merge?

@github-actions

Copy link
Copy Markdown
Contributor

Hi there 👋 Thanks for your contribution!

The OpenMetadata team will review the PR shortly! Once it has been labeled as safe to test, the CI workflows
will start executing and we'll be able to make sure everything is working as expected.

Let us know if you need any help!

@github-actions

Copy link
Copy Markdown
Contributor

Hi there 👋 Thanks for your contribution!

The OpenMetadata team will review the PR shortly! Once it has been labeled as safe to test, the CI workflows
will start executing and we'll be able to make sure everything is working as expected.

Let us know if you need any help!

@rafaelmgrecco

Copy link
Copy Markdown
Contributor Author

@harshach If you need anything else, just let me know.

@harshach

Copy link
Copy Markdown
Collaborator

@rafaelmgrecco need all of these checks passing. If there are nay changes in your PR affecting these, please fix them.

@github-actions

Copy link
Copy Markdown
Contributor

Hi there 👋 Thanks for your contribution!

The OpenMetadata team will review the PR shortly! Once it has been labeled as safe to test, the CI workflows
will start executing and we'll be able to make sure everything is working as expected.

Let us know if you need any help!

@gitar-bot

gitar-bot Bot commented Aug 12, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 13 resolved / 13 findings

Adds the new NATS JetStream messaging connector with comprehensive unit and integration tests, schema auto-detection, and UI integration. Additive feature with all previous findings successfully addressed.

✅ 13 resolved
✅ Bug: TLS config uses non-existent nats-py parameters

📄 ingestion/src/metadata/ingestion/source/messaging/nats/connection.py:103-110
The _build_connect_opts function sets tls_ca_file, tls_cert_file, and tls_key_file in the options dict passed to nats.connect(). However, nats-py does not accept these parameters — it expects a tls parameter with an ssl.SSLContext object. This means TLS connections will silently ignore the certificates (they'll be passed as unknown kwargs) and fail to establish secure connections or connect without proper verification.

✅ Bug: nkeys_seed expects a file path, not raw bytes

📄 ingestion/src/metadata/ingestion/source/messaging/nats/connection.py:100-101
The nats-py library's nkeys_seed parameter expects a file path string pointing to a file containing the seed, not the raw seed bytes. The current code passes connection.nkeySeed.get_secret_value().encode() which will cause a TypeError or connection failure when NKey authentication is used.

✅ Edge Case: Missing newline at end of natsConnection.json

📄 openmetadata-spec/src/main/resources/json/schema/entity/services/connections/messaging/natsConnection.json:86
The JSON schema file natsConnection.json is missing a trailing newline character (the diff shows \ No newline at end of file). While not a functional issue, this causes unnecessary diff noise in future edits and violates POSIX text file conventions.

✅ Security: additionalConfig can override auth/TLS connection options

📄 ingestion/src/metadata/ingestion/source/messaging/nats/connection.py:118-119
In _build_connect_opts, opts.update(connection.additionalConfig) is called after setting servers, user, password, token, tls, and nkeys_seed_str. This means any value in additionalConfig can silently override these security-critical parameters. A user (or anyone with access to the service connection config) could:

  • Override servers to point to a malicious NATS proxy and capture credentials
  • Override tls with None to disable encryption
  • Override user/password to impersonate another identity

Since additionalConfig is a free-form JSON object with no key restrictions in the schema, this creates a security gap.

✅ Edge Case: _detect_schema_type falsely classifies text containing 'message ' as Protobuf

📄 ingestion/src/metadata/ingestion/source/messaging/nats/metadata.py:74-76
The heuristic in _detect_schema_type checks for "message " in stripped to identify Protobuf schemas. However, any non-JSON text containing the word "message " (e.g., plain text documentation, YAML, or error messages stored as schema text) would be misclassified as Protobuf. This could lead to schema parsing failures for those entries.

A more robust check would require both a syntax declaration AND a message keyword, or use a regex that matches Protobuf structure more precisely.

...and 8 more resolved from earlier reviews

Options

Display: compact → Showing less information.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ TypeScript Types Need Update

The generated TypeScript types are out of sync with the JSON schema changes.

Since this is a pull request from a forked repository, the types cannot be automatically committed.
Please generate and commit the types manually:

cd openmetadata-ui/src/main/resources/ui
./json2ts-generate-all.sh -l true
git add src/generated/
git commit -m "Update generated TypeScript types"
git push

After pushing the changes, this check will pass automatically.

@github-actions

Copy link
Copy Markdown
Contributor

❌ UI Checkstyle Failed

❌ Licence Header

One or more files are missing or have an outdated Apache 2.0 licence header.

Affected files
  • openmetadata-ui/src/main/resources/ui/src/generated/api/automations/createWorkflow.ts
    • openmetadata-ui/src/main/resources/ui/src/generated/entity/automations/testServiceConnection.ts
    • openmetadata-ui/src/main/resources/ui/src/generated/entity/automations/workflow.ts
    • openmetadata-ui/src/main/resources/ui/src/generated/entity/services/connections/serviceConnection.ts
    • openmetadata-ui/src/main/resources/ui/src/generated/metadataIngestion/testSuitePipeline.ts

🔍 ESLint findings in this PR's files — 0 error(s), 15 warning(s)

Errors block the build. Warnings do not yet — they are rules whose backlog is still
being worked down, listed so this PR does not add to it. See docs/ui-code-quality-gate.md.

0 error(s), 15 warning(s) across 1 changed file(s).

Count Rule
14 i18next/no-literal-string
1 sonarjs/no-duplicate-string
All findings
Location Rule Message
🟡 src/components/Customization/GenericTab/DynamicHeightWidget.test.tsx:32:8 sonarjs/no-duplicate-string Define a constant instead of duplicating this literal 7 times.
🟡 src/components/Customization/GenericTab/DynamicHeightWidget.test.tsx:51:41 i18next/no-literal-string disallow literal string:
Test Content
🟡 src/components/Customization/GenericTab/DynamicHeightWidget.test.tsx:64:16 i18next/no-literal-string disallow literal string:
Test Content
🟡 src/components/Customization/GenericTab/DynamicHeightWidget.test.tsx:79:40 i18next/no-literal-string disallow literal string:
Child 1
🟡 src/components/Customization/GenericTab/DynamicHeightWidget.test.tsx:81:21 i18next/no-literal-string disallow literal string: Nested Content
🟡 src/components/Customization/GenericTab/DynamicHeightWidget.test.tsx:100:16 i18next/no-literal-string disallow literal string:
Test Content
🟡 src/components/Customization/GenericTab/DynamicHeightWidget.test.tsx:116:16 i18next/no-literal-string disallow literal string:
Test Content
🟡 src/components/Customization/GenericTab/DynamicHeightWidget.test.tsx:132:16 i18next/no-literal-string disallow literal string:
Test Content
🟡 src/components/Customization/GenericTab/DynamicHeightWidget.test.tsx:148:16 i18next/no-literal-string disallow literal string:
Test Content
🟡 src/components/Customization/GenericTab/DynamicHeightWidget.test.tsx:180:16 i18next/no-literal-string disallow literal string:
Test Content
🟡 src/components/Customization/GenericTab/DynamicHeightWidget.test.tsx:197:16 i18next/no-literal-string disallow literal string:
Test Content
🟡 src/components/Customization/GenericTab/DynamicHeightWidget.test.tsx:211:16 i18next/no-literal-string disallow literal string:
Test Content
🟡 src/components/Customization/GenericTab/DynamicHeightWidget.test.tsx:232:16 i18next/no-literal-string disallow literal string:
Test Content
🟡 src/components/Customization/GenericTab/DynamicHeightWidget.test.tsx:246:16 i18next/no-literal-string disallow literal string:
Test Content
🟡 src/components/Customization/GenericTab/DynamicHeightWidget.test.tsx:256:16 i18next/no-literal-string disallow literal string:
Test Content

Fix locally (fast - only checks files changed in this branch):

make ui-checkstyle-changed

@sonarqubecloud

Copy link
Copy Markdown

@harshach

Copy link
Copy Markdown
Collaborator

Working on merging this PR

@harshach

Copy link
Copy Markdown
Collaborator

@rafaelmgrecco I cherry-picked your code into a branch and fixed rest of the comments. Thanks for the contribution. Its in main now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

safe to test Add this label to run secure Github workflows on PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(ingestion): Add NATS Messaging Service Connector

3 participants