Queries
Views use a powerful query system to aggregate and transform data from multiple sources. You can query config items, changes, and metrics to populate your views.
Query Types
Config Queries
Query config items from your catalog:
deployments.yamlapiVersion: mission-control.flanksource.com/v1
kind: View
metadata:
name: deployments
namespace: mc
spec:
display:
title: Helm Releases
icon: rocket
sidebar: true
panels:
- name: Health
description: Helm Releases grouped by health
type: piechart
piechart:
showLabels: true
colors:
healthy: "#28C19B"
unhealthy: "#F04E6E"
query: SELECT COUNT(*) AS count, health FROM helm_releases GROUP BY health
- name: Status
description: Helm Releases grouped by status
type: piechart
piechart:
colors:
InstallSucceeded: "#28C19B"
RollbackSucceeded: "#F4B23C"
UpgradeFailed: "#F04E6E"
UpgradeSucceeded: "#5965F2"
query: SELECT COUNT(*) AS count, status FROM helm_releases GROUP BY status
columns:
- name: id
type: string
description: The id of the deployment.
primaryKey: true
hidden: true
- name: url
type: url
for: application
- name: application
type: string
description: The application name.
- name: namespace
type: string
description: The namespace name.
- name: chart
type: string
description: The chart name.
- name: version
type: string
description: The version of the deployment.
- name: status
type: status
description: The status of the deployment.
- name: health
type: health
description: The health of the deployment.
- name: lastUpdated
type: datetime
description: The last updated time.
queries:
helm_releases:
configs:
types:
- Kubernetes::HelmRelease
mapping:
application: row.name
namespace: row.tags.namespace
chart: row.config.status.history[0].chartName
version: row.config.status.history[0].chartVersion
lastUpdated: row.updated_at
url: >
"/catalog/" + row.id
Change Queries
Query configuration changes and audit data:
backups.yamlapiVersion: mission-control.flanksource.com/v1
kind: View
metadata:
name: backups
namespace: mc
spec:
display:
title: Backups
icon: database
sidebar: true
cache:
maxAge: 1h
minAge: 1m
refreshTimeout: 10s
columns:
- name: id
type: string
description: The id of the database.
primaryKey: true
hidden: true
- name: database
type: string
description: The name of the helm release.
- name: date
type: datetime
description: The namespace name.
- name: status
type: status
description: The status of the backup.
- name: source
type: string
description: The source of the backup.
queries:
backups:
changes:
search: change_type=BackupSuccessful
limit: 10
mapping:
database: row.name
date: row.created_at
status: row.details.status
Metric Queries
Query time-series data from Prometheus and other sources. Metric queries are not yet implemented in the current version, but the structure would be:
resource-usage.yamlapiVersion: mission-control.flanksource.com/v1
kind: View
metadata:
name: resource-usage
namespace: mc
spec:
queries:
cpu:
prometheus:
url: https://prometheus.demo.prometheus.io
query: container_cpu_usage_seconds_total{id="/", job="cadvisor"}
memory:
prometheus:
url: https://prometheus.demo.prometheus.io
query: container_memory_working_set_bytes{id="/", job="cadvisor"}
panels:
- name: cpu
type: number
query: SELECT SUM(value) as value FROM cpu
number:
unit: seconds
precision: 2
- name: memory
type: number
query: SELECT SUM(value) as value FROM memory
number:
unit: bytes
Multi-Source Queries
Views can combine data from different sources and use SQL queries in panels to aggregate and analyze the data:
pipelines.yamlapiVersion: mission-control.flanksource.com/v1
kind: View
metadata:
name: pipelines
namespace: mc
spec:
display:
title: Pipelines
icon: github
sidebar: true
cache:
maxAge: 30m
minAge: 1m
refreshTimeout: 30s
panels:
- name: Repository
type: table
query: SELECT COUNT(*) AS value, details->'repository'->>'full_name' as repository FROM workflows GROUP BY details->'repository'->>'full_name'
- name: Average Duration
description: Create Release average duration
type: number
number:
unit: seconds
query: >
SELECT AVG(details->'duration') AS value, details->'repository'->>'full_name' as label
FROM workflows GROUP BY details->'repository'->>'full_name'
columns:
- name: id
type: string
description: The id of the pipeline.
primaryKey: true
hidden: true
- name: name
type: string
description: The name of the pipeline.
- name: repository
type: string
description: The repository of the pipeline.
- name: lastRun
type: datetime
description: The namespace name.
- name: lastRunBy
type: string
description: The chart name.
- name: duration
type: duration
description: The duration of the pipeline.
- name: status
type: status
description: The status of the pipeline.
queries:
workflows:
changes:
limit: 10
search: change_type=GitHubActionRun* @order=-created_at
types:
- GitHubAction::Workflow
mapping:
lastRun: row.details.created_at
lastRunBy: row.details.triggering_actor.login
repository: row.details.repository.full_name
status: >
has(row.details.conclusion) ? row.details.conclusion : 'pending'
duration: timestamp(row.details.updated_at) - timestamp(row.details.run_started_at)
This example shows:
- Multiple query sources: Combining workflow runs from changes
- Panel queries: Using SQL to aggregate repository data
- CEL expressions: Complex duration calculations in mappings
- Data aggregation:
COUNT
(count) andAVG
(average) functions in panel queries