gensearch

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: May 27, 2025 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SearchTypeExact      = searchparser.SearchTypeExact
	SearchTypeExactCase  = searchparser.SearchTypeExactCase
	SearchTypeRegexp     = searchparser.SearchTypeRegexp
	SearchTypeRegexpCase = searchparser.SearchTypeRegexpCase
	SearchTypeFzf        = searchparser.SearchTypeFzf
	SearchTypeFzfCase    = searchparser.SearchTypeFzfCase
	SearchTypeNot        = searchparser.SearchTypeNot
	SearchTypeTag        = searchparser.SearchTypeTag
	SearchTypeUserQuery  = searchparser.SearchTypeUserQuery
	SearchTypeMarked     = searchparser.SearchTypeMarked
	SearchTypeNumeric    = searchparser.SearchTypeNumeric

	// Additional constants not in searchparser
	SearchTypeAnd = "and"
	SearchTypeOr  = "or"
	SearchTypeAll = "all"
)

Re-export search type constants from searchparser package

View Source
const (
	MaxSearchManagers = 5
	CleanupInterval   = 10 * time.Second
	MaxIdleTime       = 1 * time.Minute
	TrimSize          = 1000
	LogLineBufferSize = 10000
)
View Source
const (
	FieldMod_ToLower = 1
)

Variables

This section is empty.

Functions

func DropManager

func DropManager(widgetId string)

DropManager removes a SearchManager for the given widget ID

func ExtractErrorSpans

func ExtractErrorSpans(node *searchparser.Node) []rpctypes.SearchErrorSpan

ExtractErrorSpans extracts all error nodes from the AST

func GetAllSearchManagerInfos

func GetAllSearchManagerInfos() map[string]SearchManagerInfo

GetAllSearchManagerInfos returns a map of widget ID to SearchManagerInfo for all search managers

func PrettyPrint

func PrettyPrint(s Searcher) string

PrettyPrint returns a human-readable string representation of a searcher

func PrettyPrintMultiline

func PrettyPrintMultiline(s Searcher) string

PrettyPrintMultiline returns a human-readable multi-line string representation of a searcher

Types

type AllSearcher

type AllSearcher struct{}

AllSearcher implements a searcher that matches everything

func (*AllSearcher) GetType

func (s *AllSearcher) GetType() string

GetType returns the search type identifier

func (*AllSearcher) Match

func (s *AllSearcher) Match(sctx *SearchContext, obj SearchObject) bool

Match always returns true

type AndSearcher

type AndSearcher struct {
	// contains filtered or unexported fields
}

AndSearcher implements a searcher that requires all contained searchers to match

func (*AndSearcher) GetType

func (s *AndSearcher) GetType() string

GetType returns the search type identifier

func (*AndSearcher) Match

func (s *AndSearcher) Match(sctx *SearchContext, obj SearchObject) bool

Match checks if the search object matches all contained searchers

type ExactSearcher

type ExactSearcher struct {
	// contains filtered or unexported fields
}

ExactSearcher implements exact string matching with case sensitivity option

func (*ExactSearcher) GetType

func (s *ExactSearcher) GetType() string

GetType returns the search type identifier

func (*ExactSearcher) Match

func (s *ExactSearcher) Match(sctx *SearchContext, obj SearchObject) bool

Match checks if the search object contains the search term

type FzfSearcher

type FzfSearcher struct {
	// contains filtered or unexported fields
}

FzfSearcher implements fuzzy matching using the fzf algorithm

func (*FzfSearcher) GetType

func (s *FzfSearcher) GetType() string

GetType returns the search type identifier

func (*FzfSearcher) Match

func (s *FzfSearcher) Match(sctx *SearchContext, obj SearchObject) bool

Match checks if the search object matches the fuzzy search pattern

type GoRoutineSearchObject

type GoRoutineSearchObject struct {
	GoId  int64
	Name  string
	Tags  []string
	Stack string
	State string

	// Cached values for searches
	NameToLower     string
	GoIdStr         string
	StackToLower    string
	StateToLower    string
	Combined        string
	CombinedToLower string
}

func (*GoRoutineSearchObject) GetField

func (gso *GoRoutineSearchObject) GetField(fieldName string, fieldMods int) string

func (*GoRoutineSearchObject) GetId

func (gso *GoRoutineSearchObject) GetId() int64

func (*GoRoutineSearchObject) GetTags

func (gso *GoRoutineSearchObject) GetTags() []string

