whevent

package
v1.136.0 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package whevent turns one accepted webhook request into the events a source stores, and renders them as the JSON-lines a segment holds (#1870).

An event is the envelope the receiver adds around what the sender posted: when it was received, which replica received it, the sender's id, type and key for it when the source says where to find them, and the posted JSON as text. The payload is never transformed: a reader extracts what it needs from it with json_extract_scalar, and a sender adding a field never changes the table.

Index

Constants

View Source
const FormPayloadField = "payload"

FormPayloadField is the form field a sender that posts application/x-www-form-urlencoded carries its JSON in.

View Source
const TimestampLayout = "2006-01-02 15:04:05.000000"

TimestampLayout is how a timestamp is written into a segment: the text the Hive JSON reader parses as a TIMESTAMP(6), in UTC.

Variables

View Source
var (
	ErrNotJSON       = errors.New("the body is not JSON")
	ErrNoPayload     = errors.New("the form has no payload field")
	ErrSplitNotArray = errors.New("the split path does not name an array in the body")
)

Refusals a body can meet. Each is answered 400 and nothing is stored.

View Source
var Columns = []string{
	"received_at", "landed_at", "event_id", "event_type", "key",
	"content_hash", "replica", "payload",
}

Columns are the columns every source's tables and view declare, in order. dt, hour and minute are the partition columns and are not written into a file.

Functions

func EncodeSegment

func EncodeSegment(events []Event, landedAt time.Time) ([]byte, error)

EncodeSegment renders events as gzipped JSON-lines, each stamped with landedAt.

func JSONBody

func JSONBody(contentType string, body []byte) ([]byte, error)

JSONBody returns the JSON a request carries: the body itself, or the payload field of a form. contentType is the request's Content-Type.

Types

type Event

type Event struct {
	ReceivedAt  time.Time
	EventID     string
	EventType   string
	Key         string
	ContentHash string
	Replica     string
	// Payload is the event's JSON, compacted.
	Payload []byte
}

Event is one stored event.

func Build

func Build(jsonBody []byte, paths Paths, receivedAt time.Time, replica string) ([]Event, error)

Build decodes a request's JSON and returns its events, all stamped with receivedAt and replica.

func (Event) Window

func (e Event) Window(length time.Duration) time.Time

Window is the start of the window of the given length the event is filed under: the window it was received in, in UTC.

type Paths

type Paths struct {
	Split, EventID, EventType, Key *jsonpath.Path
}

Paths are a source's parsed JSON paths. A nil path is unset.

func ParsePaths

func ParsePaths(c whsource.Config) (Paths, error)

ParsePaths reads the paths a source configures. Validation already refused a path that does not parse, so an error here is a source written around it.

type Stored

type Stored struct {
	Event
	LandedAt time.Time
}

Stored is one event read back from a segment, with the time the segment holding it was written.

func DecodeSegment

func DecodeSegment(data []byte) ([]Stored, error)

DecodeSegment reads a segment written by EncodeSegment.

Jump to

Keyboard shortcuts

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