lib

package
v0.0.0-...-ace29c2 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func UpdateAnalyticsBQSchema

func UpdateAnalyticsBQSchema(ctx context.Context, project, dataset, table string) error

UpdateAnalyticsBQSchema updates the bigquery schema if fields are added.

func UpdateReportsBQSchema

func UpdateReportsBQSchema(ctx context.Context, project, dataset, table string) error

UpdateReportsBQSchema updates the bigquery schema if fields are added.

func WriteAnalyticsToBigQuery

func WriteAnalyticsToBigQuery(ctx context.Context, project, dataset, table string, data []*WebVital) error

WriteAnalyticsToBigQuery saves a webvital to bq.

func WriteReportToBigQuery

func WriteReportToBigQuery(ctx context.Context, project, dataset, table string, reports []*Report) error

WriteReportToBigQuery saves a copy of a report to BQ.

Types

type CSPReport

type CSPReport struct {
	CSPReport struct {
		DocumentURI        string `json:"document-uri"`
		Referer            string `json:"referrer"`
		ViolatedDirective  string `json:"violated-directive"`
		EffectiveDirective string `json:"effective-directive"`
		OriginalPolicy     string `json:"original-policy"`
		BlockedURI         string `json:"blocked-uri"`
		StatusCode         int    `json:"status-code"`
		SourceFile         string `json:"source-file"`
		LineNumber         int    `json:"line-number"`
		ColumnNumber       int    `json:"column-number"`
	} `json:"csp-report"`
}

CSPReport is the struct for CSP errors. Spec is at https://www.w3.org/TR/CSP3/#violation.

type ExpectCTReport

type ExpectCTReport struct {
	ExpectCTReport ExpectCTSubReport `json:"expect-ct-report"`
}

ExpectCTReport is the struct for Expect-CT errors.

type ExpectCTSubReport

type ExpectCTSubReport struct {
	DateTime                  time.Time `json:"date-time"`
	EffectiveExpirationDate   time.Time `json:"effective-expiration-date"`
	Hostname                  string    `json:"hostname"`
	Port                      int       `json:"port"`
	Scts                      []string  `json:"scts"`
	ServedCertificateChain    []string  `json:"served-certificate-chain"`
	ValidatedCertificateChain []string  `json:"validated-certificate-chain"`
}

ExpectCTSubReport is the internal datastructure of an ExpectCTReport.

type Report

type Report struct {
	ExpectCT *ExpectCTReport `bigquery:",nullable"`
	CSP      *CSPReport      `bigquery:",nullable"`
	ReportTo []*ReportToReport

	// When we recorded this metric.
	Time bigquery.NullDateTime

	// What service this is for.
	Service bigquery.NullString
}

Report is a simple interface for types exported by ParseReport.

func ParseReport

func ParseReport(ct, body, srv string) (*Report, error)

ParseReport takes a content-type header and a body json string and parses it into valid Go structs.

type ReportToReport

type ReportToReport struct {
	Type      string `json:"type"`
	Age       int    `json:"age"`
	URL       string `json:"url"`
	UserAgent string `json:"user_agent"`
	Body      struct {
		AnticipatedRemoval float64 `json:"anticipatedRemoval,omitempty"`
		Blocked            string  `json:"blocked,omitempty"`
		BlockedURL         string  `json:"blockedURL,omitempty"`
		ColumnNumber       int64   `json:"columnNumber,omitempty"`
		Directive          string  `json:"directive,omitempty"`
		Disposition        string  `json:"disposition,omitempty"`
		DocumentURL        string  `json:"documentURL,omitempty"`
		EffectiveDirective string  `json:"effectiveDirective,omitempty"`
		ElapsedTime        int64   `json:"elapsed_time,omitempty"`
		ID                 string  `json:"id,omitempty"`
		LineNumber         int64   `json:"lineNumber,omitempty"`
		Message            string  `json:"message,omitempty"`
		Method             string  `json:"method,omitempty"`
		OriginalPolicy     string  `json:"originalPolicy,omitempty"`
		Phase              string  `json:"phase,omitempty"`
		Policy             string  `json:"policy,omitempty"`
		Protocol           string  `json:"protocol,omitempty"`
		Reason             string  `json:"reason,omitempty"`
		Referrer           string  `json:"referrer,omitempty"`
		SamplingFraction   float64 `json:"sampling_fraction,omitempty"`
		ServerIP           string  `json:"server_ip,omitempty"`
		SourceFile         string  `json:"sourceFile,omitempty"`
		Status             int64   `json:"status,omitempty"`
		StatusCode         int64   `json:"status_code,omitempty"`
		Type               string  `json:"type,omitempty"`
	} `json:"body"`
}

ReportToReport is the struct for generic reports via the Reporting API. TODO: There are multiple ways browsers send the field statuscode!

type WebVital

type WebVital struct {
	// The name of the metric (in acronym form).
	Name string `json:"name"`

	// The current value of the metric.
	Value float64 `json:"value"`

	// The delta between the current value and the last-reported value.
	// On the first report, `delta` and `value` will always be the same.
	Delta float64 `json:"delta"`

	// A unique ID representing this particular metric that's specific to the
	// current page. This ID can be used by an analytics tool to dedupe
	// multiple values sent for the same metric, or to group multiple deltas
	// together and calculate a total.
	ID string `json:"id"`

	// Type of metric (web-vital or custom).
	Label bigquery.NullString `json:"label"`

	// When we recorded this metric.
	Time bigquery.NullDateTime

	// What service this is for.
	Service bigquery.NullString
}

WebVital is a a version of https://web.dev/vitals/.

See also https://nextjs.org/docs/advanced-features/measuring-performance#build-your-own.

func ParseAnalytics

func ParseAnalytics(body, service string) (*WebVital, error)

ParseAnalytics parses a webvitals request body.

Jump to

Keyboard shortcuts

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