type LogSearchObject

type LogSearchObject struct {
	// Direct line fields
	Msg     string
	Source  string
	LineNum int64

	// Cached values for searches
	MsgToLower    string
	SourceToLower string
	LineNumStr    string
	CachedTags    []string
	TagsParsed    bool
}

func (*LogSearchObject) GetField

func (lso *LogSearchObject) GetField(fieldName string, fieldMods int) string

func (*LogSearchObject) GetId

func (lso *LogSearchObject) GetId() int64

func (*LogSearchObject) GetTags

func (lso *LogSearchObject) GetTags() []string

type MarkManager

type MarkManager struct {
	Lock      *sync.Mutex
	MarkedIds map[int64]bool // Map of line numbers that are marked
}

MarkManager handles management of marked log lines

func GetMarkManager

func GetMarkManager(widgetId string) *MarkManager

GetMarkManager returns the MarkManager for the given widget ID

func MakeMarkManager

func MakeMarkManager() *MarkManager

MakeMarkManager creates a new MarkManager

func (*MarkManager) ClearMarks

func (m *MarkManager) ClearMarks()

ClearMarks clears all marked lines

func (*MarkManager) GetMarkedIds

func (m *MarkManager) GetMarkedIds() map[int64]bool

GetMarkedIds returns a copy of the marked lines map

func (*MarkManager) GetMarkedLogLines

func (m *MarkManager) GetMarkedLogLines(allLogs []ds.LogLine) []ds.LogLine

GetMarkedLogLines returns all marked log lines from the provided logs

func (*MarkManager) GetNumMarks

func (m *MarkManager) GetNumMarks() int

GetNumMarks returns the number of marked lines

func (*MarkManager) UpdateMarkedLines

func (m *MarkManager) UpdateMarkedLines(marks map[int64]bool)

UpdateMarkedLines updates the marked status of lines based on the provided map If the value is true, the line is marked; if false, the mark is removed

type MarkedSearcher

type MarkedSearcher struct{}

MarkedSearcher is a searcher that matches lines that are marked

func (*MarkedSearcher) GetType

func (s *MarkedSearcher) GetType() string

GetType returns the search type identifier

func (*MarkedSearcher) Match

func (s *MarkedSearcher) Match(sctx *SearchContext, obj SearchObject) bool

Match checks if a search object is marked

type NotSearcher

type NotSearcher struct {
	// contains filtered or unexported fields
}

NotSearcher implements a searcher that inverts the result of another searcher

func (*NotSearcher) GetType

func (s *NotSearcher) GetType() string

GetType returns the search type identifier

func (*NotSearcher) Match

func (s *NotSearcher) Match(sctx *SearchContext, obj SearchObject) bool

Match checks if the search object does NOT match the contained searcher

type NumericSearcher

type NumericSearcher struct {
	// contains filtered or unexported fields
}

NumericSearcher implements numeric comparison operations (>, <, >=, <=)

func (*NumericSearcher) GetType

func (s *NumericSearcher) GetType() string

GetType returns the search type identifier

func (*NumericSearcher) Match

func (s *NumericSearcher) Match(sctx *SearchContext, obj SearchObject) bool

Match checks if the numeric field value satisfies the comparison

type OrSearcher

type OrSearcher struct {
	// contains filtered or unexported fields
}

OrSearcher implements a searcher that matches if any contained searcher matches

func (*OrSearcher) GetType

func (s *OrSearcher) GetType() string

GetType returns the search type identifier

func (*OrSearcher) Match

func (s *OrSearcher) Match(sctx *SearchContext, obj SearchObject) bool

Match checks if the search object matches any contained searcher

type PeerInterface

type PeerInterface interface {
	GetLogLines() ([]ds.LogLine, int)
	RegisterSearchManager(manager SearchManagerInterface)
	UnregisterSearchManager(manager SearchManagerInterface)
}

type RegexpSearcher

type RegexpSearcher struct {
	// contains filtered or unexported fields
}

RegexpSearcher implements regular expression matching

func (*RegexpSearcher) GetType

func (s *RegexpSearcher) GetType() string

GetType returns the search type identifier

func (*RegexpSearcher) Match

func (s *RegexpSearcher) Match(sctx *SearchContext, obj SearchObject) bool

Match checks if the search object matches the regular expression

type SearchContext

type SearchContext struct {
	MarkedLines map[int64]bool
	UserQuery   Searcher
}

SearchContext contains runtime context for search operations

type SearchManager

