server

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package server implements the gRPC service for time series data querying.

The server provides:

  • Time series data querying with various aggregations
  • Request validation and error handling
  • Middleware support for:
  • Request rate limiting
  • Response caching
  • Metrics collection
  • Logging
  • Context management
  • Prometheus metrics integration
  • gRPC reflection for debugging

Example Usage:

config := DefaultServerConfig()
repo := database.NewTimeScaleDB(...)

server, err := SetupServer(repo, config)
if err != nil {
    log.Fatalf("Failed to setup server: %v", err)
}

lis, err := net.Listen("tcp", ":50051")
if err != nil {
    log.Fatalf("Failed to listen: %v", err)
}

if err := server.Serve(lis); err != nil {
    log.Fatalf("Failed to serve: %v", err)
}

Index

Constants

View Source
const (
	Window1m = "1m"
	Window5m = "5m"
	Window1h = "1h"
	Window1d = "1d"

	AggregationMin = "MIN"
	AggregationMax = "MAX"
	AggregationAvg = "AVG"
	AggregationSum = "SUM"
)

Variables

This section is empty.

Functions

func ConfigureGRPCServer

func ConfigureGRPCServer(
	repo DataRepository,
	opts ...grpc.ServerOption,
) *grpc.Server

gRPC Server Configuration without the middleware (for development and debug only)

func SetupServer

func SetupServer(repo DataRepository, config ServerConfig) (*grpc.Server, error)

SetupServer initializes and configures the gRPC server with all middleware

func SetupServerWithRegistry

func SetupServerWithRegistry(repo DataRepository, logger *logrus.Logger, reg prometheus.Registerer) (*grpc.Server, error)

SetupServerWithRegistry initializes the server with a custom registry

Types

type DataPoint

type DataPoint struct {
	Time  time.Time
	Value float64
}

DataPoint represents a generic time series data point

type DataRepository

type DataRepository interface {
	Query(
		ctx context.Context,
		start, end time.Time,
		window string,
		aggregation string,
	) ([]DataPoint, error)
}

DataRepository defines the interface for data access

type RequestValidator

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

func NewRequestValidator

func NewRequestValidator() *RequestValidator

func (*RequestValidator) Validate

func (v *RequestValidator) Validate(start, end time.Time, window, aggregation string) error

Validate checks if the request parameters are valid

type ServerConfig

type ServerConfig struct {
	CacheSize      int     // Size of the LRU cache
	RateLimit      float64 // Requests per second
	RateLimitBurst int     // Maximum burst size for rate limiting
}

ServerConfig holds configuration options for the gRPC server. It controls caching, rate limiting, and other server behaviors.

func DefaultServerConfig

func DefaultServerConfig() ServerConfig

DefaultServerConfig returns a ServerConfig with sensible defaults

type TimeSeriesService

type TimeSeriesService struct {
	pb.UnimplementedTimeSeriesServiceServer
	// contains filtered or unexported fields
}

TimeSeriesService implements the gRPC service for querying time series data. It handles request validation, data retrieval, and response formatting.

func NewTimeSeriesService

func NewTimeSeriesService(repo DataRepository) *TimeSeriesService

NewTimeSeriesService creates a new service instance

func (*TimeSeriesService) QueryTimeSeries

func (s *TimeSeriesService) QueryTimeSeries(
	ctx context.Context,
	req *pb.TimeSeriesRequest,
) (*pb.TimeSeriesResponse, error)

QueryTimeSeries retrieves time series data based on the provided request parameters. It supports various time windows and aggregation methods.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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