Skip to main content

deployments.go

deployments.go - Overview

  1. Overview This file defines the DeploymentsRepo struct and its methods for retrieving and processing deployment-related metrics and metadata. It includes functions to get deployment attribute keys and values, fetch metadata attributes, retrieve top deployment groups, and construct a deployment list.

  2. Detailed Documentation

metricToUseForDeployments

  • Purpose: Specifies the metric to be used for deployments.
  • Type: string
  • Value: "k8s_pod_cpu_utilization"

k8sDeploymentNameAttrKey

  • Purpose: Specifies the attribute key for the Kubernetes deployment name.
  • Type: string
  • Value: "k8s_deployment_name"

metricNamesForDeployments

  • Purpose: Maps logical names (e.g., "desired_pods") to actual metric names.
  • Type: map[string]string
  • Example:
{
"desired_pods": "k8s_deployment_desired",
"available_pods": "k8s_deployment_available"
}

deploymentAttrsToEnrich

  • Purpose: Lists attributes to enrich deployment data.
  • Type: []string
  • Example:
[
"k8s_deployment_name",
"k8s_namespace_name",
"k8s_cluster_name"
]

queryNamesForDeployments

  • Purpose: Maps logical names (e.g., "cpu") to builder query names.
  • 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"]
}

builderQueriesForDeployments

  • Purpose: Defines builder queries for specific metrics related to deployments.
  • Type: map[string]*v3.BuilderQuery
  • Includes queries for "desired_pods" ("H") and "available_pods" ("I"). Each query specifies the data source, aggregate attribute, filters, group by attributes, expression, reduce to operator, time aggregation, space aggregation, and whether it is disabled.
  • Example:
{
"H": {
QueryName: "H",
DataSource: v3.DataSourceMetrics,
AggregateAttribute: {
Key: metricNamesForDeployments["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,
},
//...
}

deploymentQueryNames

  • Purpose: Lists the query names used for deployments.
  • Type: []string
  • Value: {"A", "B", "C", "D", "E", "F", "G", "H", "I"}

DeploymentsRepo

  • Purpose: Manages deployment-related data retrieval.
  • Fields:
    • reader: An interfaces.Reader for reading data.
    • querierV2: An interfaces.Querier for querying data.

NewDeploymentsRepo

  • Purpose: Creates a new DeploymentsRepo instance.
  • Parameters:
    • reader: An interfaces.Reader instance.
    • querierV2: An interfaces.Querier instance.
  • Returns: A pointer to the newly created DeploymentsRepo.
  • Return Type: *DeploymentsRepo

(*DeploymentsRepo) GetDeploymentAttributeKeys

  • Purpose: Retrieves attribute keys associated with deployments.
  • Parameters:
    • ctx: A context.Context for managing the request context.
    • req: A v3.FilterAttributeKeyRequest containing the request parameters.
  • Returns:
    • *v3.FilterAttributeKeyResponse: The response containing the attribute keys.
    • error: An error, if any.

(*DeploymentsRepo) GetDeploymentAttributeValues

  • Purpose: Retrieves attribute values for deployments.
  • Parameters:
    • ctx: A context.Context for managing the request context.
    • req: A v3.FilterAttributeValueRequest containing the request parameters.
  • Returns:
    • *v3.FilterAttributeValueResponse: The response containing the attribute values.
    • error: An error, if any.

(*DeploymentsRepo) getMetadataAttributes

  • Purpose: Retrieves metadata attributes for deployments based on the provided request.
  • Parameters:
    • ctx: A context.Context for managing the request context.
    • req: A model.DeploymentListRequest containing the request parameters including group by attributes.
  • Returns:
    • map[string]map[string]string: A map of deployment names to a map of attribute keys to their values.
    • error: An error, if any.

(*DeploymentsRepo) getTopDeploymentGroups

  • Purpose: Retrieves the top deployment groups based on the provided request and query parameters.
  • Parameters:
    • ctx: A context.Context for managing the request context.
    • req: A model.DeploymentListRequest containing the request parameters.
    • q: A *v3.QueryRangeParamsV3 containing query parameters.
  • Returns:
    • []map[string]string: A slice of maps representing the top deployment groups. Each map contains attributes and their values.
    • []map[string]string: A slice of maps representing all deployment groups.
    • error: An error, if any.

(*DeploymentsRepo) GetDeploymentList

  • Purpose: Retrieves a list of deployments based on the provided request.
  • Parameters:
    • ctx: A context.Context for managing the request context.
    • req: A model.DeploymentListRequest containing the request parameters, such as filters, group by attributes, ordering, and limits.
  • Returns:
    • model.DeploymentListResponse: The response containing the list of deployments and related information.
    • error: An error, if any.
  1. Code Examples N/A

  2. Clarity and Accuracy The documentation is derived directly from the code and aims to provide a clear and accurate description of each function and its parameters.

  3. Markdown & MDX Perfection The markdown syntax is correct, with proper headings, lists, and fenced code blocks. Special characters are escaped where necessary to avoid breaking MDX.

  4. Edge Cases To Avoid Breaking MDX All potential MDX breaking cases have been avoided by using correct markdown syntax and escaping special characters.

  5. Getting Started Relevance Include in Getting Started: NO