Schemas

Schema Registry schemas, their compatibility settings, and their versions are browsed and managed from the Schemas page in Cloudera Surveyor for Apache Kafka.

Schemas page

The Schemas page lists all schemas in the selected Schema Registry instance. View the type, compatibility, validation level, and evolution setting of each schema. Filter and sort schemas by name, compatibility, validation level, evolution, type, or group. Add new schemas as needed.

Figure 1. Schemas page

The table displays the following schema attributes:

  • Name – The unique name of the schema in the Schema Registry instance. Click to open the Schema Details page.

  • Compatibility – The compatibility rule that new schema versions must satisfy, such as Backward, Forward, Both, or None.

  • Validation Level – The set of existing versions that a new version is checked against, either All or Latest.

  • Evolution – The indication of whether new versions can be added to the schema after the first version.

  • Type – The format of the schema, either Avro or JSON.

  • Schema Group – The user-defined group the schema belongs to.

Click Add Schema to create a new schema. Click any schema row to open the Entity Details drawer for quick access to the schema text of the latest version. Click the schema name to go to the Schema Details page.

Schema Details page

The Schema Details page provides information about an individual schema and its versions. At the top of the page, a summary displays the metadata of the schema, such as its type and compatibility.

Figure 2. Schema Details page

The page is organized into the following sections:

  • Schema Text – The schema editor, which displays the schema text and description of the selected version. Use the editor to view a version, or to create a new version by editing the displayed text, typing or pasting new text, or loading text from a file using Add File. Add the new version with Add Version, or revert your edits with Discard Changes.

  • Versions – A table of all versions of the schema, where you can compare versions and change the state of a version. By default, the latest version is selected and displayed in the Schema Text section. Click any row to display that version instead. The table displays the following attributes:

    • Version – The version number of the schema. Each schema numbers its own versions, starting at 1.

    • ID – The unique ID of the version across all schemas in Schema Registry. Clients can use the ID to reference this exact version.

    • Created – The time when the version was added.

    • State – The state of the version, which determines whether the version is included in compatibility checks. Enabled versions are included. Disabled and Archived versions are excluded, but only a disabled version can be enabled again. Archived is a terminal state.

    • Description – The description of the version. Hover over a truncated description to view the full text.

Adding schemas

Add new schemas with their first version to Schema Registry in Cloudera Surveyor using the Add Schema option on the Schemas page.

A schema in Schema Registry consists of metadata and schema text. The metadata, such as the name, type, and compatibility, applies to the schema as a whole. The schema text is stored in versions, where each version holds a different revision of the schema text.

In Cloudera Surveyor, adding a schema is done in two steps. First, you create the schema metadata in the Add Schema modal, which you open using the Schemas > Add Schema option. Second, you add schema text on the Schema Details page, which opens after the metadata is created, to create the first version of the schema.

  • You must have the necessary permissions to add schemas in Schema Registry. In Apache Ranger, the required permissions are Read and Create on the Schema Registry Service or Schema Group resource.

  1. In Cloudera Surveyor, click Schemas.
  2. At the top left, next to the page title, click the Instance: selector and select your Schema Registry instance from the list.
  3. Click Add Schema at the top right of the table.
  4. In the Add Schema modal, configure your schema:
    1. Enter the Name – The unique name of the schema in the Schema Registry instance.
    2. Select the Schema Group – A user-defined group for organizing related schemas.
    3. Select the Schema Type – The format of the schema, either Avro or JSON.
    4. Select the Compatibility – The compatibility rule that new schema versions must satisfy. When you add a version, Schema Registry checks the schema text against this rule and rejects the version if it does not satisfy it. Writing schema text that satisfies the rule is up to you.
      • Backward – Consumers on the new schema can read messages produced with the old schema. For example, adding a field without a default value is rejected, because consumers on the new schema cannot fill in the field when reading old messages.

      • Forward – Consumers on the old schema can read messages produced with the new schema. For example, removing a field without a default value is rejected, because consumers on the old schema expect the field in new messages.

      • Both – Consumers on the new schema can read messages produced with the old schema, and consumers on the old schema can read messages produced with the new schema.

      • None – No compatibility check. Schema Registry accepts any new version.

    5. Select the Validation Level – The set of existing versions that a new version is checked against when a compatibility check runs:
      • All – Every existing version.

      • Latest – The latest version only.

      When the Compatibility option is set to None, no compatibility check runs, so the Validation Level option does not apply. The option is disabled and has no effect. For JSON schemas, compatibility rules do not apply, so the Compatibility option is always None and the Validation Level option is always disabled.

    6. Optional: Enter a Description for the schema.
    7. Select or clear the Evolution checkbox to choose whether the schema can have more than one version.
      When the Evolution checkbox is selected, you can add new versions to the schema. When it is cleared, the schema is locked to a single version.
  5. Click Add.
    The schema metadata is created and the Schema Details page of the new schema opens.
  6. In the Schema Text section, provide the schema text of the first version.
    Type or paste the schema text into the editor, or click Add File and select a .json, .avsc, or .txt file. The schema text must be valid JSON.
  7. Optional: Enter a Version Description.
    The field becomes editable after you enter valid schema text.
  8. Click Add Version.