type SearchManager struct {
	Lock     *sync.Mutex
	WidgetId string
	AppRunId string
	LogPeer  PeerInterface // Reference to the peer for log operations
	LastUsed time.Time     // Timestamp of when this manager was last used

	// User search components
	UserQuery    string   // The user's search term
	UserSearcher Searcher // Searcher for the user's search term

	// System search components
	SystemQuery    string   // System-generated query that may reference UserQuery
	SystemSearcher Searcher // Searcher for the system query

	CachedResult []ds.LogLine // Filtered log lines matching the search criteria
	Stats        SearchStats  // Statistics about the search operation
	TrimmedCount int          // Number of lines trimmed from the filtered logs

	MarkManager *MarkManager // Manager for marked lines
	RpcSource   string       // Source of the last RPC request that used this manager
	Streaming   bool         // Whether to stream updates to the client
}

SearchManager handles search functionality for a specific widget

func GetManager

func GetManager(widgetId string) *SearchManager

func GetOrCreateManager

func GetOrCreateManager(widgetId string, appRunId string, peer PeerInterface) *SearchManager

GetOrCreateManager gets or creates a SearchManager for the given widget ID and app run ID

func MakeSearchManager

func MakeSearchManager(widgetId string, appRunId string, peer PeerInterface) *SearchManager

MakeSearchManager creates a new SearchManager for a specific widget

func (*SearchManager) GetInfo

func (m *SearchManager) GetInfo() SearchManagerInfo

GetInfo returns a thread-safe copy of the SearchManager's information

func (*SearchManager) GetLastUsed

func (m *SearchManager) GetLastUsed() time.Time

func (*SearchManager) GetMarkedLogLines

func (m *SearchManager) GetMarkedLogLines() ([]ds.LogLine, error)

GetMarkedLogLines returns all marked log lines using a MarkedSearcher

func (*SearchManager) ProcessNewLine

func (m *SearchManager) ProcessNewLine(line ds.LogLine)

ProcessNewLine processes a new log line and adds it to FilteredLogs if it matches the search criteria

func (*SearchManager) SearchLogs

SearchLogs handles a search request for logs

func (*SearchManager) SetRpcSource

func (m *SearchManager) SetRpcSource(ctx context.Context)

SetRpcSource updates the RpcSource field with proper synchronization

func (*SearchManager) UpdateLastUsed

func (m *SearchManager) UpdateLastUsed()

UpdateLastUsed updates the LastUsed timestamp for a SearchManager

type SearchManagerInfo

type SearchManagerInfo struct {
	WidgetId         string      `json:"widgetid"`
	AppRunId         string      `json:"apprunid"`
	LastUsedTime     time.Time   `json:"lastusedtime"`
	SearchTerm       string      `json:"searchterm"`
	FilteredLogCount int         `json:"filteredlogcount"`
	MarkedLinesCount int         `json:"markedlinescount"`
	RpcSource        string      `json:"rpcsource,omitempty"`
	TrimmedCount     int         `json:"trimmedcount,omitempty"`
	Stats            SearchStats `json:"stats"`
	Streaming        bool        `json:"streaming"`
}

SearchManagerInfo contains thread-safe information about a SearchManager

type SearchManagerInterface

type SearchManagerInterface interface {
	ProcessNewLine(line ds.LogLine)
}

SearchManagerInterface defines the interface for search managers This is the same interface as in apppeer, but defined here to avoid the dependency

type SearchObject

type SearchObject interface {
	GetField(fieldName string, fieldMods int) string
	GetTags() []string
	GetId() int64
}

func LogLineToSearchObject

func LogLineToSearchObject(line ds.LogLine) SearchObject

LogLineToSearchObject converts a ds.LogLine to a SearchObject

func ParsedGoRoutineToSearchObject

func ParsedGoRoutineToSearchObject(gr rpctypes.ParsedGoRoutine) SearchObject

ParsedGoRoutineToSearchObject converts a ParsedGoRoutine to a GoRoutineSearchObject

type SearchStats

type SearchStats struct {
	TotalCount     int   `json:"totalcount"`     // Total number of log lines in the AppRunPeer
	SearchedCount  int   `json:"searchedcount"`  // Number of log lines that were actually searched
	LastLineNum    int64 `json:"lastlinenum"`    // Last line number processed to avoid duplicates
	SearchDuration int   `json:"searchduration"` // Duration of the search operation in milliseconds
}

SearchStats contains statistics about a search operation

