Skip to main content

hosts.go

hosts.go - Overview

  1. Overview

This file defines the HostsRepo struct and its associated methods for retrieving and processing host-related metrics. It interacts with a reader and querier to fetch host attributes, values, and lists, and formats the data for presentation.

  1. Detailed Documentation

type HostsRepo struct

  • Purpose: Defines a repository for host-related operations.
  • Fields:
    • reader: An interfaces.Reader for reading metric data.
    • querierV2: An interfaces.Querier for querying metric data.

var pointAttrsToIgnore []string

  • Purpose: Lists attribute keys to ignore when retrieving resource attributes, as they represent data point attributes.

var queryNamesForTopHosts map[string][]string

  • Purpose: Maps column names to a list of query names.

var metricToUseForHostAttributes string

  • Purpose: Specifies the metric name used to retrieve host attributes.

var hostNameAttrKey string

  • Purpose: Specifies the attribute key for the host name.

var agentNameToIgnore string

  • Purpose: Specifies the agent name to ignore.

var hostAttrsToEnrich []string

  • Purpose: Specifies a list of attributes to enrich.

var metricNamesForHosts map[string]string

  • Purpose: Specifies the metric names for the host.

func NewHostsRepo(reader interfaces.Reader, querierV2 interfaces.Querier) *HostsRepo

  • Purpose: Creates a new HostsRepo instance.
  • Parameters:
    • reader: An interfaces.Reader instance.
    • querierV2: An interfaces.Querier instance.
  • Returns: A pointer to the created HostsRepo instance.

func (h *HostsRepo) GetHostAttributeKeys(ctx context.Context, req v3.FilterAttributeKeyRequest) (*v3.FilterAttributeKeyResponse, error)

  • Purpose: Retrieves host attribute keys based on the provided request.
  • Parameters:
    • ctx: The context.Context for the request.
    • req: A v3.FilterAttributeKeyRequest containing filter criteria.
  • Returns: A *v3.FilterAttributeKeyResponse containing the attribute keys, or an error if one occurred.

func (h *HostsRepo) GetHostAttributeValues(ctx context.Context, req v3.FilterAttributeValueRequest) (*v3.FilterAttributeValueResponse, error)

  • Purpose: Retrieves host attribute values based on the provided request.
  • Parameters:
    • ctx: The context.Context for the request.
    • req: A v3.FilterAttributeValueRequest containing filter criteria.
  • Returns: A *v3.FilterAttributeValueResponse containing the attribute values, or an error if one occurred.

func (h *HostsRepo) getActiveHosts(ctx context.Context, req model.HostListRequest) (map[string]bool, error)

  • Purpose: Determines the active status of hosts based on a given request.
  • Parameters:
    • ctx: The context.Context for the request.
    • req: A model.HostListRequest containing the request parameters.
  • Returns: A map of host names to their active status (bool), or an error if one occurred.

func (h *HostsRepo) getMetadataAttributes(ctx context.Context, req model.HostListRequest) (map[string]map[string]string, error)

  • Purpose: Retrieves metadata attributes for hosts based on a given request.
  • Parameters:
    • ctx: The context.Context for the request.
    • req: A model.HostListRequest containing the request parameters.
  • Returns: A nested map containing host names and their attributes, or an error if one occurred.

func (h *HostsRepo) getTopHostGroups(ctx context.Context, req model.HostListRequest, q *v3.QueryRangeParamsV3) ([]map[string]string, []map[string]string, error)

  • Purpose: Retrieves the top host groups based on a given request and query parameters.
  • Parameters:
    • ctx: The context.Context for the request.
    • req: A model.HostListRequest containing the request parameters.
    • q: A *v3.QueryRangeParamsV3 containing query parameters.
  • Returns: Two slices of maps, representing the top host groups and all host groups respectively, and an error if one occurred.

func (h *HostsRepo) DidSendHostMetricsData(ctx context.Context, req model.HostListRequest) (bool, error)

  • Purpose: Checks if any host metrics data has been sent.
  • Parameters:
    • ctx: The context.Context for the request.
    • req: A model.HostListRequest containing the request parameters.
  • Returns: A boolean indicating whether host metrics data has been sent, and an error if one occurred.

func (h *HostsRepo) IsSendingK8SAgentMetrics(ctx context.Context, req model.HostListRequest) ([]string, []string, error)

  • Purpose: Checks if the k8s agent metrics are being sent.
  • Parameters:
    • ctx: The context.Context for the request.
    • req: A model.HostListRequest containing the request parameters.
  • Returns: Two slices of strings, representing cluster names and node names respectively, and an error if one occurred.

func (h *HostsRepo) GetHostList(ctx context.Context, req model.HostListRequest) (model.HostListResponse, error)

  • Purpose: Retrieves a list of hosts based on the provided request.
  • Parameters:
    • ctx: The context.Context for the request.
    • req: A model.HostListRequest containing filter and pagination criteria.
  • Returns: A model.HostListResponse containing the list of hosts, or an error if one occurred.
  1. Code Examples
// Example usage of NewHostsRepo
const hostsRepo = NewHostsRepo(readerInstance, querierV2Instance);
  1. Clarity and Accuracy

The documentation accurately reflects the code's functionality.

Include in Getting Started: NO