The schema is added to Schema Registry with its first version in the Enabled state. The version appears in the Versions table of the Schema Details page.

Adding schema versions

Evolve existing schemas by adding new versions in Cloudera Surveyor using the Add Version option in the Schema Text section of the Schema Details pages.

As your data changes, you evolve a schema by adding new versions, each holding a revised schema text. In Cloudera Surveyor, you add versions in the Schemas > Schema Details > Schema Text section. You can edit the schema text of an existing version, type or paste new schema text into the editor, or upload it from a .json, .avsc, or .txt file.

When you add a version, Schema Registry checks it against the enabled versions of the schema according to the schema's Compatibility and Validation Level settings. Schema Registry rejects a version that does not pass the check. If the schema text is identical to an existing version, Schema Registry does not create a new version.

  • You must have the necessary permissions to add schema versions in Schema Registry. In Apache Ranger, the required permissions are Read and Create on the Schema Registry Service or Schema Group resource.

  • The schema must have evolution enabled.

  1. In Cloudera Surveyor, click Schemas.
  2. At the top left, next to the page title, click the Instance: selector and select your Schema Registry instance from the list.
  3. Click the Name of a schema to open the Schema Details page for that schema.
  4. In the Schema Text section, provide the schema text for the new version.
    Edit the displayed schema text, type or paste new schema text into the editor, or click Add File and select a .json, .avsc, or .txt file. The editor initially displays the schema text of the latest version. To start from a different version, select it in the Versions table. The schema text must be valid JSON.
  5. Optional: Enter a Version Description.
    The Version Description field becomes editable after you enter valid schema text. It starts empty and does not inherit the description of the displayed version.
  6. Click Add Version.
    To discard the schema text and description you entered, click Discard Changes.
The new version is added to Schema Registry in the Enabled state and appears at the top of the Versions table. If the schema text is identical to an existing version, no version is added. A No Version Added notification is displayed, and the matching existing version is selected in the table.

Comparing schema versions

Compare the schema text of two schema versions in Cloudera Surveyor using the Compare Versions option in the Versions section of the Schema Details pages.

Comparing two versions of a schema shows exactly what changed in the schema text between them. In Cloudera Surveyor, you compare versions using the Schemas > Schema Details > Versions > Compare Versions option, which opens the Compare Schema Versions modal. The modal displays the differences between the schema text of a base version and a target version, together with the description of each version.

You compare versions, for example, when a consumer fails after a schema is updated. Compare the version the consumer was built against with the latest version to find which fields changed.

  • You must have the necessary permissions to read schemas in Schema Registry. In Apache Ranger, the required permission is Read on the Schema Registry Service or Schema Group resource.

  • The schema must have at least two versions.

  1. In Cloudera Surveyor, click Schemas.
  2. At the top left, next to the page title, click the Instance: selector and select your Schema Registry instance from the list.
  3. Click the Name of a schema to open the Schema Details page for that schema.
  4. In the Versions section, click Compare Versions.
  5. In the Compare Schema Versions modal, select a Base Version and a Target Version to compare.
    The modal always opens with the latest version as the Target Version and the version before it as the Base Version, regardless of which version is selected in the Versions table.
  6. Compare the schema text of the two versions.
    Differences are highlighted in red and green. Select Split to display the two versions side by side, or Unified to display the differences in a single view.
  7. Click Close.

Changing the state of a schema version

Enable, disable, or archive schema versions in Cloudera Surveyor using the actions menu of the Versions table on the Schema Details pages.

The state of a schema version determines whether Schema Registry includes the version in compatibility checks when a new version is added. In Cloudera Surveyor, you change the state using the actions menu of a version row on the Schemas > Schema Details > Versions table.

A schema version can have the following states:

  • Enabled – The version is included in compatibility checks. Versions are enabled when you add them. You can disable or archive an enabled version.

  • Disabled – The version is excluded from compatibility checks. Disable a version when it causes new versions to be rejected, for example, a version that was added by mistake. You can enable a disabled version again if it is compatible with the currently enabled versions. You can also archive a disabled version.

  • Archived – The version is permanently excluded from compatibility checks. Archive a version when you never want it to be part of compatibility checks again. You cannot enable or disable an archived version.

  • You must have the necessary permissions to change the state of schema versions in Schema Registry. In Apache Ranger, the required permissions are Read and Update on the Schema Registry Service or Schema Group resource.

  1. In Cloudera Surveyor, click Schemas.
  2. At the top left, next to the page title, click the Instance: selector and select your Schema Registry instance from the list.
  3. Click the Name of a schema to open the Schema Details page for that schema.
  4. Locate the version you want to change in the Versions table.
  5. Click on the right side of the version row and select Enable, Disable, or Archive.
    The menu only lists the actions available for the current state of the version.
  6. If you selected Archive, click Archive in the confirmation dialog.
The state of the version is changed in Schema Registry and is immediately visible in the State column.