Skip to main content

parser.go

parser.go - Overview

This file defines functions for parsing log filter parameters from HTTP requests and generating SQL where clauses for querying logs.

Detailed Documentation

ParseLogFilterParams(r *http.Request) (*model.LogsFilterParams, error)

  • Purpose: Parses log filter parameters from an HTTP request.
  • Parameters:
    • r: *http.Request - The HTTP request to parse parameters from.
  • Returns:
    • *model.LogsFilterParams: A pointer to a LogsFilterParams struct containing the parsed parameters.
    • error: An error if any of the parameters could not be parsed.

ParseLiveTailFilterParams(r *http.Request) (*model.LogsFilterParams, error)

  • Purpose: Parses live tail filter parameters from an HTTP request.
  • Parameters:
    • r: *http.Request - The HTTP request to parse parameters from.
  • Returns:
    • *model.LogsFilterParams: A pointer to a LogsFilterParams struct containing the parsed parameters.
    • error: An error if any of the parameters could not be parsed.

ParseLogAggregateParams(r *http.Request) (*model.LogsAggregateParams, error)

  • Purpose: Parses log aggregation parameters from an HTTP request.
  • Parameters:
    • r: *http.Request - The HTTP request to parse parameters from.
  • Returns:
    • *model.LogsAggregateParams: A pointer to a LogsAggregateParams struct containing the parsed parameters.
    • error: An error if any of the parameters could not be parsed, including missing timestamp or step parameters.

parseLogQuery(query string) ([]string, error)

  • Purpose: Parses a log query string into a slice of SQL query tokens.
  • Parameters:
    • query: string - The log query string to parse.
  • Returns:
    • []string: A slice of SQL query tokens.
    • error: An error if the query could not be parsed or contains unknown tokens.

parseColumn(s string) (*string, error)

  • Purpose: Parses a column name from a filter string.
  • Parameters:
    • s: string - The filter string to parse.
  • Returns:
    • *string: A pointer to the column name.
    • error: An error if the column name could not be parsed.

arrayToMap(fields []model.Field) map[string]model.Field

  • Purpose: Converts a slice of model.Field to a map with the field name as the key.
  • Parameters:
    • fields: []model.Field - The slice of fields to convert.
  • Returns:
    • map[string]model.Field: A map of fields with the field name as the key.

replaceInterestingFields(allFields *model.GetFieldsResponse, queryTokens []string) ([]string, error)

  • Purpose: Replaces interesting fields in the query tokens with their corresponding SQL column names.
  • Parameters:
    • allFields: *model.GetFieldsResponse - Contains selected and interesting fields.
    • queryTokens: []string - The slice of SQL query tokens to process.
  • Returns:
    • []string: The modified slice of SQL query tokens.
    • error: An error if a field is not found or if there is an error replacing a field.

replaceFieldInToken(queryToken string, selectedFieldsLookup map[string]model.Field, interestingFieldLookup map[string]model.Field) (string, error)

  • Purpose: Replaces a field within a single query token with its corresponding SQL column name.
  • Parameters:
    • queryToken: string - The SQL query token to process.
    • selectedFieldsLookup: map[string]model.Field - A map of selected fields.
    • interestingFieldLookup: map[string]model.Field - A map of interesting fields.
  • Returns:
    • string: The modified SQL query token.
    • error: An error if a field is not found or if there is an error replacing the field.

CheckIfPrevousPaginateAndModifyOrder(params *model.LogsFilterParams) (isPaginatePrevious bool)

  • Purpose: Checks if the query is for the previous page and modifies the order accordingly.
  • Parameters:
    • params: *model.LogsFilterParams - The log filter parameters.
  • Returns:
    • isPaginatePrevious: bool - True if the query is for the previous page, false otherwise.

GenerateSQLWhere(allFields *model.GetFieldsResponse, params *model.LogsFilterParams) (string, int, error)

  • Purpose: Generates an SQL where clause based on the provided filter parameters.
  • Parameters:
    • allFields: *model.GetFieldsResponse - Contains all selected and interesting fields.
    • params: *model.LogsFilterParams - The log filter parameters.
  • Returns:
    • string: The generated SQL where clause.
    • int: Number of tokens.
    • error: An error if there was an issue generating the where clause.

Code Examples

N/A

Include in Getting Started: NO