Skip to main content

statefulsets.go

statefulsets.go - Overview

  1. Overview This file defines the StatefulSetsRepo struct and its associated methods for retrieving and processing data related to Kubernetes StatefulSets. It includes functionalities for fetching attribute keys and values, retrieving metadata, and generating a list of StatefulSets with relevant metrics.

  2. Detailed Documentation

metricToUseForStatefulSets

  • Purpose: Defines the metric used for querying StatefulSet data.
  • Type: string
  • Value: "k8s_pod_cpu_utilization"

k8sStatefulSetNameAttrKey

  • Purpose: Defines the attribute key for the StatefulSet name.
  • Type: string
  • Value: "k8s_statefulset_name"

metricNamesForStatefulSets

  • Purpose: Maps descriptive names to actual metric names for StatefulSets.
  • Type: map[string]string
  • Example:
{
"desired_pods": "k8s_statefulset_desired_pods",
"available_pods": "k8s_statefulset_current_pods",
}

statefulSetAttrsToEnrich

  • Purpose: Defines a list of attributes to enrich StatefulSet data.
  • Type: []string
  • Example:
[
"k8s_statefulset_name",
"k8s_namespace_name",
"k8s_cluster_name",
]

queryNamesForStatefulSets

  • Purpose: Maps descriptive names to query names used in BuilderQueries.
  • Type: map[string][]string
  • Example:
{
"cpu": ["A"],
"cpu_request": ["B", "A"],
"cpu_limit": ["C", "A"],
"memory": ["D"],
"memory_request": ["E", "D"],
"memory_limit": ["F", "D"],
"restarts": ["G", "A"],
"desired_pods": ["H"],
"available_pods": ["I"],
}

builderQueriesForStatefulSets

  • Purpose: Defines BuilderQuery configurations for specific metrics related to StatefulSets.
  • Type: map[string]*v3.BuilderQuery
  • Example:
{
"H": {
QueryName: "H",
DataSource: v3.DataSourceMetrics,
AggregateAttribute: v3.AttributeKey{
Key: metricNamesForStatefulSets["desired_pods"],
DataType: v3.AttributeKeyDataTypeFloat64,
},
Temporality: v3.Unspecified,
Filters: &v3.FilterSet{
Operator: "AND",
Items: []v3.FilterItem{},
},
GroupBy: []v3.AttributeKey{},
Expression: "H",
ReduceTo: v3.ReduceToOperatorLast,
TimeAggregation: v3.TimeAggregationAnyLast,
SpaceAggregation: v3.SpaceAggregationSum,
Disabled: false,
},
// ... other builder queries
}

statefulSetQueryNames

  • Purpose: Defines a list of query names used for StatefulSets.
  • Type: []string
  • Example:
["A", "B", "C", "D", "E", "F", "G", "H", "I"]

StatefulSetsRepo

  • Purpose: Represents a repository for retrieving and processing StatefulSet data.
  • Fields:
    • reader: An interfaces.Reader used to read data.
    • querierV2: An interfaces.Querier used to query data.

NewStatefulSetsRepo

  • Purpose: Creates a new StatefulSetsRepo instance.
  • Parameters:
    • reader: An interfaces.Reader instance.
    • querierV2: An interfaces.Querier instance.
  • Returns: A pointer to a new StatefulSetsRepo instance.
  • Example:
repo := NewStatefulSetsRepo(myReader, myQuerier)

(*StatefulSetsRepo) GetStatefulSetAttributeKeys

  • Purpose: Retrieves attribute keys for StatefulSets based on the provided request.
  • Parameters:
    • ctx: The context.Context for the request.
    • req: A v3.FilterAttributeKeyRequest containing the request parameters.
  • Returns:
    • *v3.FilterAttributeKeyResponse: A response containing the attribute keys.
    • error: An error if the operation fails.

(*StatefulSetsRepo) GetStatefulSetAttributeValues

  • Purpose: Retrieves attribute values for StatefulSets based on the provided request.
  • Parameters:
    • ctx: The context.Context for the request.
    • req: A v3.FilterAttributeValueRequest containing the request parameters.
  • Returns:
    • *v3.FilterAttributeValueResponse: A response containing the attribute values.
    • error: An error if the operation fails.

(*StatefulSetsRepo) getMetadataAttributes

  • Purpose: Retrieves metadata attributes for StatefulSets based on the provided request.
  • Parameters:
    • ctx: The context.Context for the request.
    • req: A model.StatefulSetListRequest containing the request parameters.
  • Returns:
    • map[string]map[string]string: A map of StatefulSet names to their metadata attributes.
    • error: An error if the operation fails.

(*StatefulSetsRepo) getTopStatefulSetGroups

  • Purpose: Retrieves the top StatefulSet groups based on the provided request and query parameters.
  • Parameters:
    • ctx: The context.Context for the request.
    • req: A model.StatefulSetListRequest containing the request parameters.
    • q: A *v3.QueryRangeParamsV3 containing query parameters.
  • Returns:
    • []map[string]string: A list of top StatefulSet groups.
    • []map[string]string: A list of all StatefulSet groups.
    • error: An error if the operation fails.

(*StatefulSetsRepo) GetStatefulSetList

  • Purpose: Retrieves a list of StatefulSets based on the provided request.
  • Parameters:
    • ctx: The context.Context for the request.
    • req: A model.StatefulSetListRequest containing the request parameters.
  • Returns:
    • model.StatefulSetListResponse: A response containing the list of StatefulSets.
    • error: An error if the operation fails.
  1. Code Examples N/A

  2. Clarity and Accuracy The documentation accurately reflects the code's functionality based on the provided context.

Include in Getting Started: NO