Documentation
¶
Overview ¶
Package usagetypes contains the types for usage events. These are kept in their own package to avoid importing any real code from coderd.
Imports in this package should be limited to the standard library and the following packages ONLY:
- github.com/google/uuid
- golang.org/x/xerrors
This package is imported by the Tallyman codebase.
Index ¶
- Constants
- func ParseEvent(data json.RawMessage, out Event) error
- type DCManagedAgentsV1
- type DiscreteEvent
- type Event
- type TallymanV1IngestAcceptedEvent
- type TallymanV1IngestEvent
- type TallymanV1IngestRejectedEvent
- type TallymanV1IngestRequest
- type TallymanV1IngestResponse
- type TallymanV1Response
- type UnknownEventTypeError
- type UsageEventType
Constants ¶
const ( TallymanCoderLicenseKeyHeader = "Coder-License-Key" TallymanCoderDeploymentIDHeader = "Coder-Deployment-ID" )
Variables ¶
This section is empty.
Functions ¶
func ParseEvent ¶
func ParseEvent(data json.RawMessage, out Event) error
ParseEvent parses the raw event data into the provided event. It fails if there is any unknown fields or extra data at the end of the JSON. The returned event is validated.
Types ¶
type DCManagedAgentsV1 ¶
type DCManagedAgentsV1 struct {
Count uint64 `json:"count"`
}
DCManagedAgentsV1 is a discrete usage event for the number of managed agents. This event is sent in the following situations:
- Once on first startup after usage tracking is added to the product with the count of all existing managed agents (count=N)
- A new managed agent is created (count=1)
func (DCManagedAgentsV1) EventType ¶
func (DCManagedAgentsV1) EventType() UsageEventType
func (DCManagedAgentsV1) Fields ¶
func (e DCManagedAgentsV1) Fields() map[string]any
func (DCManagedAgentsV1) Valid ¶
func (e DCManagedAgentsV1) Valid() error
type DiscreteEvent ¶
type DiscreteEvent interface { Event // contains filtered or unexported methods }
DiscreteEvent is a usage event that is collected as a discrete event.
type Event ¶
type Event interface { EventType() UsageEventType Valid() error Fields() map[string]any // fields to be marshaled and sent to tallyman/Metronome // contains filtered or unexported methods }
Event is a usage event that can be collected by the usage collector.
Note that the following event types should not be updated once they are merged into the product. Please consult Dean before making any changes.
This type cannot be implemented outside of this package as it this package is the source of truth for the coder/tallyman repo.
func ParseEventWithType ¶
func ParseEventWithType(eventType UsageEventType, data json.RawMessage) (Event, error)
ParseEventWithType parses the raw event data into the specified Go type. It fails if there is any unknown fields or extra data after the event. The returned event is validated.
If the event type is unknown, UnknownEventTypeError is returned.
type TallymanV1IngestAcceptedEvent ¶
type TallymanV1IngestAcceptedEvent struct {
ID string `json:"id"`
}
TallymanV1IngestAcceptedEvent is an event that was accepted by the Tallyman API.
type TallymanV1IngestEvent ¶
type TallymanV1IngestEvent struct { ID string `json:"id"` EventType UsageEventType `json:"event_type"` EventData json.RawMessage `json:"event_data"` CreatedAt time.Time `json:"created_at"` }
TallymanV1IngestEvent is an event to be ingested into the Tallyman API.
func (TallymanV1IngestEvent) Valid ¶
func (e TallymanV1IngestEvent) Valid() error
Valid validates the TallymanV1IngestEvent. It does not validate the event body.
type TallymanV1IngestRejectedEvent ¶
type TallymanV1IngestRejectedEvent struct { ID string `json:"id"` Message string `json:"message"` Permanent bool `json:"permanent"` }
TallymanV1IngestRejectedEvent is an event that was rejected by the Tallyman API.
type TallymanV1IngestRequest ¶
type TallymanV1IngestRequest struct {
Events []TallymanV1IngestEvent `json:"events"`
}
TallymanV1IngestRequest is a request to the Tallyman API to ingest usage events.
type TallymanV1IngestResponse ¶
type TallymanV1IngestResponse struct { AcceptedEvents []TallymanV1IngestAcceptedEvent `json:"accepted_events"` RejectedEvents []TallymanV1IngestRejectedEvent `json:"rejected_events"` }
TallymanV1IngestResponse is a response from the Tallyman API to ingest usage events.
type TallymanV1Response ¶
type TallymanV1Response struct {
Message string `json:"message"`
}
TallymanV1Response is a generic response with a message from the Tallyman API. It is typically returned when there is an error.
type UnknownEventTypeError ¶
type UnknownEventTypeError struct {
EventType string
}
UnknownEventTypeError is returned by ParseEventWithType when an unknown event type is encountered.
func (UnknownEventTypeError) Error ¶
func (e UnknownEventTypeError) Error() string
Error implements error.
type UsageEventType ¶
type UsageEventType string
UsageEventType is an enum of all usage event types. It mirrors the database type `usage_event_type`.
const (
UsageEventTypeDCManagedAgentsV1 UsageEventType = "dc_managed_agents_v1"
)
All event types.
When adding a new event type, ensure you add it to the Valid method and the ParseEventWithType function.
func (UsageEventType) IsDiscrete ¶
func (e UsageEventType) IsDiscrete() bool
func (UsageEventType) IsHeartbeat ¶
func (e UsageEventType) IsHeartbeat() bool
func (UsageEventType) Valid ¶
func (e UsageEventType) Valid() bool