searchstore

package
v0.0.0-cloud Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 30, 2023 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package searchstore converts search queries to SQL.

Because of the wide array of deployments supported by Grafana, search strives to be both performant enough to handle heavy users and lightweight enough to not increase complexity/resource utilization for light users. To allow this we're currently searching without fuzziness and in a single SQL query.

Search queries are a combination of an outer query which Builder creates automatically when calling the Builder.ToSQL method and an inner query feeding that which lists the IDs of the dashboards that should be part of the result set. By default search will return all dashboards (behind pagination) but it is possible to dynamically add filters capable of adding more specific inclusion or ordering requirements.

A filter is any data type which implements one or more of the FilterWhere, FilterGroupBy, FilterOrderBy, or FilterLeftJoin interfaces. The filters will be applied (in order) to limit or reorder the results.

Filters will be applied in order with the final result like such:

SELECT id FROM dashboard LEFT OUTER JOIN <FilterLeftJoin...>
WHERE <FilterWhere[0]> AND ... AND <FilterWhere[n]>
GROUP BY <FilterGroupBy...>
ORDER BY <FilterOrderBy...>
LIMIT <limit> OFFSET <(page-1)*limit>;

This structure is intended to isolate the filters from each other and implementors are expected to add all the required joins, where clauses, groupings, and/or orderings necessary for applying a filter in the filter. Using side-effects of other filters is bad manners and increases the complexity and volatility of the code.

Index

Constants

View Source
const (
	TypeFolder      = "dash-folder"
	TypeDashboard   = "dash-db"
	TypeAlertFolder = "dash-folder-alerting"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

type Builder struct {
	// List of FilterWhere/FilterGroupBy/FilterOrderBy/FilterLeftJoin
	// to modify the query.
	Filters []interface{}
	Dialect migrator.Dialect
	// contains filtered or unexported fields
}

Builder defaults to returning a SQL query to get a list of all dashboards in default order, but can be modified by applying filters.

func (*Builder) ToSQL

func (b *Builder) ToSQL(limit, page int64) (string, []interface{})

ToSQL builds the SQL query and returns it as a string, together with the SQL parameters.

type DashboardFilter

type DashboardFilter struct {
	UIDs []string
}

func (DashboardFilter) Where

func (f DashboardFilter) Where() (string, []interface{})

type DashboardIDFilter

type DashboardIDFilter struct {
	IDs []int64
}

func (DashboardIDFilter) Where

func (f DashboardIDFilter) Where() (string, []interface{})

type FilterGroupBy

type FilterGroupBy interface {
	GroupBy() (string, []interface{})
}

FilterGroupBy should be used after performing an outer join on the search result to ensure there is only one of each ID in the results. The id column must be present in the result.

type FilterLeftJoin

type FilterLeftJoin interface {
	LeftJoin() string
}

FilterLeftJoin adds the returned string as a "LEFT OUTER JOIN" to allow for fetching extra columns from a table outside of the dashboard column.

type FilterOrderBy

type FilterOrderBy interface {
	OrderBy() string
}

FilterOrderBy provides an ordering for the search result.

type FilterSelect

type FilterSelect interface {
	Select() string
}

type FilterWhere

type FilterWhere interface {
	Where() (string, []interface{})
}

FilterWhere limits the set of dashboard IDs to the dashboards for which the filter is applicable. Results where the first value is an empty string are discarded.

type FolderFilter

type FolderFilter struct {
	IDs []int64
}

func (FolderFilter) Where

func (f FolderFilter) Where() (string, []interface{})

type FolderWithAlertsFilter

type FolderWithAlertsFilter struct {
}

FolderWithAlertsFilter applies a filter that makes the result contain only folders that contain alert rules

func (FolderWithAlertsFilter) Where

func (f FolderWithAlertsFilter) Where() (string, []interface{})

type OrgFilter

type OrgFilter struct {
	OrgId int64
}

func (OrgFilter) Where

func (f OrgFilter) Where() (string, []interface{})

type TagsFilter

type TagsFilter struct {
	Tags []string
}

func (TagsFilter) GroupBy

func (f TagsFilter) GroupBy() (string, []interface{})

func (TagsFilter) LeftJoin

func (f TagsFilter) LeftJoin() string

func (TagsFilter) Where

func (f TagsFilter) Where() (string, []interface{})

type TitleFilter

type TitleFilter struct {
	Dialect migrator.Dialect
	Title   string
}

func (TitleFilter) Where

func (f TitleFilter) Where() (string, []interface{})

type TitleSorter

type TitleSorter struct {
	Descending bool
}

func (TitleSorter) OrderBy

func (s TitleSorter) OrderBy() string

type TypeFilter

type TypeFilter struct {
	Dialect migrator.Dialect
	Type    string
}

func (TypeFilter) Where

func (f TypeFilter) Where() (string, []interface{})

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL