Documentation
¶
Overview ¶
Package server provides the core server infrastructure for the MCP Prometheus server.
This package contains: - ServerContext: Configuration and shared resources management - Logger interface: Structured logging abstraction - Configuration options: Functional options pattern for server setup
The ServerContext manages the lifecycle of the server and provides thread-safe access to configuration options such as: - Debug mode toggle - Dry run simulation mode - Prometheus connection settings - Authentication credentials
Example usage:
ctx := context.Background()
serverContext, err := server.NewServerContext(ctx,
server.WithDebugMode(true),
server.WithLogger(logger),
)
Index ¶
- type PrometheusConfig
- type ServerContext
- func (sc *ServerContext) Context() context.Context
- func (sc *ServerContext) IsOAuthEnabled() bool
- func (sc *ServerContext) Logger() *slog.Logger
- func (sc *ServerContext) PrometheusConfig() PrometheusConfig
- func (sc *ServerContext) Shutdown() error
- func (sc *ServerContext) TenancyResolver() TenancyResolver
- type ServerOption
- type TenancyResolver
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type PrometheusConfig ¶
type PrometheusConfig struct {
URL string
Username string
Password string
Token string
OrgID string
// TLS configuration
TLSSkipVerify bool // PROMETHEUS_TLS_SKIP_VERIFY — disable TLS certificate verification
TLSCACert string // PROMETHEUS_TLS_CA_CERT — path to a PEM-encoded CA certificate file
}
PrometheusConfig holds the Prometheus server configuration
type ServerContext ¶
type ServerContext struct {
// contains filtered or unexported fields
}
ServerContext holds the server configuration and shared resources
func NewServerContext ¶
func NewServerContext(ctx context.Context, opts ...ServerOption) (*ServerContext, error)
NewServerContext creates a new server context with the given options
func (*ServerContext) Context ¶
func (sc *ServerContext) Context() context.Context
Context returns the context associated with the server
func (*ServerContext) IsOAuthEnabled ¶ added in v0.0.21
func (sc *ServerContext) IsOAuthEnabled() bool
IsOAuthEnabled returns whether OAuth 2.1 middleware is active.
func (*ServerContext) Logger ¶
func (sc *ServerContext) Logger() *slog.Logger
Logger returns the configured structured logger.
func (*ServerContext) PrometheusConfig ¶
func (sc *ServerContext) PrometheusConfig() PrometheusConfig
PrometheusConfig returns the Prometheus configuration
func (*ServerContext) Shutdown ¶
func (sc *ServerContext) Shutdown() error
Shutdown gracefully shuts down the server context
func (*ServerContext) TenancyResolver ¶ added in v0.0.21
func (sc *ServerContext) TenancyResolver() TenancyResolver
TenancyResolver returns the configured tenancy resolver, or nil when tenancy is disabled.
type ServerOption ¶
type ServerOption func(*ServerContext)
ServerOption is a functional option for configuring ServerContext
func WithOAuthEnabled ¶ added in v0.0.21
func WithOAuthEnabled(enabled bool) ServerOption
WithOAuthEnabled marks the server as running behind OAuth 2.1 middleware. When true, tool handlers will attempt to extract user info from the request context to perform tenancy resolution.
func WithPrometheusConfig ¶
func WithPrometheusConfig(config PrometheusConfig) ServerOption
WithPrometheusConfig sets the Prometheus configuration
func WithSlogLogger ¶ added in v0.0.54
func WithSlogLogger(logger *slog.Logger) ServerOption
WithSlogLogger sets the structured logger for the server context.
func WithTenancyResolver ¶ added in v0.0.21
func WithTenancyResolver(r TenancyResolver) ServerOption
WithTenancyResolver attaches a tenancy resolver used by tools to map authenticated user groups to Mimir X-Scope-OrgID values.
type TenancyResolver ¶ added in v0.0.21
type TenancyResolver interface {
TenantsForGroups(ctx context.Context, groups []string) ([]string, error)
}
TenancyResolver resolves Mimir tenant IDs from a set of authenticated user groups. It is implemented by [tenancy.Resolver] and exposed here as an interface to avoid a direct import cycle between the server and tenancy packages.