diagnostics

package
v0.4.13 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package diagnostics defines read-only runtime inspection contracts for Atlas.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateReadOnlySQL

func ValidateReadOnlySQL(sql string) error

ValidateReadOnlySQL rejects SQL that is not obviously read-only.

Types

type BrowserLogEntry

type BrowserLogEntry struct {
	Time    string `json:"time,omitempty"`
	App     string `json:"app,omitempty"`
	Level   string `json:"level,omitempty"`
	Message string `json:"message"`
	URL     string `json:"url,omitempty"`
}

BrowserLogEntry describes one browser console log entry.

type BrowserLogRequest

type BrowserLogRequest struct {
	App   string `json:"app,omitempty"`
	Limit int    `json:"limit,omitempty"`
}

BrowserLogRequest describes a bounded browser log read.

type Column

type Column struct {
	Name     string `json:"name"`
	Type     string `json:"type"`
	Nullable bool   `json:"nullable"`
	Primary  bool   `json:"primary,omitempty"`
}

Column describes one database column.

type DatabaseConnection

type DatabaseConnection struct {
	Name     string `json:"name"`
	Driver   string `json:"driver"`
	Database string `json:"database,omitempty"`
	App      string `json:"app,omitempty"`
}

DatabaseConnection describes safe database connection metadata.

type DatabaseSchema

type DatabaseSchema struct {
	Connection string  `json:"connection"`
	Tables     []Table `json:"tables,omitempty"`
}

DatabaseSchema describes safe schema metadata.

type Index

type Index struct {
	Name    string   `json:"name"`
	Columns []string `json:"columns"`
	Unique  bool     `json:"unique,omitempty"`
}

Index describes one database index.

type LogEntry

type LogEntry struct {
	Time    string         `json:"time,omitempty"`
	App     string         `json:"app,omitempty"`
	Runtime string         `json:"runtime,omitempty"`
	Level   string         `json:"level,omitempty"`
	Message string         `json:"message"`
	Fields  map[string]any `json:"fields,omitempty"`
}

LogEntry describes one runtime log entry.

type LogRequest

type LogRequest struct {
	App   string `json:"app,omitempty"`
	Limit int    `json:"limit,omitempty"`
}

LogRequest describes a bounded log read.

type MetricsMetadata

type MetricsMetadata struct {
	App      string            `json:"app,omitempty"`
	Runtime  string            `json:"runtime,omitempty"`
	Labels   map[string]string `json:"labels,omitempty"`
	Targets  []string          `json:"targets,omitempty"`
	Counters []string          `json:"counters,omitempty"`
}

MetricsMetadata describes known app/runtime metric labels and targets.

type MetricsMetadataRequest

type MetricsMetadataRequest struct {
	App     string `json:"app,omitempty"`
	Runtime string `json:"runtime,omitempty"`
}

MetricsMetadataRequest describes app/runtime metrics metadata lookup.

type Provider

type Provider interface {
	// DatabaseConnections returns safe connection metadata without secrets.
	DatabaseConnections(context.Context) ([]DatabaseConnection, error)
	// DatabaseSchema returns table, column, and index metadata for a connection.
	DatabaseSchema(context.Context, string) (DatabaseSchema, error)
	// DatabaseQuery runs a bounded read-only query.
	DatabaseQuery(context.Context, QueryRequest) (QueryResult, error)
	// LogEntries returns recent framework log entries.
	LogEntries(context.Context, LogRequest) ([]LogEntry, error)
	// LastError returns the latest error-level log entry when one is available.
	LastError(context.Context) (LogEntry, bool, error)
	// AbsoluteURL resolves an app-relative path to a local absolute URL.
	AbsoluteURL(context.Context, URLRequest) (string, error)
	// BrowserLogs returns recent browser console entries captured during local development.
	BrowserLogs(context.Context, BrowserLogRequest) ([]BrowserLogEntry, error)
	// MetricsMetadata returns app/runtime-aware metrics labels and targets.
	MetricsMetadata(context.Context, MetricsMetadataRequest) (MetricsMetadata, error)
}

Provider supplies read-only runtime diagnostics to Atlas.

type QueryRequest

type QueryRequest struct {
	Connection string `json:"connection"`
	SQL        string `json:"sql"`
	Limit      int    `json:"limit,omitempty"`
}

QueryRequest describes a bounded read-only database query.

type QueryResult

type QueryResult struct {
	Connection string           `json:"connection"`
	Columns    []string         `json:"columns,omitempty"`
	Rows       []map[string]any `json:"rows,omitempty"`
	Limit      int              `json:"limit,omitempty"`
}

QueryResult describes read-only query output.

type StaticProvider

type StaticProvider struct {
	Connections []DatabaseConnection
	Schemas     map[string]DatabaseSchema
	Queries     map[string]QueryResult
	Logs        []LogEntry
	BaseURLs    map[string]string
	Browser     []BrowserLogEntry
	Metrics     map[string]MetricsMetadata
}

StaticProvider is an in-memory diagnostics provider for tests and adapters.

func (StaticProvider) AbsoluteURL

func (p StaticProvider) AbsoluteURL(_ context.Context, req URLRequest) (string, error)

AbsoluteURL resolves a local app URL.

func (StaticProvider) BrowserLogs

BrowserLogs returns bounded static browser log entries.

func (StaticProvider) DatabaseConnections

func (p StaticProvider) DatabaseConnections(context.Context) ([]DatabaseConnection, error)

DatabaseConnections returns static connection metadata.

func (StaticProvider) DatabaseQuery

func (p StaticProvider) DatabaseQuery(_ context.Context, req QueryRequest) (QueryResult, error)

DatabaseQuery returns a static query result after enforcing read-only SQL.

func (StaticProvider) DatabaseSchema

func (p StaticProvider) DatabaseSchema(_ context.Context, connection string) (DatabaseSchema, error)

DatabaseSchema returns static schema metadata.

func (StaticProvider) LastError

func (p StaticProvider) LastError(context.Context) (LogEntry, bool, error)

LastError returns the latest error-level log entry.

func (StaticProvider) LogEntries

func (p StaticProvider) LogEntries(_ context.Context, req LogRequest) ([]LogEntry, error)

LogEntries returns bounded static log entries.

func (StaticProvider) MetricsMetadata

MetricsMetadata returns static metrics metadata.

type Table

type Table struct {
	Name    string   `json:"name"`
	Columns []Column `json:"columns,omitempty"`
	Indexes []Index  `json:"indexes,omitempty"`
}

Table describes one database table.

type URLRequest

type URLRequest struct {
	App  string `json:"app,omitempty"`
	Path string `json:"path,omitempty"`
}

URLRequest describes a local app URL lookup.

Jump to

Keyboard shortcuts

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