views

package
v0.2.0-beta.4 Latest Latest
Warning

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

Go to latest
Published: May 3, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package views provides explicit JSON view models for the HTTP API.

Handlers MUST NOT serialize GORM storage models directly — doing so leaks ORM bookkeeping (CreatedAt, UpdatedAt, DeletedAt) and tenant_id to the wire, and couples the UI contract to the schema. Each type here is the stable JSON shape consumed by the UI and by MCP clients.

Rules:

  • No GORM bookkeeping fields (DeletedAt, CreatedAt, UpdatedAt).
  • No tenant_id — auth already scopes the request.
  • Preserve JSON field names that consumers rely on.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AffectedEntry

type AffectedEntry struct {
	Service     string  `json:"service"`
	Depth       int     `json:"depth"`
	CallCount   int64   `json:"call_count"`
	ImpactScore float64 `json:"impact_score"`
}

AffectedEntry is a service affected by an upstream failure.

type AnomalyNode

type AnomalyNode struct {
	ID        string    `json:"id"`
	Type      string    `json:"type"`
	Severity  string    `json:"severity"`
	Service   string    `json:"service"`
	Evidence  string    `json:"evidence"`
	Timestamp time.Time `json:"timestamp"`
}

AnomalyNode is an anomaly detected by the anomaly engine.

func AnomalyNodeFromModel

func AnomalyNodeFromModel(a graphrag.AnomalyNode) AnomalyNode

AnomalyNodeFromModel converts a GraphRAG anomaly node into its view.

type DashboardStats

type DashboardStats struct {
	TotalTraces        int64          `json:"total_traces"`
	TotalLogs          int64          `json:"total_logs"`
	TotalErrors        int64          `json:"total_errors"`
	AvgLatencyMs       float64        `json:"avg_latency_ms"`
	ErrorRate          float64        `json:"error_rate"`
	ActiveServices     int64          `json:"active_services"`
	P99Latency         int64          `json:"p99_latency"`
	TopFailingServices []ServiceError `json:"top_failing_services"`
}

DashboardStats is the aggregated dashboard metric view.

func DashboardStatsFromModel

func DashboardStatsFromModel(s *storage.DashboardStats) DashboardStats

DashboardStatsFromModel converts repo stats into the view form.

type GraphSnapshot

type GraphSnapshot struct {
	ID             string    `json:"id"`
	CreatedAt      time.Time `json:"created_at"`
	Nodes          any       `json:"nodes"`
	Edges          any       `json:"edges"`
	ServiceCount   int       `json:"service_count"`
	TotalCalls     int64     `json:"total_calls"`
	AvgHealthScore float64   `json:"avg_health_score"`
}

GraphSnapshot is the wire shape of a persisted topology snapshot.

func GraphSnapshotFromModel

func GraphSnapshotFromModel(m graphrag.GraphSnapshot) GraphSnapshot

GraphSnapshotFromModel converts a persisted GraphRAG snapshot into its view.

type ImpactResult

type ImpactResult struct {
	Service          string          `json:"service"`
	AffectedServices []AffectedEntry `json:"affected_services"`
	TotalDownstream  int             `json:"total_downstream"`
}

ImpactResult describes the blast radius of a service failure.

func ImpactResultFromModel

func ImpactResultFromModel(r *graphrag.ImpactResult) *ImpactResult

ImpactResultFromModel converts a GraphRAG impact result into its view.

type Investigation

type Investigation struct {
	ID               string    `json:"id"`
	CreatedAt        time.Time `json:"created_at"`
	Status           string    `json:"status"`
	Severity         string    `json:"severity"`
	TriggerService   string    `json:"trigger_service"`
	TriggerOperation string    `json:"trigger_operation"`
	ErrorMessage     string    `json:"error_message"`
	RootService      string    `json:"root_service"`
	RootOperation    string    `json:"root_operation"`
	CausalChain      any       `json:"causal_chain"`
	TraceIDs         any       `json:"trace_ids"`
	ErrorLogs        any       `json:"error_logs"`
	AnomalousMetrics any       `json:"anomalous_metrics"`
	AffectedServices any       `json:"affected_services"`
	SpanChain        any       `json:"span_chain"`
}

Investigation is the wire shape of an automated investigation record. The raw-JSON fields (CausalChain, TraceIDs, etc.) are passed through verbatim — they are already JSON on the wire.

func InvestigationFromModel

func InvestigationFromModel(m graphrag.Investigation) Investigation

InvestigationFromModel converts a persisted GraphRAG Investigation into its view. The RawMessage fields are unwrapped to `any` so JSON output is the decoded structure, not a base64 blob.

func InvestigationsFromModels

func InvestigationsFromModels(ms []graphrag.Investigation) []Investigation

InvestigationsFromModels is the slice form of InvestigationFromModel.

type Log

type Log struct {
	ID             uint      `json:"id"`
	TraceID        string    `json:"trace_id"`
	SpanID         string    `json:"span_id"`
	Severity       string    `json:"severity"`
	Body           string    `json:"body"`
	ServiceName    string    `json:"service_name"`
	AttributesJSON string    `json:"attributes_json"`
	AIInsight      string    `json:"ai_insight"`
	Timestamp      time.Time `json:"timestamp"`
}

Log is the wire shape of an ingested log record.

func LogFromModel

func LogFromModel(m storage.Log) Log

LogFromModel converts a storage.Log into its view.

func LogsFromModels

func LogsFromModels(ms []storage.Log) []Log

LogsFromModels is the slice form of LogFromModel.

type LogClusterNode

