Skip to main content

model.go

model.go - Overview

  1. Overview This file defines the data models and database interaction logic for dashboards within the SigNoz query service. It includes functions for creating, retrieving, updating, deleting, and locking/unlocking dashboards. It also provides functions for extracting information from dashboard data for analytics and metric association purposes.

  2. Detailed Documentation

Variables

  • store: An unexported global variable of type sqlstore.SQLStore used to interact with the database.
  • instanceEQRE, nodeEQRE, jobEQRE, instanceRERE, nodeRERE, jobRERE: Regular expressions used for mapping job, instance from grafana.

Function: InitDB

  • Purpose: Initializes the database connection and sets the dashboards info callback for telemetry.
  • Parameters:
    • sqlStore (sqlstore.SQLStore): The SQLStore instance to use for database interactions.
  • Returns:
    • error: An error if initialization fails, nil otherwise.

Function: CreateDashboard

  • Purpose: Creates a new dashboard in the database.
  • Parameters:
    • ctx (context.Context): The context for the operation.
    • orgID (string): The organization ID.
    • email (string): The email of the user creating the dashboard.
    • data (map[string]interface{}): The dashboard data.
  • Returns:
    • *types.Dashboard: The created dashboard, or nil on error.
    • *model.ApiError: An API error if the creation fails, nil otherwise.

Function: GetDashboards

  • Purpose: Retrieves all dashboards for a given organization ID.
  • Parameters:
    • ctx (context.Context): The context for the operation.
    • orgID (string): The organization ID.
  • Returns:
    • []types.Dashboard: A slice of dashboards, or nil on error.
    • *model.ApiError: An API error if the retrieval fails, nil otherwise.

Function: DeleteDashboard

  • Purpose: Deletes a dashboard based on organization ID and UUID.
  • Parameters:
    • ctx (context.Context): The context for the operation.
    • orgID (string): The organization ID.
    • uuid (string): The UUID of the dashboard to delete.
  • Returns:
    • *model.ApiError: An API error if the deletion fails, nil otherwise.

Function: GetDashboard

  • Purpose: Retrieves a single dashboard based on organization ID and UUID.
  • Parameters:
    • ctx (context.Context): The context for the operation.
    • orgID (string): The organization ID.
    • uuid (string): The UUID of the dashboard to retrieve.
  • Returns:
    • *types.Dashboard: The retrieved dashboard, or nil if not found.
    • *model.ApiError: An API error if the retrieval fails, nil otherwise.

Function: UpdateDashboard

  • Purpose: Updates an existing dashboard.
  • Parameters:
    • ctx (context.Context): The context for the operation.
    • orgID (string): The organization ID.
    • userEmail (string): The email of the user updating the dashboard.
    • uuid (string): The UUID of the dashboard to update.
    • data (map[string]interface{}): The updated dashboard data.
  • Returns:
    • *types.Dashboard: The updated dashboard, or nil on error.
    • *model.ApiError: An API error if the update fails, nil otherwise.

Function: LockUnlockDashboard

  • Purpose: Locks or unlocks a dashboard to prevent modifications.
  • Parameters:
    • ctx (context.Context): The context for the operation.
    • orgID (string): The organization ID.
    • uuid (string): The UUID of the dashboard to lock/unlock.
    • lock (bool): A boolean indicating whether to lock (true) or unlock (false) the dashboard.
  • Returns:
    • *model.ApiError: An API error if the operation fails, nil otherwise.

Function: IsPostDataSane

  • Purpose: Checks if the provided dashboard data contains a title.
  • Parameters:
    • data (*map[string]interface{}): A pointer to the dashboard data map.
  • Returns:
    • error: An error if the title is missing, nil otherwise.

Function: getWidgetIds

  • Purpose: Extracts widget IDs from the dashboard data.
  • Parameters:
    • data (map[string]interface{}): The dashboard data.
  • Returns:
    • []string: A slice of widget IDs.

Function: getIdDifference

  • Purpose: Finds the difference between two slices of IDs (existing IDs and new IDs).
  • Parameters:
    • existingIds ([]string): A slice of existing IDs.
    • newIds ([]string): A slice of new IDs.
  • Returns:
    • []string: A slice containing the IDs that are in existingIds but not in newIds.

Function: GetDashboardsInfo

  • Purpose: Retrieves analytics data for dashboards.
  • Parameters:
    • ctx (context.Context): The context for the operation.
  • Returns:
    • *model.DashboardsInfo: A pointer to a model.DashboardsInfo struct containing the analytics data.
    • error: An error, if any.

Function: isDashboardWithTSV2

  • Purpose: Checks if a dashboard contains time_series_v2 queries.
  • Parameters:
    • data (map[string]interface{}): The dashboard data.
  • Returns:
    • bool: True if the dashboard contains time_series_v2 queries, false otherwise.

Function: isDashboardWithTagAttrs

  • Purpose: Checks if a dashboard contains span_attributes or tag_attributes queries.
  • Parameters:
    • data (map[string]interface{}): The dashboard data.
  • Returns:
    • bool: True if the dashboard contains span_attributes or tag_attributes queries, false otherwise.

Function: isDashboardWithLogsClickhouseQuery

  • Purpose: Checks if a dashboard contains logs clickhouse queries.
  • Parameters:
    • data (map[string]interface{}): The dashboard data.
  • Returns:
    • bool: True if the dashboard contains logs clickhouse queries, false otherwise.

Function: isDashboardWithTracesClickhouseQuery

  • Purpose: Checks if a dashboard contains traces clickhouse queries.
  • Parameters:
    • data (map[string]interface{}): The dashboard data.
  • Returns:
    • bool: True if the dashboard contains traces clickhouse queries, false otherwise.

Function: isDashboardWithPanelAndName

  • Purpose: Checks if a dashboard has a name and at least one panel.
  • Parameters:
    • data (map[string]interface{}): The dashboard data.
  • Returns:
    • bool: True if the dashboard has a name and at least one panel, false otherwise.

Function: extractDashboardName

  • Purpose: Extracts the dashboard name from the dashboard data.
  • Parameters:
    • data (map[string]interface{}): The dashboard data.
  • Returns:
    • string: The dashboard name, or an empty string if not found.

Function: checkLogPanelAttrContains

  • Purpose: Checks log panels for attribute contains operations, excluding the body attribute.
  • Parameters:
    • data (map[string]interface{}): The dashboard data.
  • Returns:
    • int: The number of log panels using attribute contains operations (excluding body).

Function: countPanelsInDashboard

  • Purpose: Counts the number of logs, traces, and metrics panels in a dashboard and also checks for clickhouse queries.
  • Parameters:
    • inputData (map[string]interface{}): The dashboard data.
  • Returns:
    • model.DashboardsInfo: A model.DashboardsInfo struct containing the counts of different panel types.

Function: GetDashboardsWithMetricNames

  • Purpose: Retrieves dashboards that use specific metric names.
  • Parameters:
    • ctx (context.Context): The context for the operation.
    • orgID (string): The organization ID.
    • metricNames ([]string): A slice of metric names to search for.
  • Returns:
    • map[string][]map[string]string: A map where keys are metric names, and values are slices of maps, each containing dashboard and widget information where the metric is used.
    • *model.ApiError: An API error if the retrieval fails, nil otherwise.
  1. Code Examples

No examples are needed.

  1. Clarity and Accuracy

The documentation is derived directly from the code and aims to be precise.

  1. Markdown & MDX Perfection

Markdown syntax has been validated.

  1. Edge Cases To Avoid Breaking MDX

All precautions have been taken to avoid breaking MDX.

  1. Getting Started Relevance Include in Getting Started: NO