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 queryselect
: Lists the fields to retrievewhere
: Defines conditions using regex patterns
Key Components
-
From Clause
- Specifies the resource type to query
- Format:
resource_type[string]
- Example:
service[string]
,deployment[string]
-
Select Clause
- Lists fields to retrieve from matching resources
- Use
["*"]
to select all fields - Supports nested field selection
-
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
- Declarative Syntax: Easy to read and write, following familiar SQL-like patterns
- Pattern Matching: Powerful regex-based filtering capabilities
- Nested Field Support: Ability to query complex, nested configurations
- Flexible Selection: Choose specific fields or entire configurations
- 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