Skip to main content

Configuration Query Language (CQL) Overview

Feature status: Experimental

Purpose

Configuration Query Language (CQL) is a specialized query language designed for infrastructure configuration analysis. The core idea is to treat configuration as data and enable powerful query capabilities, that can shorten the time to understand specific configurations and environments, and reduce toil in various scenarios like debugging, testing, validation, code-review, impact analysis, etc.

It enables users to:

  • Query and analyze infrastructure configurations
  • Extract specific configuration patterns
  • Validate configuration compliance
  • Identify potential issues or misconfigurations

Basic Syntax

CQL follows a SQL-like syntax with three main components:

  • from: Specifies the type of resource to query
  • select: Lists the fields to retrieve
  • where: Defines conditions using regex patterns

Key Components

  1. From Clause

    • Specifies the resource type to query
    • Format: resource_type[string]
    • Example: service[string], deployment[string]
  2. Select Clause

    • Lists fields to retrieve from matching resources
    • Use ["*"] to select all fields
    • Supports nested field selection
  3. Where Clause

    • Defines conditions using regex patterns
    • Supports nested field matching
    • Uses standard regex syntax for pattern matching

Usage Examples

Basic Query

from: "service[string]"
select: ["name", "namespace"]
where: {
"namespace": "production"
}

Complex Pattern Matching

from: "service[string]"
select: ["*"]
where: {
"name": "^api-.*",
"namespace": "prod.*"
}

Nested Field Query

from: "service[string]"
select: ["metadata.labels"]
where: {
"metadata.labels.environment": "production",
"metadata.labels.team": "platform"
}

Benefits

  1. Declarative Syntax: Easy to read and write, following familiar SQL-like patterns
  2. Pattern Matching: Powerful regex-based filtering capabilities
  3. Nested Field Support: Ability to query complex, nested configurations
  4. Flexible Selection: Choose specific fields or entire configurations
  5. Infrastructure Analysis: Effective tool for configuration analysis and validation

Common Use Cases

  • Change impact analysis
  • Configuration validation
  • Static and dynamic dependency tracking
  • Debugging and troubleshooting
  • Pre-deployment checks
  • Testing and validation of configurations