DocumentationAPIConfiguration Validation

Ensuring that infrastructure configurations are correct is crucial for successful deployments. Lack of proper validation can lead to errors that delay deployments and add frustration for developers and DevOps engineers. To prevent such issues, ProjectPlanton utilizes inline field validations using Proto Options, allowing for rigorous and consistent validation logic.

Lack of Field Validations

  • Manual Validation: Without inline validation, developers are often left to manually validate fields, increasing the risk of human error.
  • Inconsistent Standards: Different developers may validate configurations differently, leading to inconsistencies in infrastructure deployment.
  • Deployment Failures: Lack of validation leads to configuration issues being caught late in the deployment process, resulting in failed deployments and increased troubleshooting efforts.

Inline Validations

  • Automatic Validation at the Source: By embedding validation rules directly into the protobuf definitions, every field in the YAML manifest is automatically validated before proceeding, minimizing the chance of errors.
  • Consistent Validation Logic: Since validation is defined at the protobuf level, every field is validated uniformly across deployments, ensuring that all developers follow the same standards.
  • Reduced Human Error: Proto Validate project enables developers to define validation rules declaratively, reducing the risk of manual errors and ensuring correctness before deployment.

Example

The KafkaTopic message below includes multiple validation rules for the name field, such as enforcing required presence, minimum and maximum length constraints, and specific character patterns using custom validation expressions.

message KafkaTopic {
  string name = 1 [
    (buf.validate.field).required = true,
    (buf.validate.field).string.min_len = 1,
    (buf.validate.field).string.max_len = 249,
    (buf.validate.field).cel = {
      id: "topic.name",
      message: "Should start with an alphanumeric character",
      expression: "this.matches('^[a-zA-Z0-9].*$')"
    },
    (buf.validate.field).cel = {
      id: "topic.name",
      message: "Only alphanumeric and ('.', '_' and '-') characters are allowed",
      expression: "this.matches('^[a-zA-Z0-9._-]+$')"
    },
    (buf.validate.field).cel = {
      id: "topic.name",
      message: "Must not contain '..'",
      expression: "!this.contains('..')"
    },
    (buf.validate.field).cel = {
      id: "topic.name",
      message: "Must not contain non-ASCII characters",
      expression: "this.matches('^[\x00-\x7F]+$')"
    },
    (buf.validate.field).cel = {
      id: "topic.name",
      message: "Should end with an alphanumeric character",
      expression: "this.matches('[a-zA-Z0-9]$')"
    }
  ];
 
  int32 partitions = 2;
  int32 replicas = 3;
  map<string, string> config = 4;
}

The configuration can then be validated in any language using the language specific sdk available for bufbuild/protovalidate. The project-planton cli has a built-in command validate that uses golang sdk.

project-planton validate <configuration-manifest.yaml>

Benefits for Users

  • Inline, Declarative Validation: Every field in the YAML manifest is validated based on rules defined in protobuf, providing a consistent and reliable validation mechanism.
  • Catch Errors Early: Issues are caught before deployment, saving time and resources by reducing troubleshooting efforts.
  • Automated & Consistent: The validation logic is embedded directly within the API contracts, automating the validation process and ensuring consistency across deployments.

How It Works

  • Proto Definitions: Validation rules are defined at the protobuf level using Proto Options, specifying requirements for each field.
  • Protovalidate SDK: The validation rules are enforced using the Protovalidate SDK during infrastructure deployment, ensuring compliance with the specified rules.
  • Consistent Enforcement: The validation logic is enforced uniformly, preventing configuration errors from propagating to deployment environments.

Inline field validations in ProjectPlanton ensure that infrastructure configurations are accurate and consistent. By embedding validation logic directly in the protobuf definitions, developers can avoid common configuration errors, reduce manual work, and confidently deploy infrastructure.