type LogClusterNode struct {
	ID             string           `json:"id"`
	Template       string           `json:"template"`
	TemplateID     uint64           `json:"template_id,omitempty"`
	TemplateTokens []string         `json:"template_tokens,omitempty"`
	SampleLog      string           `json:"sample_log,omitempty"`
	Count          int64            `json:"count"`
	FirstSeen      time.Time        `json:"first_seen"`
	LastSeen       time.Time        `json:"last_seen"`
	SeverityDist   map[string]int64 `json:"severity_distribution"`
}

LogClusterNode is the wire shape of a log cluster (Drain template).

func LogClusterNodeFromModel

func LogClusterNodeFromModel(n graphrag.LogClusterNode) LogClusterNode

LogClusterNodeFromModel converts a GraphRAG log cluster into its view.

type MetricBucket

type MetricBucket struct {
	ID             uint      `json:"id"`
	Name           string    `json:"name"`
	ServiceName    string    `json:"service_name"`
	TimeBucket     time.Time `json:"time_bucket"`
	Min            float64   `json:"min"`
	Max            float64   `json:"max"`
	Sum            float64   `json:"sum"`
	Count          int64     `json:"count"`
	AttributesJSON string    `json:"attributes_json"`
}

MetricBucket is the wire shape of a pre-aggregated metric window.

func MetricBucketFromModel

func MetricBucketFromModel(m storage.MetricBucket) MetricBucket

MetricBucketFromModel converts a storage.MetricBucket into its view.

func MetricBucketsFromModels

func MetricBucketsFromModels(ms []storage.MetricBucket) []MetricBucket

MetricBucketsFromModels is the slice form of MetricBucketFromModel.

type RootCauseInfo

type RootCauseInfo struct {
	Service      string `json:"service"`
	Operation    string `json:"operation"`
	ErrorMessage string `json:"error_message"`
	SpanID       string `json:"span_id"`
	TraceID      string `json:"trace_id"`
}

RootCauseInfo identifies the responsible service/operation behind an error chain.

func RootCauseInfoFromModel

func RootCauseInfoFromModel(r *graphrag.RootCauseInfo) *RootCauseInfo

RootCauseInfoFromModel converts a GraphRAG root-cause node into its view.

type ServiceError

type ServiceError struct {
	ServiceName string  `json:"service_name"`
	ErrorCount  int64   `json:"error_count"`
	TotalCount  int64   `json:"total_count"`
	ErrorRate   float64 `json:"error_rate"`
}

ServiceError is the top-failing-service entry on the dashboard.

type ServiceMapEdge

type ServiceMapEdge struct {
	Source       string  `json:"source"`
	Target       string  `json:"target"`
	CallCount    int64   `json:"call_count"`
	AvgLatencyMs float64 `json:"avg_latency_ms"`
	ErrorRate    float64 `json:"error_rate"`
}

ServiceMapEdge is an edge on the service topology view.

type ServiceMapMetrics

type ServiceMapMetrics struct {
	Nodes []ServiceMapNode `json:"nodes"`
	Edges []ServiceMapEdge `json:"edges"`
}

ServiceMapMetrics is the full topology view.

func ServiceMapMetricsFromModel

func ServiceMapMetricsFromModel(m *storage.ServiceMapMetrics) ServiceMapMetrics

ServiceMapMetricsFromModel converts repo topology into the view form.

type ServiceMapNode

type ServiceMapNode struct {
	Name         string  `json:"name"`
	TotalTraces  int64   `json:"total_traces"`
	ErrorCount   int64   `json:"error_count"`
	AvgLatencyMs float64 `json:"avg_latency_ms"`
}

ServiceMapNode is a node on the service topology view.

type Span

type Span struct {
	ID             uint      `json:"id"`
	TraceID        string    `json:"trace_id"`
	SpanID         string    `json:"span_id"`
	ParentSpanID   string    `json:"parent_span_id"`
	OperationName  string    `json:"operation_name"`
	StartTime      time.Time `json:"start_time"`
	EndTime        time.Time `json:"end_time"`
	Duration       int64     `json:"duration"`
	ServiceName    string    `json:"service_name"`
	AttributesJSON string    `json:"attributes_json"`
}

Span is the wire shape of a single operation inside a trace.

func SpanFromModel

func SpanFromModel(m storage.Span) Span

SpanFromModel converts a storage.Span into its view.

func SpansFromModels

func SpansFromModels(ms []storage.Span) []Span

SpansFromModels is the slice form of SpanFromModel.

type Trace

type Trace struct {
	ID          uint      `json:"id"`
	TraceID     string    `json:"trace_id"`
	ServiceName string    `json:"service_name"`
	Operation   string    `json:"operation"`
	Status      string    `json:"status"`
	Duration    int64     `json:"duration"` // microseconds, preserved for legacy consumers
	DurationMs  float64   `json:"duration_ms"`
	SpanCount   int       `json:"span_count"`
	Timestamp   time.Time `json:"timestamp"`
	Spans       []Span    `json:"spans,omitempty"`
	Logs        []Log     `json:"logs,omitempty"`
}

Trace is the wire shape of a distributed trace summary.

func TraceFromModel

func TraceFromModel(m storage.Trace) Trace

TraceFromModel converts a storage.Trace (with possibly-Preloaded children) into its wire-facing view.

func TracesFromModels

func TracesFromModels(ms []storage.Trace) []Trace

TracesFromModels is the slice form of TraceFromModel.

type TracesResponse

type TracesResponse struct {
	Traces []Trace `json:"traces"`
	Total  int64   `json:"total"`
	Limit  int     `json:"limit"`
	Offset int     `json:"offset"`
}

TracesResponse is the paginated trace-list response.

func TracesResponseFromModel

func TracesResponseFromModel(r *storage.TracesResponse) TracesResponse

TracesResponseFromModel wraps a repo TracesResponse into the view form.

Jump to

Keyboard shortcuts

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