Documentation
¶
Index ¶
- Variables
- type AccessLogContributor
- type AccessLogCountryStat
- type AccessLogDetailView
- type AccessLogQuery
- type AccessLogView
- type HTTPHandler
- func (h *HTTPHandler) GetAccessLog(ctx context.Context, request httpapi.GetAccessLogRequestObject) (httpapi.GetAccessLogResponseObject, error)
- func (h *HTTPHandler) GetAccessLogByCountry(ctx context.Context, request httpapi.GetAccessLogByCountryRequestObject) (httpapi.GetAccessLogByCountryResponseObject, error)
- func (h *HTTPHandler) GetAccessLogEntry(ctx context.Context, request httpapi.GetAccessLogEntryRequestObject) (httpapi.GetAccessLogEntryResponseObject, error)
- func (h *HTTPHandler) GetAccessLogHistogram(ctx context.Context, request httpapi.GetAccessLogHistogramRequestObject) (httpapi.GetAccessLogHistogramResponseObject, error)
- type Repository
- func (r *Repository) BatchInsert(ctx context.Context, events []policy.DecisionEvent) error
- func (r *Repository) DeleteOlderThan(ctx context.Context, before time.Time) (int64, error)
- func (r *Repository) GetAccessLogEntry(ctx context.Context, id int64) (AccessLogDetailView, error)
- func (r *Repository) GetAccessLogHistogram(ctx context.Context, q AccessLogQuery) (httpapi.AccessLogHistogramResponse, error)
- func (r *Repository) ListAccessLog(ctx context.Context, q AccessLogQuery) ([]AccessLogView, int, error)
- func (r *Repository) ListAccessLogStatsByCountry(ctx context.Context, from, to time.Time) ([]AccessLogCountryStat, error)
- func (r *Repository) ListDenyReasons(ctx context.Context) ([]string, error)
- type Sink
Constants ¶
This section is empty.
Variables ¶
var ErrEntryNotFound = errors.New("access log entry not found")
ErrEntryNotFound reports that no access_log row carries the requested id. Entries are pruned by retention (DeleteOlderThan), so a link to an old request resolving to this is an ordinary outcome, not a failure.
Functions ¶
This section is empty.
Types ¶
type AccessLogContributor ¶ added in v0.7.0
type AccessLogContributor struct {
DeviceID *ids.DeviceID
DeviceName *string
UserID *ids.UserID
UserName *string
AddressID *ids.AddressID
}
AccessLogContributor is one device/user/address a request's client IP resolved to. Fields are always populated (contributor rows are fully constrained) but carried as pointers to mirror the API shape.
type AccessLogCountryStat ¶ added in v0.7.0
type AccessLogCountryStat struct {
CountryCode string
CountryName string
Total int64
Allowed int64
Denied int64
}
AccessLogCountryStat holds aggregated request counts for a single country.
type AccessLogDetailView ¶ added in v0.7.0
type AccessLogDetailView struct {
AccessLogView
XFFChain *string
Headers map[string][]string
CountryName *string
ContinentCode *string
ASN *int64
ASNOrg *string
}
AccessLogDetailView is the whole record of one request: the table row plus the fields only the detail view shows.
type AccessLogQuery ¶ added in v0.7.0
type AccessLogQuery struct {
From time.Time
To time.Time
Outcome *bool
Filters []filterx.Filter
Sort string
Order string
Cursor *filterx.Cursor
Limit int
}
AccessLogQuery is the validated, normalized form of the list request. Sort and Order always hold effective values; Cursor is nil on the first page. The histogram shares Filters, Outcome and the window, and leaves the rest zero.
func NewAccessLogHistogramQuery ¶ added in v0.7.0
func NewAccessLogHistogramQuery(params httpapi.GetAccessLogHistogramParams) (AccessLogQuery, error)
NewAccessLogHistogramQuery validates and normalizes GET /access-log/histogram params. A histogram has no page and no ordering, so sort, order, limit and cursor are absent by design.
func NewAccessLogQuery ¶ added in v0.7.0
func NewAccessLogQuery(params httpapi.GetAccessLogParams) (AccessLogQuery, error)
NewAccessLogQuery validates and normalizes GET /access-log params, resolving the page's sort, order, cursor and limit on top of the shared filter set.
type AccessLogView ¶ added in v0.7.0
type AccessLogView struct {
ID int64
ClientIP string
Outcome bool
DenyReason *string
Contributors []AccessLogContributor
ContributorCount int
CreatedAt time.Time
DurationUs int64
TargetHost *string
TargetURI *string
HTTPMethod *string
CountryCode *string
NetworkPolicyID *int64
NetworkPolicyName *string
}
AccessLogView is one row of the access-log table.
type HTTPHandler ¶
type HTTPHandler struct {
// contains filtered or unexported fields
}
func NewHTTPHandler ¶
func NewHTTPHandler(repo *Repository, logger *slog.Logger) *HTTPHandler
func (*HTTPHandler) GetAccessLog ¶ added in v0.7.0
func (h *HTTPHandler) GetAccessLog( ctx context.Context, request httpapi.GetAccessLogRequestObject, ) (httpapi.GetAccessLogResponseObject, error)
func (*HTTPHandler) GetAccessLogByCountry ¶ added in v0.7.0
func (h *HTTPHandler) GetAccessLogByCountry( ctx context.Context, request httpapi.GetAccessLogByCountryRequestObject, ) (httpapi.GetAccessLogByCountryResponseObject, error)
func (*HTTPHandler) GetAccessLogEntry ¶ added in v0.7.0
func (h *HTTPHandler) GetAccessLogEntry( ctx context.Context, request httpapi.GetAccessLogEntryRequestObject, ) (httpapi.GetAccessLogEntryResponseObject, error)
func (*HTTPHandler) GetAccessLogHistogram ¶ added in v0.7.0
func (h *HTTPHandler) GetAccessLogHistogram( ctx context.Context, request httpapi.GetAccessLogHistogramRequestObject, ) (httpapi.GetAccessLogHistogramResponseObject, error)
type Repository ¶
type Repository struct {
// contains filtered or unexported fields
}
Repository owns the access log write path plus the read models over it — the list, one entry's detail, the histogram and the country rollup, each isolated in a *_view.go file (ADR-009).
func NewRepository ¶
func NewRepository(db *database.DB) *Repository
func (*Repository) BatchInsert ¶
func (r *Repository) BatchInsert(ctx context.Context, events []policy.DecisionEvent) error
func (*Repository) DeleteOlderThan ¶ added in v0.4.0
DeleteOlderThan removes access_log rows (and their children via CASCADE) with created_at before the given time. Returns the number of rows deleted from access_log.
func (*Repository) GetAccessLogEntry ¶ added in v0.7.0
func (r *Repository) GetAccessLogEntry(ctx context.Context, id int64) (AccessLogDetailView, error)
GetAccessLogEntry returns the full record of one request. It reports ErrEntryNotFound when the id is unknown, which retention pruning makes an ordinary answer for an old link rather than a failure.
func (*Repository) GetAccessLogHistogram ¶ added in v0.7.0
func (r *Repository) GetAccessLogHistogram(ctx context.Context, q AccessLogQuery) (httpapi.AccessLogHistogramResponse, error)
GetAccessLogHistogram answers the histogram endpoint: allow/deny counts per time bucket over exactly the rows GET /access-log lists for the same filters, contiguous across the whole window. Granularity follows the window size.
It always aggregates access_log itself, at every window width. The hourly rollups cannot serve it: they carry no user, device or policy attribution, so they can only answer the unfiltered case, and they exclude the in-flight hour — which would make the chart quietly disagree with the table beside it.
func (*Repository) ListAccessLog ¶ added in v0.7.0
func (r *Repository) ListAccessLog(ctx context.Context, q AccessLogQuery) ([]AccessLogView, int, error)
func (*Repository) ListAccessLogStatsByCountry ¶ added in v0.7.0
func (r *Repository) ListAccessLogStatsByCountry(ctx context.Context, from, to time.Time) ([]AccessLogCountryStat, error)
ListAccessLogStatsByCountry returns request counts grouped by country for all rows within the [from, to] time window. Only rows with GeoIP data are included.
Dispatches on rollup.RawWindowThreshold like every other traffic widget, so the map/country tables answer from the same source as the stat cards and charts for a given window.
func (*Repository) ListDenyReasons ¶
func (r *Repository) ListDenyReasons(ctx context.Context) ([]string, error)
type Sink ¶
type Sink struct {
// contains filtered or unexported fields
}
Sink receives DecisionEvents on a buffered channel and batch-inserts them.
func (*Sink) OnDecision ¶
func (s *Sink) OnDecision(_ context.Context, e policy.DecisionEvent)
OnDecision implements policy.DecisionObserver.