Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/openstatusHQ/openstatus. ๐ซ Status page with uptime monitoring & API monitoring as code ๐ซ openstatus.dev
bun drizzle-orm monitoring monitoring-as-code nextjs observability on-call open-source shadcn-ui status-page statuspage synthetic-monitoring tinybird turso uptime uptime-checker uptime-monitor
Something went wrong. Try again.
2.7 kB ยท 78 lines
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879package server
import ( "errors" "fmt"
"connectrpc.com/connect" private_locationv1 "github.com/openstatushq/openstatus/apps/private-location/proto/private_location/v1")
// Validation errorsvar ( ErrEmptyMonitorID = errors.New("monitor_id is required") ErrEmptyID = errors.New("id is required") ErrInvalidLatency = errors.New("latency must be non-negative") ErrInvalidTimestamp = errors.New("timestamp must be positive") ErrInvalidGRPCCode = errors.New("grpc_code must be a canonical gRPC status code") ErrInvalidErrorFlag = errors.New("error must be 0 or 1"))
// maxGRPCStatusCode is UNAUTHENTICATED, the highest canonical code.const maxGRPCStatusCode = 16
// validateIngestCommon holds the rules every ingest request shares. Keeping one// copy stops the per-type validators drifting as the rules change.func validateIngestCommon(monitorID string, latency, timestamp int64) error { if monitorID == "" { return ErrEmptyMonitorID } if latency < 0 { return ErrInvalidLatency } if timestamp <= 0 { return ErrInvalidTimestamp } return nil}
// ValidateIngestHTTPRequest validates an HTTP ingest requestfunc ValidateIngestHTTPRequest(req *private_locationv1.IngestHTTPRequest) error { return validateIngestCommon(req.MonitorId, req.Latency, req.Timestamp)}
// ValidateIngestTCPRequest validates a TCP ingest requestfunc ValidateIngestTCPRequest(req *private_locationv1.IngestTCPRequest) error { return validateIngestCommon(req.MonitorId, req.Latency, req.Timestamp)}
// ValidateIngestDNSRequest validates a DNS ingest requestfunc ValidateIngestDNSRequest(req *private_locationv1.IngestDNSRequest) error { return validateIngestCommon(req.MonitorId, req.Latency, req.Timestamp)}
// ValidateIngestICMPRequest validates an ICMP ingest requestfunc ValidateIngestICMPRequest(req *private_locationv1.IngestICMPRequest) error { return validateIngestCommon(req.MonitorId, req.Latency, req.Timestamp)}
// ValidateIngestGRPCRequest validates a gRPC ingest request. The two numeric// fields are narrowed on the way into the Tinybird row, so they are bounded// here rather than wrapping silently.func ValidateIngestGRPCRequest(req *private_locationv1.IngestGRPCRequest) error { if err := validateIngestCommon(req.MonitorId, req.Latency, req.Timestamp); err != nil { return err } if req.GrpcCode < 0 || req.GrpcCode > maxGRPCStatusCode { return ErrInvalidGRPCCode } if req.Error < 0 || req.Error > 1 { return ErrInvalidErrorFlag } return nil}
// NewValidationError creates a Connect error for validation failuresfunc NewValidationError(err error) *connect.Error { return connect.NewError(connect.CodeInvalidArgument, fmt.Errorf("validation error: %w", err))}