Skip to content

Ingestion

Publishing, admission and the schema registry

The ingestion endpoint (POST /api/events/pub) accepts every content mode of the CloudEvents HTTP binding.

Mode Request Response
Structured the body is a cloud event, with Content-Type: application/cloudevents+json 204 No Content
Binary the body is the event’s data, and its context attributes are ce- prefixed headers, e.g. ce-specversion, ce-id, ce-source, ce-type 204 No Content
Batched the body is an array of cloud events, with Content-Type: application/cloudevents-batch+json 200 OK, with one result per event

Binary mode:

  • the Content-Type header is the event’s datacontenttype;
  • JSON data is stored as JSON, and text as a string;
  • any other data is stored and delivered as data_base64.

Batches:

  • events are ingested one at a time, in order;
  • each event is admitted on its own, so an invalid or refused event doesn’t prevent the others from being stored;
  • each result gives the event’s index, id, source and status, which is what the gateway would have answered had the event been published alone, plus an outcome or a problem.
[
  { "index": 0, "id": "1", "source": "https://orders.example.com", "status": 201, "outcome": "stored" },
  { "index": 1, "status": 400, "problem": { "title": "Bad Request", "detail": "The cloud event at index 1 is not a valid cloud event: ..." } }
]

Requests in any other format are refused with 415 Unsupported Media Type.

A gateway’s spec.ingestion limits the size of requests, deduplicates events, and limits the rate at which they’re published:

spec:
  ingestion:
    maxRequestBodySize: 1048576     # bytes, larger requests are refused with 413. Defaults to the server's limit (30 MB)
    maxBatchSize: 100               # events per batch, larger batches are refused with 413. Unlimited by default
    deduplication:
      window: PT10M                 # how long a stored event is remembered by its source and id
    rateLimits:
      - partition: publisher        # each publisher, by the name it authenticated with. Anonymous publishers share a limit
        limit: 100
        period: PT1S
      - partition: source           # each source of events
        limit: 1000000
        period: P1D                 # a long period makes the limit a quota

Deduplication:

  • A publisher that retries after a timeout may publish the same event twice. Within the window, an event whose source and id have already been stored is answered as a success (204, with cloudstreams-outcome: duplicate), but isn’t stored again.
  • An event that’s still being ingested is answered 503 with Retry-After. Retrying tells whether it has been stored.
  • An event that fails to be stored, or is refused, isn’t remembered.

Rate limits:

  • Events are counted in fixed windows of each limit’s period. The counters are kept in Redis and shared by every replica of the gateway.
  • An event beyond any limit is refused with 429 Too Many Requests, and a Retry-After header that tells when its window ends.
  • Refused events count against the limits too.

Duplicates are counted by the cloud_streams_gateway_events_duplicate_count metric. Rate-limited events are counted as rejected, with the rate_limit reason.

Admission

Until a gateway has loaded its configuration, it answers 503 Service Unavailable (with Retry-After), rather than admitting events its policies were not applied to.

  • Time-based authorization rules (temporary, timeOfDay) are evaluated against the time at which the gateway receives the event, not against its publisher-supplied time attribute. A timeOfDay range whose end precedes its start spans midnight, e.g. from 22:00 to 06:00.
  • Attribute patterns match the source as it was published. A source without a path, such as https://orders.example.com, used to be compared with a trailing slash, so a pattern anchored with $ never matched it. This also applies to the attribute patterns of metadata extraction.
  • Regular expressions used by authorization rules, ingestion configurations and subscription attribute filters are not anchored: order.created also matches xorder_createdx. Use ^order\.created$ to match the whole value. Every match times out after 250 ms, and a match that times out is treated as a mismatch.
  • Data schemas referenced by events’ dataschema attribute are fetched over HTTP(S) only, never from private, loopback or link-local addresses, and kept in a bounded cache. A schema that cannot be fetched or parsed causes the event to be rejected with 400 Bad Request:
SchemaRegistry:
  AllowedHosts: [ schemas.example.com, '*.example.org' ]   # any public host if empty
  AllowPrivateNetworks: false
  Timeout: '00:00:10'
  MaxSize: 1048576                                         # bytes
  CacheSize: 1000

Schema registry

JSON schemas can be registered as Schema resources, at /api/resources/v1/schemas:

apiVersion: cloud-streams.io/v1
kind: Schema
metadata:
  name: order-placed
spec:
  compatibility: backward       # backward (default), forward, full or none
  versions:
    - version: 1
      schema: { "type": "object", "properties": { "id": { "type": "string" } }, "required": [ "id" ] }

Versions:

  • Versions can be added, but neither changed nor removed. Their numbers increase.

  • Each new version must be compatible with the previous one:

    • backward: the new version accepts every document the previous one accepts, so consumers on the new version can read older data;
    • forward: the previous version accepts every document the new one accepts;
    • full: both.

    An incompatible version is refused with 400 Bad Request, which explains why.

What the compatibility check verifies:

  • Understood keywords: type, enum, const, required, properties, additionalProperties, items, and numeric, length, item and property count bounds.
  • Other constraints, such as pattern, format, $ref or oneOf: these are only accepted if they’re unchanged.
  • Annotations, such as title or description, are ignored.
  • Open schemas: as in Confluent’s Schema Registry, a schema that doesn’t set additionalProperties: false accepts any other property. So adding a constrained property to it isn’t backward compatible: documents that already carried that property with another value would be refused.
GET  /api/resources/v1/schemas/{name}/versions/{version|latest}   # the JSON schema of a version
POST /api/resources/v1/schemas/{name}/compatibility               # checks a JSON schema against the latest version, without changing anything

A gateway validates the data of the events an ingestion configuration applies to against a registered schema. The binding uses its latest version, or a pinned one, and applies whatever the validation policy, unless it skips validation:

spec:
  events:
    - source: ^https://orders\.example\.com$
      type: order.placed
      schema:
        name: order-placed
        version: 1              # defaults to the latest version

Events whose data is invalid are refused with 400 Bad Request, which names the version they were checked against. Gateways read schemas again at most every 10 seconds, so new versions apply shortly after they’re registered.