pathfilter

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package pathfilter implements the Phase A "path-filter" plugin: an ObserveOnFinalize plugin that drops traces whose Path matches any operator-configured pattern.

Pattern semantics match the display-side filter the viewer already uses (see ROADMAP § 4 "path noise filter" + commit 5cbdda1):

  • Exact match: pattern "/api/v1/auth/me" matches Path "/api/v1/auth/me" only.
  • Prefix match via trailing "*": pattern "/api/v1/*" matches "/api/v1", "/api/v1/auth/me", "/api/v1/anything".
  • The lone pattern "*" disables the plugin (matches everything; would drop every trace — operators almost certainly don't want this, so we treat it as a config bug and reject it at Init).

Why match the display-side semantics: the viewer's path input and the capture-side skip both want to express the same operator intent ("ignore admin UI polling on /api/v1/*"). Identical syntax means the operator copies the same string into both places. Glob libraries (path.Match, doublestar) would be over-engineered for the v0 surface — two cases is enough.

Index

Constants

View Source
const Name = "path-filter"

Name is the plugin identifier used in config and telemetry.

Variables

This section is empty.

Functions

func MatchAny added in v0.1.2

func MatchAny(patterns []Pattern, path string) bool

MatchAny is the common multi-pattern check sibling plugins want. Returns true on the first matching pattern; false when none match or when patterns is empty.

Types

type Config

type Config struct {
	// Patterns is the list of paths to drop from recording. Exact match
	// or trailing-"*" prefix match per the package doc.
	Patterns []string `yaml:"patterns"`
}

Config is the YAML subtree under plugins.config.path-filter.

Defaults: zero value (Patterns: nil) is a no-op plugin that records every trace. The operator opts in by listing patterns.

type Pattern added in v0.1.2

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

Pattern is a parsed Config.Patterns entry. Exported so sibling plugins (e.g. internal/plugin/builtin/capturefilter) can reuse the compile + match logic without owning a duplicate copy of the parser.

Fields are package-private — callers use Matches.

func Compile added in v0.1.2

func Compile(patterns []string) ([]Pattern, error)

Compile parses operator-supplied pattern strings into Patterns, enforcing the same validation pathfilter.Plugin.Init enforces:

  • Empty strings are rejected.
  • The lone "*" pattern is rejected (would match everything).
  • Trailing "*" → prefix match on the leading body.
  • No "*" → exact match.

patterns is the operator-facing []string. The slice may be nil or empty; either yields a nil result + nil error so callers can use the same code path for "no patterns configured" as for "operator listed patterns".

func (Pattern) Matches added in v0.1.2

func (p Pattern) Matches(path string) bool

Matches returns true when path satisfies the pattern.

  • Exact form: path equality.
  • Trailing-"*" form: strings.HasPrefix on the body.

func (Pattern) Raw added in v0.1.2

func (p Pattern) Raw() string

Raw returns the operator-facing pattern string (e.g. "/api/v1/*"), useful for log + telemetry. The empty string indicates a zero Pattern.

type Plugin

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

Plugin is the path-filter implementation. It satisfies plugin.Plugin and plugin.ObserveOnFinalize. Construction is trivial; the patterns are compiled in Init.

func New

func New() *Plugin

New returns an uninitialized Plugin. The caller (Registry) MUST call Init before invoking OnFinalize — calling OnFinalize on a fresh Plugin yields shouldRecord=true (no patterns means nothing matches).

func (*Plugin) Close

func (p *Plugin) Close() error

Close is a no-op for path-filter; there is no buffered state.

func (*Plugin) Init

func (p *Plugin) Init(cfg map[string]any) error

Init parses cfg into compiled patterns. cfg is the raw map form produced by YAML unmarshaling at the plugin.Registry layer.

Accepted shape:

{"patterns": ["/api/v1/*", "/api/v1/auth/me"]}

nil cfg = no patterns = the plugin is a no-op; an absent block is the same as an explicit empty block.

Returns an error on:

  • Wrong type for "patterns" (not a list or list elements not strings).
  • The lone pattern "*" (operator config bug — would drop every trace).

func (*Plugin) Name

func (p *Plugin) Name() string

Name returns the constant plugin identifier.

func (*Plugin) OnFinalize

func (p *Plugin) OnFinalize(_ context.Context, tr trace.Trace) (bool, error)

OnFinalize returns shouldRecord=false when tr.Path matches any of the configured patterns, shouldRecord=true otherwise. The error return is always nil for path-filter — pattern matching cannot fail at runtime once patterns compile cleanly in Init.

The context is accepted to honor the plugin interface contract but is not consulted; matching is non-blocking and cheap.

Renamed from BeforeRecord per plugin-b-c-spec §7.3 (Phase A migration).

Jump to

Keyboard shortcuts

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