webvitals

package
v0.16.521 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package webvitals is how the page tells the server how fast it was: the time from opening Sinopia's home to every card drawn, and the largest contentful paint. The page sends one small POST per number; the hub counts it in a histogram (harnessly_hub_web_vital_seconds{name}) and a runtime without a hub writes it to its own journal. The set of names is closed: a name nobody listed is dropped, so a label never grows from what a client sends.

Index

Constants

View Source
const (
	SinopiaHomeFull = "sinopia_home_full" // from opening the home to all its cards drawn
	LCP             = "lcp"               // largest contentful paint of the page
)

The names the page may send.

View Source
const MaxSeconds = 120

MaxSeconds is the longest time taken as a measurement; a tab left in the background for an hour says nothing of speed.

Variables

View Source
var Names = [...]string{SinopiaHomeFull, LCP}

Names is the closed set, in the order the metric lists them.

Functions

func Known

func Known(name string) bool

Known says the name is in the closed set.

func Serve

func Serve(w http.ResponseWriter, r *http.Request, lim *Limiter, key string, sink func(Sample))

Serve answers one report: POST {name, seconds}. A sample that passes is given to sink; a name nobody listed or a time that cannot be one is answered 204 and dropped (the page has nothing to fix), a bad body is 400, too many reports from one key 429. key names who sends (the person, the address).

Types

type Limiter

type Limiter struct {
	Max    int
	Window time.Duration
	// contains filtered or unexported fields
}

Limiter lets one key send so many reports in a window; the rest are dropped.

func NewLimiter

func NewLimiter() *Limiter

NewLimiter is 60 reports a minute for one key: a page sends a couple in a visit.

func (*Limiter) Allow

func (l *Limiter) Allow(key string, now time.Time) bool

Allow counts a report of the key and says whether it may pass.

type Sample

type Sample struct {
	Name    string  `json:"name"`
	Seconds float64 `json:"seconds"`
}

Sample is one number of the page.

func (Sample) Valid

func (s Sample) Valid() bool

Valid says the sample is a name of the set and a time that can be one.

Jump to

Keyboard shortcuts

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