func PerformSearch

func PerformSearch[T any](allItems []T, totalCount int, toSearchObj func(T) SearchObject, searcher Searcher, sctx *SearchContext) ([]T, *SearchStats, error)

PerformSearch is a generic function that filters items based on search criteria It takes a slice of items of any type T, a total count, a function to convert T to SearchObject, a searcher, and a search context, and returns filtered items and search stats

type Searcher

type Searcher interface {
	// Match checks if a search object matches the search criteria
	Match(sctx *SearchContext, obj SearchObject) bool

	// GetType returns the search type identifier
	GetType() string
}

Searcher defines the interface for different search strategies

func GetSearcher

func GetSearcher(searchTerm string) (Searcher, error)

GetSearcher returns the appropriate searcher based on the search term

func GetSearcherWithErrors

func GetSearcherWithErrors(searchTerm string) (Searcher, []rpctypes.SearchErrorSpan, error)

GetSearcherWithErrors returns both a searcher and any error spans found in the search term

func MakeAllSearcher

func MakeAllSearcher() Searcher

MakeAllSearcher creates a new searcher that matches all log lines

func MakeAndSearcher

func MakeAndSearcher(searchers []Searcher) Searcher

MakeAndSearcher creates a new AND searcher from a slice of searchers

func MakeExactSearcher

func MakeExactSearcher(field string, searchTerm string, caseSensitive bool) Searcher

MakeExactSearcher creates a new exact match searcher

func MakeFzfSearcher

func MakeFzfSearcher(field string, searchTerm string, caseSensitive bool) (Searcher, error)

MakeFzfSearcher creates a new FZF searcher

func MakeMarkedSearcher

func MakeMarkedSearcher() Searcher

MakeMarkedSearcher creates a new MarkedSearcher

func MakeNotSearcher

func MakeNotSearcher(searcher Searcher) Searcher

MakeNotSearcher creates a new NOT searcher that inverts the result of the provided searcher

func MakeNumericSearcher

func MakeNumericSearcher(field string, searchTerm string, operator string) (Searcher, error)

MakeNumericSearcher creates a new numeric comparison searcher

func MakeOrSearcher

func MakeOrSearcher(searchers []Searcher) Searcher

MakeOrSearcher creates a new OR searcher from a slice of searchers

func MakeRegexpSearcher

func MakeRegexpSearcher(field string, searchTerm string, caseSensitive bool) (Searcher, error)

MakeRegexpSearcher creates a new regexp searcher

func MakeSearcherFromNode

func MakeSearcherFromNode(node *searchparser.Node) (Searcher, error)

MakeSearcherFromNode creates a searcher from an AST node

func MakeTagSearcher

func MakeTagSearcher(field string, searchTerm string) Searcher

MakeTagSearcher creates a new tag searcher

func MakeUserQuerySearcher

func MakeUserQuerySearcher() Searcher

MakeUserQuerySearcher creates a new UserQuerySearcher

type TagSearcher

type TagSearcher struct {
	// contains filtered or unexported fields
}

TagSearcher implements tag matching

func (*TagSearcher) GetType

func (s *TagSearcher) GetType() string

GetType returns the search type identifier

func (*TagSearcher) Match

func (s *TagSearcher) Match(sctx *SearchContext, obj SearchObject) bool

Match checks if the search object contains a tag that matches the search term

type UserQuerySearcher

type UserQuerySearcher struct{}

UserQuerySearcher is a searcher that delegates to the UserQuery field in SearchContext

func (*UserQuerySearcher) GetType

func (s *UserQuerySearcher) GetType() string

GetType returns the search type identifier

func (*UserQuerySearcher) Match

func (s *UserQuerySearcher) Match(sctx *SearchContext, obj SearchObject) bool

Match delegates to the UserQuery searcher in SearchContext

type WatchSearchObject

type WatchSearchObject struct {
	WatchNum int64
	Name     string
	Val      string // Value of the watch
	Tags     []string
	Type     string

	// Cached values for searches
	NameToLower     string
	ValToLower      string
	TypeToLower     string
	Combined        string
	CombinedToLower string
}

func (*WatchSearchObject) GetField

func (wso *WatchSearchObject) GetField(fieldName string, fieldMods int) string

func (*WatchSearchObject) GetId

func (wso *WatchSearchObject) GetId() int64

func (*WatchSearchObject) GetTags

func (wso *WatchSearchObject) GetTags() []string

Jump to

Keyboard shortcuts

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