Skip to main content

workload_query.go

workload_query.go - Overview

This file defines the query structure for retrieving workload-related metrics, specifically designed for displaying data in a table format. It defines metric names and a complex query (WorkloadTableListQuery) to fetch CPU, memory, and restart metrics for workloads.

Detailed Documentation

metricNamesForWorkloads

  • Purpose: Defines a map of user-friendly metric names (e.g., "cpu", "memory") to their corresponding metric names used in the data source (e.g., "k8s_pod_cpu_utilization").
  • Type: map[string]string
  • Example:
{
"cpu": "k8s_pod_cpu_utilization",
"memory": "k8s_pod_memory_usage",
"restarts": "k8s_container_restarts"
}

WorkloadTableListQuery

  • Purpose: Defines a complex query structure (v3.QueryRangeParamsV3) to retrieve workload metrics for displaying in a table. It includes definitions for several builder queries, each responsible for fetching a specific metric (CPU utilization, memory usage, restarts).
  • Type: v3.QueryRangeParamsV3
  • Fields:
    • CompositeQuery: *v3.CompositeQuery - Defines a composite query composed of builder queries.
      • BuilderQueries: map[string]*v3.BuilderQuery - A map of builder queries, where the key is a query name (e.g., "A", "B", "C", "D", "E", "F", "G"). Each BuilderQuery defines how to fetch a specific metric.
        • QueryName: string - A unique identifier for the query (e.g., "A").
        • DataSource: v3.DataSource - Specifies the data source (e.g., v3.DataSourceMetrics).
        • AggregateAttribute: v3.AttributeKey - Defines the attribute to aggregate. Includes the attribute Key (metric name from metricNamesForWorkloads) and DataType (e.g., v3.AttributeKeyDataTypeFloat64).
        • Temporality: v3.Temporality - Specifies the temporality of the metric (e.g., v3.Unspecified).
        • Filters: *v3.FilterSet - Defines filters to apply to the query.
        • GroupBy: []v3.AttributeKey - Defines attributes to group by.
        • Expression: string - An expression representing the query (e.g., "A").
        • ReduceTo: v3.ReduceToOperator - Defines how to reduce the data (e.g., v3.ReduceToOperatorAvg, v3.ReduceToOperatorSum).
        • TimeAggregation: v3.TimeAggregation - Specifies the time aggregation method (e.g., v3.TimeAggregationAvg, v3.TimeAggregationAnyLast).
        • SpaceAggregation: v3.SpaceAggregation - Specifies the space aggregation method (e.g., v3.SpaceAggregationSum, v3.SpaceAggregationMax, v3.SpaceAggregationAvg).
        • Functions: []v3.Function - Defines functions to apply to the data (e.g., v3.FunctionNameRunningDiff for restarts).
        • Disabled: bool - Indicates whether the query is disabled.
      • PanelType: v3.PanelType - Specifies the panel type (e.g., v3.PanelTypeTable).
      • QueryType: v3.QueryType - Specifies the query type (e.g., v3.QueryTypeBuilder).
    • Version: string - The version of the query structure (e.g., "v4").
    • FormatForWeb: bool - Indicates whether the data should be formatted for web display.

Code Examples

None

Clarity and Accuracy

The documentation is based on the code provided and aims to be accurate.

Include in Getting Started: NO