Documentation
¶
Index ¶
- Constants
- Variables
- func AddTeamMember(ctx context.Context, db *sqlite.DB, log *slog.Logger, teamID models.TeamID, ...) error
- func AddTeamSource(ctx context.Context, db *sqlite.DB, log *slog.Logger, teamID models.TeamID, ...) error
- func AuthenticateAPIToken(ctx context.Context, db *sqlite.DB, log *slog.Logger, ...) (*models.User, *models.APIToken, error)
- func CheckSourceConnectionStatus(ctx context.Context, chDB *clickhouse.Manager, log *slog.Logger, ...) bool
- func CleanupExpiredTokens(ctx context.Context, db *sqlite.DB, log *slog.Logger) error
- func CreateAPIToken(ctx context.Context, db *sqlite.DB, log *slog.Logger, ...) (*models.CreateAPITokenResponse, error)
- func CreateAlert(ctx context.Context, db *sqlite.DB, log *slog.Logger, teamID models.TeamID, ...) (*models.Alert, error)
- func CreateSession(ctx context.Context, db *sqlite.DB, log *slog.Logger, userID models.UserID, ...) (*models.Session, error)
- func CreateSource(ctx context.Context, db *sqlite.DB, chDB *clickhouse.Manager, log *slog.Logger, ...) (*models.Source, error)
- func CreateTeam(ctx context.Context, db *sqlite.DB, log *slog.Logger, name, description string) (*models.Team, error)
- func CreateTeamSourceQuery(ctx context.Context, db *sqlite.DB, log *slog.Logger, teamID models.TeamID, ...) (*models.SavedTeamQuery, error)
- func CreateUser(ctx context.Context, db *sqlite.DB, log *slog.Logger, email, fullName string, ...) (*models.User, error)
- func DeleteAPIToken(ctx context.Context, db *sqlite.DB, log *slog.Logger, userID models.UserID, ...) error
- func DeleteAlert(ctx context.Context, db *sqlite.DB, log *slog.Logger, teamID models.TeamID, ...) error
- func DeleteSource(ctx context.Context, db *sqlite.DB, chDB *clickhouse.Manager, log *slog.Logger, ...) error
- func DeleteTeam(ctx context.Context, db *sqlite.DB, log *slog.Logger, teamID models.TeamID) error
- func DeleteTeamSourceQuery(ctx context.Context, db *sqlite.DB, log *slog.Logger, teamID models.TeamID, ...) error
- func DeleteUser(ctx context.Context, db *sqlite.DB, log *slog.Logger, id models.UserID) error
- func GetAPIToken(ctx context.Context, db *sqlite.DB, tokenID int) (*models.APIToken, error)
- func GetAlert(ctx context.Context, db *sqlite.DB, log *slog.Logger, alertID models.AlertID) (*models.Alert, error)
- func GetSource(ctx context.Context, db *sqlite.DB, chDB *clickhouse.Manager, log *slog.Logger, ...) (*models.Source, error)
- func GetSourceHealth(ctx context.Context, db *sqlite.DB, chDB *clickhouse.Manager, ...) (models.SourceHealth, error)
- func GetSourceSchema(ctx context.Context, db *sqlite.DB, chDB *clickhouse.Manager, log *slog.Logger, ...) ([]models.ColumnInfo, error)
- func GetSourcesWithDetails(ctx context.Context, db *sqlite.DB, chDB *clickhouse.Manager, log *slog.Logger, ...) ([]*models.Source, error)
- func GetTeam(ctx context.Context, db *sqlite.DB, id models.TeamID) (*models.Team, error)
- func GetTeamByName(ctx context.Context, db *sqlite.DB, name string) (*models.Team, error)
- func GetTeamMember(ctx context.Context, db *sqlite.DB, teamID models.TeamID, userID models.UserID) (*models.TeamMember, error)
- func GetTeamSourceQuery(ctx context.Context, db *sqlite.DB, log *slog.Logger, teamID models.TeamID, ...) (*models.SavedTeamQuery, error)
- func GetUser(ctx context.Context, db *sqlite.DB, id models.UserID) (*models.User, error)
- func GetUserByEmail(ctx context.Context, db *sqlite.DB, email string) (*models.User, error)
- func GetUserPreferences(ctx context.Context, db *sqlite.DB, userID models.UserID) (models.UserPreferences, bool, error)
- func InitAdminUsers(ctx context.Context, db *sqlite.DB, log *slog.Logger, adminEmails []string) error
- func InitializeSource(ctx context.Context, chDB *clickhouse.Manager, source *models.Source) error
- func IsAnyTeamAdmin(ctx context.Context, db *sqlite.DB, userID models.UserID) (bool, error)
- func IsNotFoundError(err error) bool
- func IsTeamAdmin(ctx context.Context, db *sqlite.DB, teamID models.TeamID, userID models.UserID) (bool, error)
- func IsTeamMember(ctx context.Context, db *sqlite.DB, teamID models.TeamID, userID models.UserID) (bool, error)
- func ListAPITokensForUser(ctx context.Context, db *sqlite.DB, userID models.UserID) ([]*models.APIToken, error)
- func ListAlertHistory(ctx context.Context, db *sqlite.DB, alertID models.AlertID, limit int) ([]*models.AlertHistoryEntry, error)
- func ListAlertsByTeamSource(ctx context.Context, db *sqlite.DB, teamID models.TeamID, ...) ([]*models.Alert, error)
- func ListQueriesForTeamAndSource(ctx context.Context, db *sqlite.DB, log *slog.Logger, teamID models.TeamID, ...) ([]*models.SavedTeamQuery, error)
- func ListSourceTeams(ctx context.Context, db *sqlite.DB, sourceID models.SourceID) ([]*models.Team, error)
- func ListSources(ctx context.Context, db *sqlite.DB, chDB *clickhouse.Manager, log *slog.Logger) ([]*models.Source, error)
- func ListSourcesForUser(ctx context.Context, db *sqlite.DB, userID models.UserID) ([]*models.Source, error)
- func ListTeamMembers(ctx context.Context, db *sqlite.DB, teamID models.TeamID) ([]*models.TeamMember, error)
- func ListTeamSources(ctx context.Context, db *sqlite.DB, chDB *clickhouse.Manager, log *slog.Logger, ...) ([]*models.Source, error)
- func ListTeams(ctx context.Context, db *sqlite.DB) ([]*models.Team, error)
- func ListTeamsForUser(ctx context.Context, db *sqlite.DB, userID models.UserID) ([]*models.UserTeamDetails, error)
- func ListTeamsWithAccessToSource(ctx context.Context, db *sqlite.DB, log *slog.Logger, sourceID models.SourceID, ...) ([]*models.Team, error)
- func ListUsers(ctx context.Context, db *sqlite.DB) ([]*models.User, error)
- func ParseSourceID(sourceIDStr string) (models.SourceID, error)
- func ParseTeamID(teamIDStr string) (models.TeamID, error)
- func ParseUserID(userIDStr string) (models.UserID, error)
- func QueryLogs(ctx context.Context, db *sqlite.DB, chDB *clickhouse.Manager, log *slog.Logger, ...) (*models.QueryResult, error)
- func RemoveTeamMember(ctx context.Context, db *sqlite.DB, log *slog.Logger, teamID models.TeamID, ...) error
- func RemoveTeamSource(ctx context.Context, db *sqlite.DB, log *slog.Logger, teamID models.TeamID, ...) error
- func ResolveAlert(ctx context.Context, db *sqlite.DB, log *slog.Logger, alertID models.AlertID, ...) error
- func RevokeSession(ctx context.Context, db *sqlite.DB, log *slog.Logger, ...) error
- func RevokeUserSessions(ctx context.Context, db *sqlite.DB, log *slog.Logger, userID models.UserID) error
- func TeamHasSourceAccess(ctx context.Context, db *sqlite.DB, teamID models.TeamID, ...) (bool, error)
- func TestAlertQuery(ctx context.Context, db *sqlite.DB, ch *clickhouse.Manager, log *slog.Logger, ...) (*models.TestAlertQueryResponse, error)
- func UpdateAPITokenLastUsed(ctx context.Context, db *sqlite.DB, tokenID int) error
- func UpdateAlert(ctx context.Context, db *sqlite.DB, log *slog.Logger, teamID models.TeamID, ...) (*models.Alert, error)
- func UpdateSource(ctx context.Context, db *sqlite.DB, chDB *clickhouse.Manager, log *slog.Logger, ...) (*models.Source, error)
- func UpdateTeam(ctx context.Context, db *sqlite.DB, log *slog.Logger, teamID models.TeamID, ...) error
- func UpdateTeamMemberRole(ctx context.Context, db *sqlite.DB, log *slog.Logger, teamID models.TeamID, ...) error
- func UpdateTeamSourceQuery(ctx context.Context, db *sqlite.DB, log *slog.Logger, teamID models.TeamID, ...) (*models.SavedTeamQuery, error)
- func UpdateUser(ctx context.Context, db *sqlite.DB, log *slog.Logger, userID models.UserID, ...) error
- func UpdateUserPreferences(ctx context.Context, db *sqlite.DB, userID models.UserID, ...) (models.UserPreferences, error)
- func UserHasAccessToTeamSource(ctx context.Context, db *sqlite.DB, log *slog.Logger, userID models.UserID, ...) (bool, error)
- func ValidateConnection(ctx context.Context, chDB *clickhouse.Manager, log *slog.Logger, ...) (*models.ConnectionValidationResult, error)
- func ValidateConnectionWithColumns(ctx context.Context, chDB *clickhouse.Manager, log *slog.Logger, ...) (*models.ConnectionValidationResult, error)
- func ValidateSavedQueryContent(contentJSON string) error
- func ValidateSession(ctx context.Context, db *sqlite.DB, log *slog.Logger, ...) (*models.Session, error)
- type HistogramParams
- type HistogramResponse
- type LogContextParams
- type LogContextResponse
- type SourceStats
- type ValidationError
Constants ¶
const ( // TokenPrefix is the prefix for all API tokens TokenPrefix = "logchef_" // TokenLength is the length of the random part of the token (32 characters) TokenLength = 32 // TokenPrefixLength is the length of the prefix shown to users TokenPrefixLength = 8 )
Variables ¶
var ( // ErrAlertNotFound is returned when an alert rule cannot be located. ErrAlertNotFound = errors.New("alert not found") // ErrInvalidAlertConfiguration indicates the request payload failed validation. ErrInvalidAlertConfiguration = errors.New("invalid alert configuration") )
var ( // ErrAPITokenNotFound is returned when an API token is not found ErrAPITokenNotFound = errors.New("API token not found") // ErrInvalidToken is returned when a token format is invalid ErrInvalidToken = errors.New("invalid token format") // ErrTokenExpired is returned when a token has expired ErrTokenExpired = errors.New("token has expired") )
var ( ErrQueryNotFound = fmt.Errorf("saved query not found") ErrQueryTypeRequired = fmt.Errorf("query type is required") ErrInvalidQueryType = fmt.Errorf("invalid query type: must be 'logchefql' or 'sql'") ErrInvalidQueryContent = fmt.Errorf("invalid query content format or values") )
var ( ErrSessionNotFound = errors.New("session not found") ErrSessionExpired = errors.New("session expired") )
Session-specific errors
var ( // ErrUserNotFound is returned when a user is not found. ErrUserNotFound = errors.New("user not found") // ErrCannotDeleteLastAdmin is returned when attempting to delete or deactivate the last admin. ErrCannotDeleteLastAdmin = errors.New("cannot delete or deactivate the last admin user") // ErrUserAlreadyExists is returned when trying to create a user that already exists. ErrUserAlreadyExists = errors.New("user already exists") // ErrTeamAlreadyExists is returned when trying to create a team that already exists. ErrTeamAlreadyExists = errors.New("team already exists") // ErrInvalidRole is returned for invalid user or team roles. ErrInvalidRole = errors.New("invalid role specified") // ErrInvalidStatus is returned for invalid user status. ErrInvalidStatus = errors.New("invalid status specified") // Define team/source errors here temporarily for IsNotFoundError, or reference from other files. // Ideally, these would live in teams.go and source.go respectively. ErrTeamNotFound = errors.New("team not found") )
var DefaultUserPreferences = models.UserPreferences{ Theme: models.ThemePreferenceAuto, Timezone: models.TimezonePreferenceLocal, DisplayMode: models.DisplayModeTable, FieldsPanelOpen: true, }
DefaultUserPreferences defines the baseline preferences for users.
var ErrSourceAlreadyExists = fmt.Errorf("source already exists")
var ErrSourceNotFound = fmt.Errorf("source not found")
ErrSourceNotFound is returned when a source is not found
Functions ¶
func AddTeamMember ¶
func AddTeamMember(ctx context.Context, db *sqlite.DB, log *slog.Logger, teamID models.TeamID, userID models.UserID, role models.TeamRole) error
AddTeamMember adds a user to a team with a specified role. If the user is already a member, it updates their role.
func AddTeamSource ¶
func AddTeamSource(ctx context.Context, db *sqlite.DB, log *slog.Logger, teamID models.TeamID, sourceID models.SourceID) error
AddTeamSource associates a source with a team.
func AuthenticateAPIToken ¶ added in v0.2.2
func AuthenticateAPIToken(ctx context.Context, db *sqlite.DB, log *slog.Logger, authCfg *config.AuthConfig, token string) (*models.User, *models.APIToken, error)
AuthenticateAPIToken authenticates a token and returns the associated user
func CheckSourceConnectionStatus ¶
func CheckSourceConnectionStatus(ctx context.Context, chDB *clickhouse.Manager, log *slog.Logger, source *models.Source) bool
CheckSourceConnectionStatus checks the connection status for a given source. It returns true if the source is connected and the table is queryable, false otherwise.
func CleanupExpiredTokens ¶ added in v0.2.2
CleanupExpiredTokens removes all expired API tokens
func CreateAPIToken ¶ added in v0.2.2
func CreateAPIToken(ctx context.Context, db *sqlite.DB, log *slog.Logger, authCfg *config.AuthConfig, userID models.UserID, name string, expiresAt *time.Time) (*models.CreateAPITokenResponse, error)
CreateAPIToken creates a new API token for a user
func CreateAlert ¶ added in v0.6.0
func CreateAlert(ctx context.Context, db *sqlite.DB, log *slog.Logger, teamID models.TeamID, sourceID models.SourceID, req *models.CreateAlertRequest) (*models.Alert, error)
CreateAlert creates a new alert rule for the specified team and source.
func CreateSession ¶
func CreateSession(ctx context.Context, db *sqlite.DB, log *slog.Logger, userID models.UserID, duration time.Duration, maxConcurrent int) (*models.Session, error)
CreateSession creates a new session for a user, respecting concurrent session limits.
func CreateSource ¶
func CreateSource(ctx context.Context, db *sqlite.DB, chDB *clickhouse.Manager, log *slog.Logger, name string, autoCreateTable bool, conn models.ConnectionInfo, description string, ttlDays int, metaTSField, metaSeverityField, customSchema string) (*models.Source, error)
CreateSource creates a new source, validates connection, and optionally creates the table.
func CreateTeam ¶
func CreateTeam(ctx context.Context, db *sqlite.DB, log *slog.Logger, name, description string) (*models.Team, error)
CreateTeam creates a new team in the database.
func CreateTeamSourceQuery ¶
func CreateTeamSourceQuery(ctx context.Context, db *sqlite.DB, log *slog.Logger, teamID models.TeamID, sourceID models.SourceID, name, description, queryContentJSON, queryType string) (*models.SavedTeamQuery, error)
CreateTeamSourceQuery creates a new saved query for a team and source.
func CreateUser ¶
func CreateUser(ctx context.Context, db *sqlite.DB, log *slog.Logger, email, fullName string, role models.UserRole, status models.UserStatus) (*models.User, error)
CreateUser creates a new user in the database.
func DeleteAPIToken ¶ added in v0.2.2
func DeleteAPIToken(ctx context.Context, db *sqlite.DB, log *slog.Logger, userID models.UserID, tokenID int) error
DeleteAPIToken deletes an API token by ID, ensuring the user owns it
func DeleteAlert ¶ added in v0.6.0
func DeleteAlert(ctx context.Context, db *sqlite.DB, log *slog.Logger, teamID models.TeamID, sourceID models.SourceID, alertID models.AlertID) error
DeleteAlert removes an alert rule.
func DeleteSource ¶
func DeleteSource(ctx context.Context, db *sqlite.DB, chDB *clickhouse.Manager, log *slog.Logger, id models.SourceID) error
DeleteSource deletes a source from SQLite and removes its connection from the manager
func DeleteTeam ¶
DeleteTeam deletes a team and its associations (members, sources, queries).
func DeleteTeamSourceQuery ¶
func DeleteTeamSourceQuery(ctx context.Context, db *sqlite.DB, log *slog.Logger, teamID models.TeamID, sourceID models.SourceID, queryID int) error
DeleteTeamSourceQuery deletes a specific saved query.
func DeleteUser ¶
DeleteUser deletes a user from the database.
func GetAPIToken ¶ added in v0.2.2
GetAPIToken retrieves an API token by ID
func GetAlert ¶ added in v0.6.0
func GetAlert(ctx context.Context, db *sqlite.DB, log *slog.Logger, alertID models.AlertID) (*models.Alert, error)
GetAlert retrieves a single alert by ID.
func GetSource ¶
func GetSource(ctx context.Context, db *sqlite.DB, chDB *clickhouse.Manager, log *slog.Logger, id models.SourceID) (*models.Source, error)
GetSource retrieves a source by ID including connection status and schema
func GetSourceHealth ¶
func GetSourceHealth(ctx context.Context, db *sqlite.DB, chDB *clickhouse.Manager, id models.SourceID) (models.SourceHealth, error)
GetSourceHealth retrieves the health status of a source from the ClickHouse manager
func GetSourceSchema ¶
func GetSourceSchema(ctx context.Context, db *sqlite.DB, chDB *clickhouse.Manager, log *slog.Logger, sourceID models.SourceID) ([]models.ColumnInfo, error)
GetSourceSchema retrieves the schema (column information) for a specific source from ClickHouse.
func GetSourcesWithDetails ¶
func GetSourcesWithDetails(ctx context.Context, db *sqlite.DB, chDB *clickhouse.Manager, log *slog.Logger, sourceIDs []models.SourceID) ([]*models.Source, error)
GetSourcesWithDetails retrieves multiple sources with their full details including schema This is more efficient than calling GetSource multiple times for a list of sources
func GetTeamByName ¶
GetTeamByName retrieves a specific team by its name.
func GetTeamMember ¶
func GetTeamMember(ctx context.Context, db *sqlite.DB, teamID models.TeamID, userID models.UserID) (*models.TeamMember, error)
GetTeamMember retrieves a specific member's details within a team.
func GetTeamSourceQuery ¶
func GetTeamSourceQuery(ctx context.Context, db *sqlite.DB, log *slog.Logger, teamID models.TeamID, sourceID models.SourceID, queryID int) (*models.SavedTeamQuery, error)
GetTeamSourceQuery retrieves a specific saved query by its ID, team ID, and source ID.
func GetUserByEmail ¶
GetUserByEmail retrieves a specific user by their email address.
func GetUserPreferences ¶ added in v1.3.0
func GetUserPreferences(ctx context.Context, db *sqlite.DB, userID models.UserID) (models.UserPreferences, bool, error)
GetUserPreferences returns stored preferences for a user. If none are stored, defaults are returned with isDefault=true.
func InitAdminUsers ¶
func InitAdminUsers(ctx context.Context, db *sqlite.DB, log *slog.Logger, adminEmails []string) error
InitAdminUsers ensures that specified admin users exist and are configured correctly.
func InitializeSource ¶
InitializeSource adds a source connection to the ClickHouse manager. It assumes the source object contains valid connection details.
func IsAnyTeamAdmin ¶ added in v1.3.0
IsAnyTeamAdmin checks if a user is an admin of ANY team. This is used to determine if a user should have access to team management features.
func IsNotFoundError ¶
IsNotFoundError checks if the error is a known not found error. TODO: Refactor to check errors defined in respective packages (users, teams, source) if errors are split.
func IsTeamAdmin ¶
func IsTeamAdmin(ctx context.Context, db *sqlite.DB, teamID models.TeamID, userID models.UserID) (bool, error)
IsTeamAdmin checks if a user is an admin of a specific team.
func IsTeamMember ¶
func IsTeamMember(ctx context.Context, db *sqlite.DB, teamID models.TeamID, userID models.UserID) (bool, error)
IsTeamMember checks if a user is a member of a specific team.
func ListAPITokensForUser ¶ added in v0.2.2
func ListAPITokensForUser(ctx context.Context, db *sqlite.DB, userID models.UserID) ([]*models.APIToken, error)
ListAPITokensForUser lists all API tokens for a specific user
func ListAlertHistory ¶ added in v0.6.0
func ListAlertHistory(ctx context.Context, db *sqlite.DB, alertID models.AlertID, limit int) ([]*models.AlertHistoryEntry, error)
ListAlertHistory retrieves a limited set of alert history entries.
func ListAlertsByTeamSource ¶ added in v0.6.0
func ListAlertsByTeamSource(ctx context.Context, db *sqlite.DB, teamID models.TeamID, sourceID models.SourceID) ([]*models.Alert, error)
ListAlertsByTeamSource returns all alerts for a team/source pair.
func ListQueriesForTeamAndSource ¶
func ListQueriesForTeamAndSource(ctx context.Context, db *sqlite.DB, log *slog.Logger, teamID models.TeamID, sourceID models.SourceID) ([]*models.SavedTeamQuery, error)
ListQueriesForTeamAndSource retrieves all saved queries associated with a specific team and source.
func ListSourceTeams ¶
func ListSourceTeams(ctx context.Context, db *sqlite.DB, sourceID models.SourceID) ([]*models.Team, error)
ListSourceTeams returns all teams that have access to a specific source.
func ListSources ¶
func ListSources(ctx context.Context, db *sqlite.DB, chDB *clickhouse.Manager, log *slog.Logger) ([]*models.Source, error)
ListSources returns all sources with basic connection status but without schema details. This is optimized for performance in list views where the schema isn't needed.
func ListSourcesForUser ¶
func ListSourcesForUser(ctx context.Context, db *sqlite.DB, userID models.UserID) ([]*models.Source, error)
ListSourcesForUser returns all unique sources a user has access to across all teams.
func ListTeamMembers ¶
func ListTeamMembers(ctx context.Context, db *sqlite.DB, teamID models.TeamID) ([]*models.TeamMember, error)
ListTeamMembers returns all members of a specific team.
func ListTeamSources ¶
func ListTeamSources(ctx context.Context, db *sqlite.DB, chDB *clickhouse.Manager, log *slog.Logger, teamID models.TeamID) ([]*models.Source, error)
ListTeamSources returns basic information for all sources associated with a specific team, including their connection status fetched from the ClickHouse manager's cache.
func ListTeamsForUser ¶
func ListTeamsForUser(ctx context.Context, db *sqlite.DB, userID models.UserID) ([]*models.UserTeamDetails, error)
ListTeamsForUser returns all teams a user is a member of, including their role and team member count.
func ListTeamsWithAccessToSource ¶
func ListTeamsWithAccessToSource(ctx context.Context, db *sqlite.DB, log *slog.Logger, sourceID models.SourceID, userID models.UserID) ([]*models.Team, error)
ListTeamsWithAccessToSource returns teams accessible by a user for a given source. This involves multiple DB calls and might be better placed closer to the handler.
func ParseSourceID ¶
ParseSourceID converts a string source ID to models.SourceID. Utility function often needed in handlers.
func ParseTeamID ¶
ParseTeamID converts a string team ID to models.TeamID. Utility function often needed in handlers.
func ParseUserID ¶
ParseUserID converts a string user ID to models.UserID. Utility function often needed in handlers.
func QueryLogs ¶
func QueryLogs(ctx context.Context, db *sqlite.DB, chDB *clickhouse.Manager, log *slog.Logger, sourceID models.SourceID, params clickhouse.LogQueryParams) (*models.QueryResult, error)
QueryLogs retrieves logs from a specific source based on the provided parameters. Timeout is always applied - either from params or default value.
func RemoveTeamMember ¶
func RemoveTeamMember(ctx context.Context, db *sqlite.DB, log *slog.Logger, teamID models.TeamID, userID models.UserID) error
RemoveTeamMember removes a user from a team.
func RemoveTeamSource ¶
func RemoveTeamSource(ctx context.Context, db *sqlite.DB, log *slog.Logger, teamID models.TeamID, sourceID models.SourceID) error
RemoveTeamSource removes the association between a source and a team.
func ResolveAlert ¶ added in v0.6.0
func ResolveAlert(ctx context.Context, db *sqlite.DB, log *slog.Logger, alertID models.AlertID, message string) error
ResolveAlert manually resolves the most recent triggered history entry.
func RevokeSession ¶
func RevokeSession(ctx context.Context, db *sqlite.DB, log *slog.Logger, sessionID models.SessionID) error
RevokeSession deletes a specific session by its ID.
func RevokeUserSessions ¶
func RevokeUserSessions(ctx context.Context, db *sqlite.DB, log *slog.Logger, userID models.UserID) error
RevokeUserSessions deletes all sessions for a specific user.
func TeamHasSourceAccess ¶
func TeamHasSourceAccess(ctx context.Context, db *sqlite.DB, teamID models.TeamID, sourceID models.SourceID) (bool, error)
TeamHasSourceAccess checks if a specific team has access to a specific source.
func TestAlertQuery ¶ added in v0.6.0
func TestAlertQuery(ctx context.Context, db *sqlite.DB, ch *clickhouse.Manager, log *slog.Logger, teamID models.TeamID, sourceID models.SourceID, req *models.TestAlertQueryRequest) (*models.TestAlertQueryResponse, error)
TestAlertQuery executes a test query to validate alert configuration and show performance metrics.
func UpdateAPITokenLastUsed ¶ added in v0.2.2
UpdateAPITokenLastUsed updates the last used timestamp for an API token
func UpdateAlert ¶ added in v0.6.0
func UpdateAlert(ctx context.Context, db *sqlite.DB, log *slog.Logger, teamID models.TeamID, sourceID models.SourceID, alertID models.AlertID, req *models.UpdateAlertRequest) (*models.Alert, error)
UpdateAlert updates an existing alert rule.
func UpdateSource ¶
func UpdateSource(ctx context.Context, db *sqlite.DB, chDB *clickhouse.Manager, log *slog.Logger, id models.SourceID, req *models.UpdateSourceRequest) (*models.Source, error)
UpdateSource updates an existing source's mutable fields using partial update semantics. Connection changes trigger re-validation and pool refresh.
func UpdateTeam ¶
func UpdateTeam(ctx context.Context, db *sqlite.DB, log *slog.Logger, teamID models.TeamID, updateData models.Team) error
UpdateTeam updates an existing team's mutable fields (name, description).
func UpdateTeamMemberRole ¶
func UpdateTeamMemberRole(ctx context.Context, db *sqlite.DB, log *slog.Logger, teamID models.TeamID, userID models.UserID, newRole models.TeamRole) error
UpdateTeamMemberRole changes the role of an existing team member.
func UpdateTeamSourceQuery ¶
func UpdateTeamSourceQuery(ctx context.Context, db *sqlite.DB, log *slog.Logger, teamID models.TeamID, sourceID models.SourceID, queryID int, name, description, queryContentJSON, queryType string) (*models.SavedTeamQuery, error)
UpdateTeamSourceQuery updates an existing saved query.
func UpdateUser ¶
func UpdateUser(ctx context.Context, db *sqlite.DB, log *slog.Logger, userID models.UserID, updateData models.User) error
UpdateUser updates an existing user's information.
func UpdateUserPreferences ¶ added in v1.3.0
func UpdateUserPreferences(ctx context.Context, db *sqlite.DB, userID models.UserID, update models.UpdateUserPreferencesRequest) (models.UserPreferences, error)
UpdateUserPreferences applies updates and persists user preferences.
func UserHasAccessToTeamSource ¶
func UserHasAccessToTeamSource(ctx context.Context, db *sqlite.DB, log *slog.Logger, userID models.UserID, teamID models.TeamID, sourceID models.SourceID) (bool, error)
UserHasAccessToTeamSource checks if a user has access to a specific source through a specific team. This is the proper way to check access - requiring both team membership and team-source linkage.
func ValidateConnection ¶
func ValidateConnection(ctx context.Context, chDB *clickhouse.Manager, log *slog.Logger, conn models.ConnectionInfo) (*models.ConnectionValidationResult, error)
ValidateConnection validates a connection to a ClickHouse database using temporary client
func ValidateConnectionWithColumns ¶
func ValidateConnectionWithColumns(ctx context.Context, chDB *clickhouse.Manager, log *slog.Logger, conn models.ConnectionInfo, tsField, severityField string) (*models.ConnectionValidationResult, error)
ValidateConnectionWithColumns validates a connection and checks specified column types.
func ValidateSavedQueryContent ¶
ValidateSavedQueryContent validates the JSON structure and basic rules of the query content.
Types ¶
type HistogramParams ¶
type HistogramParams struct {
Window string // e.g., "1m", "5m", "1h"
Query string // Optional filter query (WHERE clause part)
GroupBy string // Optional field to group by
Timezone string // Optional timezone identifier (e.g., 'America/New_York', 'UTC')
// Query execution timeout in seconds. If not specified, uses default timeout.
QueryTimeout *int
}
HistogramParams defines parameters specifically for histogram queries. Keeping it separate allows for specific validation or processing.
type HistogramResponse ¶
type HistogramResponse struct {
Granularity string `json:"granularity"`
Data []clickhouse.HistogramData `json:"data"`
}
HistogramResponse structures the response for histogram data.
func GetHistogramData ¶
func GetHistogramData(ctx context.Context, db *sqlite.DB, chDB *clickhouse.Manager, log *slog.Logger, sourceID models.SourceID, params HistogramParams) (*HistogramResponse, error)
GetHistogramData fetches histogram data for a specific source and time range.
type LogContextParams ¶ added in v1.0.0
type LogContextParams struct {
TargetTimestamp int64 // Unix timestamp in milliseconds
BeforeLimit int // Number of logs to fetch before target time
AfterLimit int // Number of logs to fetch after target time
BeforeOffset int // Offset for before query (for pagination)
AfterOffset int // Offset for after query (for pagination)
ExcludeBoundary bool // When true, use < instead of <= for before query (for pagination)
QueryTimeout *int // Optional query timeout in seconds
}
LogContextParams defines parameters for the log context query.
type LogContextResponse ¶ added in v1.0.0
type LogContextResponse struct {
TargetTimestamp int64 `json:"target_timestamp"`
BeforeLogs []map[string]interface{} `json:"before_logs"`
TargetLogs []map[string]interface{} `json:"target_logs"`
AfterLogs []map[string]interface{} `json:"after_logs"`
Stats models.QueryStats `json:"stats"`
}
LogContextResponse structures the response for log context data.
func GetLogContext ¶ added in v1.0.0
func GetLogContext(ctx context.Context, db *sqlite.DB, chDB *clickhouse.Manager, log *slog.Logger, sourceID models.SourceID, params LogContextParams) (*LogContextResponse, error)
GetLogContext retrieves surrounding logs around a specific timestamp for contextual analysis. This is similar to grep -C, showing N logs before and M logs after the target time.
type SourceStats ¶
type SourceStats struct {
TableStats *clickhouse.TableStat `json:"table_stats"` // Use pointer to allow nil if stats fail completely
ColumnStats []clickhouse.TableColumnStat `json:"column_stats"` // Slice is sufficient, empty if stats fail
TableInfo *clickhouse.TableInfo `json:"table_info"` // Schema, engine, and metadata information
Ingestion *clickhouse.IngestionStats `json:"ingestion_stats,omitempty"`
TTL string `json:"ttl,omitempty"` // TTL information extracted from CREATE TABLE
}
SourceStats represents the combined statistics for a ClickHouse table Use types directly from the clickhouse package
func GetSourceStats ¶
func GetSourceStats(ctx context.Context, chDB *clickhouse.Manager, log *slog.Logger, source *models.Source) (*SourceStats, error)
GetSourceStats retrieves statistics for a specific source (ClickHouse table)
type ValidationError ¶
ValidationError represents a validation error, potentially wrapping an original error.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string