Skip to main content

jobs.go

jobs.go - Overview

  1. Overview

This file defines the JobsRepo struct and its methods for retrieving and processing Kubernetes Job-related metrics. It interacts with SigNoz's query service components to fetch metric data, enrich it with metadata, and format it for presentation.

  1. Detailed Documentation

Constants

  • metricToUseForJobs: The metric used to retrieve job list. Its value is k8s_job_desired_successful_pods.
  • k8sJobNameAttrKey: Attribute key for K8s Job Name. Its value is k8s_job_name.
  • metricNamesForJobs: A map of metric names used for jobs, mapping descriptive names to actual metric names.
    • desired_successful_pods: k8s_job_desired_successful_pods
    • active_pods: k8s_job_active_pods
    • failed_pods: k8s_job_failed_pods
    • successful_pods: k8s_job_successful_pods
  • jobAttrsToEnrich: A list of attributes to enrich job data with, including k8s_job_name, k8s_namespace_name, and k8s_cluster_name.
  • queryNamesForJobs: A map associating descriptive names (e.g., "cpu", "memory") with the builder queries used to fetch the corresponding metrics ("A", "B", "C", etc.).
  • builderQueriesForJobs: A map containing v3.BuilderQuery definitions for different job-related metrics (desired, active, failed, successful pods).
  • jobQueryNames: A list of query names used for jobs.

JobsRepo

type JobsRepo struct {
reader interfaces.Reader
querierV2 interfaces.Querier
}
  • Purpose: JobsRepo provides methods to query and process Kubernetes Jobs data.
  • Fields:
    • reader: An interfaces.Reader instance used for fetching metric attribute keys and values, and list results.
    • querierV2: An interfaces.Querier instance used for executing queries against the metrics datasource.

NewJobsRepo

func NewJobsRepo(reader interfaces.Reader, querierV2 interfaces.Querier) *JobsRepo {
return &JobsRepo{reader: reader, querierV2: querierV2}
}
  • Purpose: Creates a new JobsRepo instance.
  • Parameters:
    • reader: An interfaces.Reader instance.
    • querierV2: An interfaces.Querier instance.
  • Returns: A pointer to a new JobsRepo instance.

GetJobAttributeKeys

func (d *JobsRepo) GetJobAttributeKeys(ctx context.Context, req v3.FilterAttributeKeyRequest) (*v3.FilterAttributeKeyResponse, error) {
  • Purpose: Retrieves attribute keys associated with Jobs.
  • Parameters:
    • ctx: The context.Context for cancellation and deadlines.
    • req: A v3.FilterAttributeKeyRequest specifying the request parameters, including data source, aggregate attribute, and limit.
  • Returns:
    • *v3.FilterAttributeKeyResponse: A response containing the attribute keys.
    • error: An error if the retrieval fails.

GetJobAttributeValues

func (d *JobsRepo) GetJobAttributeValues(ctx context.Context, req v3.FilterAttributeValueRequest) (*v3.FilterAttributeValueResponse, error) {
  • Purpose: Retrieves attribute values associated with Jobs.
  • Parameters:
    • ctx: The context.Context for cancellation and deadlines.
    • req: A v3.FilterAttributeValueRequest specifying the request parameters, including data source, aggregate attribute, and limit.
  • Returns:
    • *v3.FilterAttributeValueResponse: A response containing the attribute values.
    • error: An error if the retrieval fails.

getMetadataAttributes

func (d *JobsRepo) getMetadataAttributes(ctx context.Context, req model.JobListRequest) (map[string]map[string]string, error) {
  • Purpose: Retrieves metadata attributes for Jobs based on the group by keys specified in the request.
  • Parameters:
    • ctx: The context.Context for cancellation and deadlines.
    • req: A model.JobListRequest containing the request parameters, including group by keys, start, and end times.
  • Returns:
    • map[string]map[string]string: A map of job names to a map of attribute keys to attribute values.
    • error: An error if the retrieval fails.

getTopJobGroups

func (d *JobsRepo) getTopJobGroups(ctx context.Context, req model.JobListRequest, q *v3.QueryRangeParamsV3) ([]map[string]string, []map[string]string, error) {
  • Purpose: Retrieves the top job groups based on the specified order and limit.
  • Parameters:
    • ctx: The context.Context for cancellation and deadlines.
    • req: A model.JobListRequest containing the request parameters, including order by, offset, and limit.
    • q: A pointer to v3.QueryRangeParamsV3 containing query parameters.
  • Returns:
    • []map[string]string: A slice of maps, where each map represents a top job group's labels.
    • []map[string]string: A slice of maps, where each map represents all job groups' labels.
    • error: An error if the retrieval fails.

GetJobList

func (d *JobsRepo) GetJobList(ctx context.Context, req model.JobListRequest) (model.JobListResponse, error) {
  • Purpose: Retrieves a list of Jobs based on the provided request parameters.
  • Parameters:
    • ctx: The context.Context for cancellation and deadlines.
    • req: A model.JobListRequest containing the request parameters, including filters, group by keys, order by, offset, and limit.
  • Returns:
    • model.JobListResponse: A response containing the list of Jobs and total count.
    • error: An error if the retrieval fails.
  1. Code Examples

None

  1. Clarity and Accuracy

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

  1. Markdown & MDX Perfection

The markdown syntax is valid and well-formatted.

  1. Edge Cases To Avoid Breaking MDX

No MDX errors are present.

  1. Getting Started Relevance

Include in Getting Started: NO