axiom

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2021 License: MIT Imports: 22 Imported by: 29

Documentation

Overview

Package axiom implements Go bindings for the Axiom API.

Usage:

import "github.com/axiomhq/axiom-go/axiom"
import "github.com/axiomhq/axiom-go/axiom/apl" // When constructing APL queries
import "github.com/axiomhq/axiom-go/axiom/query" // When constructing queries

Construct a new Axiom client, then use the various services on the client to access different parts of the Axiom API. The package automatically takes its configuration from the environment if not specified otherwise. Refer to `NewClient()` for details. The configuration also differs when connection to Axiom Cloud or Axiom Selfhost. Either way, the access token can be a personal or an ingest token. The ingest token however, will just allow ingestion into the datasets targeted by the ingest token:

client, err := axiom.NewClient()

Get the version of the configured deployment:

version, err := client.Version.Get(ctx)

Some API methods have additional parameters that can be passed:

	 dashboards, err := client.Dashboards.List(ctx, axiom.ListOptions{
      Limit: 5,
	 })

NOTE: Every client method mapping to an API method takes a context.Context (https://godoc.org/context) as its first parameter to pass cancelation signals and deadlines to requests. In case there is no context available, then context.Background() can be used as a starting point.

For more code samples, check out the https://github.com/axiomhq/axiom-go/tree/main/examples directory.

Example
package main

import (
	"context"
	"fmt"
	"log"

	"github.com/axiomhq/axiom-go/axiom"
)

func main() {
	// Export `AXIOM_TOKEN` and `AXIOM_ORG_ID` for Axiom Cloud
	// Export `AXIOM_URL` and `AXIOM_TOKEN` for Axiom Selfhost

	client, err := axiom.NewClient()
	if err != nil {
		log.Fatal(err)
	}

	version, err := client.Version.Get(context.Background())
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(version)
}
Output:

Index

Examples

Constants

View Source
const CloudURL = "https://cloud.axiom.co"

CloudURL is the url of the cloud hosted version of Axiom.

View Source
const TimestampField = "_time"

TimestampField is the default field the server looks for a time to use as ingestion time. If not present, the server will set the ingestion time by itself.

Variables

View Source
var (
	// ErrUnknownContentType is raised when the given content type is not valid.
	ErrUnknownContentType = errors.New("unknown content type")
	// ErrUnknownContentEncoding is raised when the given content encoding is
	// not valid.
	ErrUnknownContentEncoding = errors.New("unknown content encoding")
)
View Source
var (
	// ErrInvalidToken is returned when the access token is invalid.
	ErrInvalidToken = errors.New("invalid access token")

	// ErrMissingAccessToken is raised when an access token is not provided. Set
	// it manually using the SetAccessToken option or export `AXIOM_TOKEN`.
	ErrMissingAccessToken = errors.New("missing access token")

	// ErrMissingOrganizationID is raised when an organization ID is not
	// provided. Set it manually using the SetOrgID option or export
	// `AXIOM_ORG_ID`.
	ErrMissingOrganizationID = errors.New("missing organization id")

	// ErrUnauthenticated is raised when the access token is not valid.
	ErrUnauthenticated = errors.New("invalid authentication credentials")

	// ErrUnprivilegedToken is raised when a client tries to call a non-ingest
	// endpoint with an ingest-only token configured.
	ErrUnprivilegedToken = errors.New("using ingest token for non-ingest operation")

	// ErrNotFound is returned when the requested resource is not found.
	ErrNotFound = errors.New("not found")

	// ErrExists is returned when the requested resource already exists.
	ErrExists = errors.New("entity exists")
)

Functions

func DefaultHTTPClient

func DefaultHTTPClient() *http.Client

DefaultHTTPClient returns the default HTTP client used for making requests.

func GzipEncoder added in v0.8.0

func GzipEncoder(r io.Reader) (io.Reader, error)

GzipEncoder is a `ContentEncoder` that gzip compresses the data it reads from the provided reader. The compression level defaults to `gzip.BestSpeed`.

func IsAPIToken added in v0.8.0

func IsAPIToken(token string) bool

IsAPIToken returns true if the given access token is an API token.

func IsIngestToken added in v0.1.2

func IsIngestToken(token string) bool

IsIngestToken returns true if the given access token is an ingest token.

func IsPersonalToken added in v0.1.2

func IsPersonalToken(token string) bool

IsPersonalToken returns true if the given access token is a personal token.

func IsValidToken added in v0.5.0

func IsValidToken(token string) bool

IsValidToken returns true if the given access token is a valid Axiom access token.

func ValidateCredentials added in v0.6.0

func ValidateCredentials(ctx context.Context) error

ValidateCredentials returns nil if the environment variables that configure a Client are valid. Otherwise, it returns an appropriate error. This function establishes a connection to the configured Axiom deployment.

func ValidateEnvironment added in v0.5.0

func ValidateEnvironment() error

ValidateEnvironment returns nil if the environment variables, needed to configure a new Client, are present and syntactically valid. Otherwise, it returns an appropriate error.

func ZstdEncoder added in v0.8.0

func ZstdEncoder(r io.Reader) (io.Reader, error)

ZstdEncoder is a `ContentEncoder` that zstd compresses the data it reads from the provided reader.

Types

type APITokensService added in v0.8.0

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

APITokensService handles communication with the api token related operations of the Axiom API.

Axiom API Reference: /api/v1/tokens/api

func (*APITokensService) Create added in v0.8.0

func (s *APITokensService) Create(ctx context.Context, req TokenCreateUpdateRequest) (*Token, error)

Create a token with the given properties.

func (*APITokensService) Delete added in v0.8.0

func (s *APITokensService) Delete(ctx context.Context, id string) error

Delete the token identified by the given id.

func (*APITokensService) Get added in v0.8.0

func (s *APITokensService) Get(ctx context.Context, id string) (*Token, error)

Get a token by id.

func (*APITokensService) List added in v0.8.0

func (s *APITokensService) List(ctx context.Context) ([]*Token, error)

List all available tokens.

func (*APITokensService) Update added in v0.8.0

func (s *APITokensService) Update(ctx context.Context, id string, req TokenCreateUpdateRequest) (*Token, error)

Update the token identified by the given id with the given properties.

func (*APITokensService) View added in v0.8.0

func (s *APITokensService) View(ctx context.Context, id string) (*RawToken, error)

View a raw token secret by id.

type AuthenticatedUser

type AuthenticatedUser struct {
	// ID is the unique ID of the user.
	ID string `json:"id"`
	// Name of the user.
	Name string `json:"name"`
	// Emails are the email addresses of the user.
	Emails []string `json:"emails"`
}

AuthenticatedUser represents an authenticated Axiom user.

type Client

type Client struct {
	Dashboards     *DashboardsService
	Datasets       *DatasetsService
	Monitors       *MonitorsService
	Notifiers      *NotifiersService
	Organizations  *OrganizationsService
	StarredQueries *StarredQueriesService
	Teams          *TeamsService
	Tokens         struct {
		API      *APITokensService
		Ingest   *IngestTokensService
		Personal *PersonalTokensService
	}
	Users         *UsersService
	Version       *VersionService
	VirtualFields *VirtualFieldsService
	// contains filtered or unexported fields
}

Client provides the Axiom HTTP API operations.

func NewClient

func NewClient(options ...Option) (*Client, error)

NewClient returns a new Axiom API client. It automatically takes its configuration from the environment.

To connect to Axiom Cloud:

  • AXIOM_TOKEN
  • AXIOM_ORG_ID (only when using a personal token)

To connect to an Axiom Selfhost:

  • AXIOM_URL
  • AXIOM_TOKEN

The configuration can be set manually using `Option` functions prefixed with `Set`. Refer to `SetCloudConfig()` and `SetSelfhostConfig()`. Individual properties can be overwritten as well.

The access token must be a personal or ingest token which can be created on the user profile or settings page on Axiom.

func (*Client) Options

func (c *Client) Options(options ...Option) error

Options applies Options to the Client.

func (*Client) ValidateCredentials added in v0.6.0

func (c *Client) ValidateCredentials(ctx context.Context) error

ValidateCredentials makes sure the client can properly authenticate against the configured Axiom deployment.

type Comparison

type Comparison uint8

Comparison represents a comparison operation for a monitor. A monitor acts on the result of comparing a query result with a threshold.

const (
	Below Comparison = iota + 1
	BelowOrEqual
	Above
	AboveOrEqual
)

All available monitor comparison modes.

func (Comparison) MarshalJSON

func (c Comparison) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler. It is in place to marshal the Comparison to its string representation because that's what the server expects.

func (Comparison) String

func (i Comparison) String() string

func (*Comparison) UnmarshalJSON

func (c *Comparison) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler. It is in place to unmarshal the Comparison from the string representation the server returns.

type ContentEncoder added in v0.8.0

type ContentEncoder func(io.Reader) (io.Reader, error)

ContentEncoder is a function that wraps a given `io.Reader` with encoding functionality and returns that enhanced reader. The content type of the encoded content must obviously be accepted by the server.

See `GzipEncoder` and `ZstdEncoder` for implementation reference.

func GzipEncoderWithLevel added in v0.8.0

func GzipEncoderWithLevel(level int) ContentEncoder

GzipEncoderWithLevel returns a `ContentEncoder` that gzip compresses data using the specified compression level.

type ContentEncoding

type ContentEncoding uint8

ContentEncoding describes the content encoding of the data to ingest.

const (
	// Identity marks the data as not being encoded.
	Identity ContentEncoding = iota + 1 //
	// Gzip marks the data as being gzip encoded. Preferred compression format.
	Gzip // gzip
	// Zstd marks the data as being zstd encoded.
	Zstd // zstd
)

func (ContentEncoding) String

func (i ContentEncoding) String() string

type ContentType

type ContentType uint8

ContentType describes the content type of the data to ingest.

const (
	// JSON treats the data as JSON array.
	JSON ContentType = iota + 1 // application/json
	// NDJSON treats the data as newline delimited JSON objects. Preferred
	// data format.
	NDJSON // application/x-ndjson
	// CSV treats the data as CSV content.
	CSV // text/csv
)

func DetectContentType

func DetectContentType(r io.Reader) (io.Reader, ContentType, error)

DetectContentType detects the content type of an io.Reader's data. The returned io.Reader must be used instead of the passed one. Compressed content is not detected.

func (ContentType) String

func (i ContentType) String() string

type Dashboard

type Dashboard struct {
	// ID is the unique ID of the dashboard.
	ID string `json:"id"`
	// Name of the dashboard.
	Name string `json:"name"`
	// Description of the dashboard.
	Description string `json:"description"`
	// Owner is the team or user ID of the dashboards owner.
	Owner string `json:"owner"`
	// Charts contains the raw data composing the dashboards charts.
	Charts []interface{} `json:"charts"`
	// Layout contains the raw data composing the dashboards layout.
	Layout []interface{} `json:"layout"`
	// RefreshTime is the duration after which the dashboards data is updated.
	RefreshTime time.Duration `json:"refreshTime"`
	// SchemaVersion auto increments with ever change made to the dashboard.
	SchemaVersion int `json:"schemaVersion"`
	// TimeWindowStart is the start of the time window displayed by the
	// dashboard.
	TimeWindowStart string `json:"timeWindowStart"`
	// TimeWindowEnd is the end of the time window displayed by the dashboard.
	TimeWindowEnd string `json:"timeWindowEnd"`
	// Against specifies the time offset to compare the dashboards time window,
	// as specified by `TimeWindowStart` and `TimeWindowEnd`, against. This
	// field and `AgainstTimestamp` mutual exclude each other.
	Against time.Duration `json:"against"`
	// AgainstTimestamp is a timestamp that specifies the time offset to compare
	// the dashboards time window, as specified by `TimeWindowStart` and
	// `TimeWindowEnd`, against.  This field and `Against` mutual exclude each
	// other.
	AgainstTimestamp time.Time `json:"againstTimestamp"`
	// Version of the dashboard.
	Version string `json:"version"`
}

Dashboard represents a dashboard.

func (Dashboard) MarshalJSON

func (d Dashboard) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler. It is in place to marshal some fields to different representations for transport because that's what the server expects.

func (*Dashboard) UnmarshalJSON

func (d *Dashboard) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler. It is in place to unmarshal some fields from their transport representation into proper Go types because the server returns them differently.

type DashboardsService

type DashboardsService service

DashboardsService handles communication with the dashboard related operations of the Axiom API.

Axiom API Reference: /api/v1/dashboards

func (*DashboardsService) Create

func (s *DashboardsService) Create(ctx context.Context, req Dashboard) (*Dashboard, error)

Create a dashboard with the given properties. The ID and Version fields of the request payload are ignored.

func (*DashboardsService) Delete

func (s *DashboardsService) Delete(ctx context.Context, id string) error

Delete the dashboard identified by the given id.

func (*DashboardsService) Get

func (s *DashboardsService) Get(ctx context.Context, id string) (*Dashboard, error)

Get a dashboard by id.

func (*DashboardsService) List

func (s *DashboardsService) List(ctx context.Context, opts ListOptions) ([]*Dashboard, error)

List all available dashboards.

func (*DashboardsService) Update

func (s *DashboardsService) Update(ctx context.Context, id string, req Dashboard) (*Dashboard, error)

Update the dashboard identified by the given id with the given properties. When updating, the Version is mandantory and must be set to the current version of the dashboard as returned by a Get() call.

type Dataset

type Dataset struct {
	// ID of the dataset.
	ID string `json:"id"`
	// Name is the unique name of the dataset.
	Name string `json:"name"`
	// Description of the dataset.
	Description string `json:"description"`
	// CreatedBy is the ID of the user who created the dataset.
	CreatedBy string `json:"who"`
	// CreatedAt is the time the dataset was created at.
	CreatedAt time.Time `json:"created"`
}

Dataset represents an Axiom dataset.

type DatasetCreateRequest

type DatasetCreateRequest struct {
	// Name of the dataset to create. Restricted to 80 characters of [a-zA-Z0-9]
	// and special characters "-", "_" and ".". Special characters cannot be a
	// prefix or suffix. The prefix cannot be "axiom-".
	Name string `json:"name"`
	// Description of the dataset to create.
	Description string `json:"description"`
}

DatasetCreateRequest is a request used to create a dataset.

type DatasetInfo

type DatasetInfo struct {
	// Name is the unique name of the dataset.
	Name string `json:"name"`
	// NumBlocks is the number of blocks of the dataset.
	NumBlocks uint64 `json:"numBlocks"`
	// NumEvents is the number of events of the dataset.
	NumEvents uint64 `json:"numEvents"`
	// NumFields is the number of fields of the dataset.
	NumFields uint32 `json:"numFields"`
	// InputBytes is the amount of data stored in the dataset.
	InputBytes uint64 `json:"inputBytes"`
	// InputBytesHuman is the amount of data stored in the dataset formatted in
	// a human readable format.
	InputBytesHuman string `json:"inputBytesHuman"`
	// CompressedBytes is the amount of compressed data stored in the dataset.
	CompressedBytes uint64 `json:"compressedBytes"`
	// CompressedBytesHuman is the amount of compressed data stored in the
	// dataset formatted in a human readable format.
	CompressedBytesHuman string `json:"compressedBytesHuman"`
	// MinTime is the time of the oldest event stored in the dataset.
	MinTime time.Time `json:"minTime"`
	// MaxTime is the time of the newest event stored in the dataset.
	MaxTime time.Time `json:"maxTime"`
	// Fields are the fields of the dataset.
	Fields []Field `json:"fields"`
	// CreatedBy is the ID of the user who created the dataset.
	CreatedBy string `json:"who"`
	// CreatedAt is the time the dataset was created.
	CreatedAt time.Time `json:"created"`
}

DatasetInfo represents the details of the information stored inside an Axiom dataset.

type DatasetStats

type DatasetStats struct {
	Datasets []*DatasetInfo `json:"datasets"`
	// NumBlocks is the number of blocks of the dataset.
	NumBlocks uint64 `json:"numBlocks"`
	// NumEvents is the number of events of the dataset.
	NumEvents uint64 `json:"numEvents"`
	// InputBytes is the amount of data stored in the dataset.
	InputBytes uint64 `json:"inputBytes"`
	// InputBytesHuman is the amount of data stored in the dataset formatted in
	// a human readable format.
	InputBytesHuman string `json:"inputBytesHuman"`
	// CompressedBytes is the amount of compressed data stored in the dataset.
	CompressedBytes uint64 `json:"compressedBytes"`
	// CompressedBytesHuman is the amount of compressed data stored in the
	// dataset formatted in a human readable format.
	CompressedBytesHuman string `json:"compressedBytesHuman"`
}

DatasetStats are the stats of

type DatasetUpdateRequest

type DatasetUpdateRequest struct {
	// Description of the dataset to update.
	Description string `json:"description"`
}

DatasetUpdateRequest is a request used to update a dataset.

type DatasetsService

type DatasetsService service

DatasetsService handles communication with the dataset related operations of the Axiom API.

Axiom API Reference: /api/v1/datasets

func (*DatasetsService) APLQuery added in v0.4.0

func (s *DatasetsService) APLQuery(ctx context.Context, raw string, opts apl.Options) (*apl.Result, error)

APLQuery executes the given query specified using the Axiom Processing Language (APL).

func (*DatasetsService) Create

Create a dataset with the given properties.

func (*DatasetsService) Delete

func (s *DatasetsService) Delete(ctx context.Context, id string) error

Delete the dataset identified by the given id.

func (*DatasetsService) Get

func (s *DatasetsService) Get(ctx context.Context, id string) (*Dataset, error)

Get a dataset by id.

func (*DatasetsService) History

func (s *DatasetsService) History(ctx context.Context, id string) (*query.History, error)

History retrieves the query stored inside the query history dataset identified by its id.

func (*DatasetsService) Info

func (s *DatasetsService) Info(ctx context.Context, id string) (*DatasetInfo, error)

Info retrieves the information of the dataset identified by its id.

func (*DatasetsService) Ingest

Ingest data into the dataset identified by its id. Restrictions for field names (JSON object keys) can be reviewed here: https://www.axiom.co/docs/usage/field-restrictions.

func (*DatasetsService) IngestEvents

func (s *DatasetsService) IngestEvents(ctx context.Context, id string, opts IngestOptions, events ...Event) (*IngestStatus, error)

IngestEvents ingests events into the dataset identified by its id. Restrictions for field names (JSON object keys) can be reviewed here: https://www.axiom.co/docs/usage/field-restrictions.

func (*DatasetsService) List

func (s *DatasetsService) List(ctx context.Context) ([]*Dataset, error)

List all available datasets.

func (*DatasetsService) Query

func (s *DatasetsService) Query(ctx context.Context, id string, q query.Query, opts query.Options) (*query.Result, error)

Query executes the given query on the dataset identified by its id.

func (*DatasetsService) Stats

func (s *DatasetsService) Stats(ctx context.Context) (*DatasetStats, error)

Stats returns detailed statistics about all available datasets. This operation is more expenssive and listing the datasets and then getting the information of a specific dataset is preferred, when no aggregated statistics across all datasets are needed.

func (*DatasetsService) Trim

func (s *DatasetsService) Trim(ctx context.Context, id string, maxDuration time.Duration) (*TrimResult, error)

Trim the dataset identified by its id to a given length. The max duration given will mark the oldest timestamp an event can have. Older ones will be deleted from the dataset.

func (*DatasetsService) Update

Update the dataset identified by the given id with the given properties.

func (*DatasetsService) UpdateField added in v0.8.0

func (s *DatasetsService) UpdateField(ctx context.Context, dataset, field string, req FieldUpdateRequest) (*Field, error)

Update the named field of the dataset identified by the given id with the given properties.

type Error

type Error struct {
	Status  int    `json:"-"`
	Message string `json:"message"`
}

Error is the generic error response returned on non 2xx HTTP status codes. Either one of the two fields is populated. However, calling the Error() method is preferred.

func (Error) Error

func (e Error) Error() string

Error implements the error interface.

type Event

type Event map[string]interface{}

An Event is a map of key-value pairs.

type Field

type Field struct {
	// Name is the unique name of the field.
	Name string `json:"name"`
	// Description is the description of the field.
	Description string `json:"description"`
	// Type is the datatype of the field.
	Type string `json:"type"`
	// Unit is the unit of the field.
	Unit string `json:"unit"`
	// Hidden describes if the field is hidden or not.
	Hidden bool `json:"hidden"`
}

Field represents a field of an Axiom dataset.

type FieldUpdateRequest added in v0.8.0

type FieldUpdateRequest struct {
	// Description of the field to update.
	Description string `json:"description"`
	// Unit of the field to update.
	Unit string `json:"unit"`
	// Hidden status of the field to update.
	Hidden bool `json:"hidden"`
}

FieldUpdateRequest is a request used to update a field for a dataset.

type IngestFailure

type IngestFailure struct {
	// Timestamp of the event that failed to ingest.
	Timestamp time.Time `json:"timestamp"`
	// Error that made the event fail to ingest.
	Error string `json:"error"`
}

IngestFailure describes the ingestion failure of a single event.

type IngestOptions

type IngestOptions struct {
	// TimestampField defines a custom field to extract the ingestion timestamp
	// from. Defaults to `_time`.
	TimestampField string `url:"timestamp-field,omitempty"`
	// TimestampFormat defines a custom format for the TimestampField.
	// The reference time is `Mon Jan 2 15:04:05 -0700 MST 2006`, as specified
	// in https://pkg.go.dev/time/?tab=doc#Parse.
	TimestampFormat string `url:"timestamp-format,omitempty"`
	// CSVDelimiter is the delimiter that separates CSV fields. Only valid when
	// the content to be ingested is CSV formatted.
	CSVDelimiter string `url:"csv-delimiter,omitempty"`
}

IngestOptions specifies the optional parameters for the Ingest and IngestEvents method of the Datasets service.

type IngestStatus

type IngestStatus struct {
	// Ingested is the amount of events that have been ingested.
	Ingested uint64 `json:"ingested"`
	// Failed is the amount of events that failed to ingest.
	Failed uint64 `json:"failed"`
	// Failures are the ingestion failures, if any.
	Failures []*IngestFailure `json:"failures"`
	// ProcessedBytes is the number of bytes processed.
	ProcessedBytes uint64 `json:"processedBytes"`
	// BlocksCreated is the amount of blocks created.
	BlocksCreated uint32 `json:"blocksCreated"`
	// WALLength is the length of the Write-Ahead Log.
	WALLength uint32 `json:"walLength"`
}

IngestStatus is the status after an event ingestion operation.

type IngestTokensService

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

IngestTokensService handles communication with the ingest token related operations of the Axiom API.

Axiom API Reference: /api/v1/tokens/ingest

func (*IngestTokensService) Create added in v0.6.0

func (s *IngestTokensService) Create(ctx context.Context, req TokenCreateUpdateRequest) (*Token, error)

Create a token with the given properties.

func (*IngestTokensService) Delete added in v0.6.0

func (s *IngestTokensService) Delete(ctx context.Context, id string) error

Delete the token identified by the given id.

func (*IngestTokensService) Get added in v0.6.0

func (s *IngestTokensService) Get(ctx context.Context, id string) (*Token, error)

Get a token by id.

func (*IngestTokensService) List added in v0.6.0

func (s *IngestTokensService) List(ctx context.Context) ([]*Token, error)

List all available tokens.

func (*IngestTokensService) Update added in v0.6.0

func (s *IngestTokensService) Update(ctx context.Context, id string, req TokenCreateUpdateRequest) (*Token, error)

Update the token identified by the given id with the given properties.

func (*IngestTokensService) Validate

func (s *IngestTokensService) Validate(ctx context.Context) error

Validate the token that is used for authentication.

func (*IngestTokensService) View added in v0.6.0

func (s *IngestTokensService) View(ctx context.Context, id string) (*RawToken, error)

View a raw token secret by id.

type License

type License struct {
	// ID of the license.
	ID string `json:"id"`
	// Issuer of the license.
	Issuer string `json:"issuer"`
	// IssuedTo describes who the license was issued to.
	IssuedTo string `json:"issuedTo"`
	// IssuedAt is the time the license was issued at.
	IssuedAt time.Time `json:"issuedAt"`
	// ValidFrom is the time the license is valid from.
	ValidFrom time.Time `json:"validFrom"`
	// ExpiresAt is the time the license expires.
	ExpiresAt time.Time `json:"expiresAt"`
	// Tier of the license.
	Tier Plan `json:"tier"`
	// DailyIngestGB is the daily amount of data in gigabytes that can be
	// ingested as part of the license.
	DailyIngestGB int `json:"dailyIngestGb"`
	// MaxUsers is the maximum amount of teams allowed.
	MaxUsers int `json:"maxUsers"`
	// MaxTeams is the maximum amount of user allowed.
	MaxTeams int `json:"maxTeams"`
	// MaxDatasets is the maximum amount of datasets allowed.
	MaxDatasets int `json:"maxDatasets"`
	// MaxQueriesPerSecond is the maximum amount of queries allowed per second.
	MaxQueriesPerSecond int `json:"maxQueriesPerSecond"`
	// MaxQueryWindow is the maximum query window allowed.
	MaxQueryWindow time.Duration `json:"maxQueryWindowSeconds"`
	// MaxAuditWindow is the maximum audit window allowed.
	MaxAuditWindow time.Duration `json:"maxAuditWindowSeconds"`
	// WithRBAC specifies it RBAC is enabled.
	WithRBAC bool `json:"withRBAC"`
	// WithAuths specifies the supported authentication modes.
	WithAuths []string `json:"withAuths"`
	// Error is the last error (if any) on token refresh.
	Error string `json:"error"`
}

License of a deployment or organization.

func (License) MarshalJSON

func (l License) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler. It is in place to marshal the MaxQueryWindow and MaxAuditWindow to seconds because that's what the server expects.

func (*License) UnmarshalJSON

func (l *License) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler. It is in place to unmarshal the MaxQueryWindow and MaxAuditWindow into a proper time.Duration value because the server returns it in seconds.

type ListOptions

type ListOptions struct {
	// Limit of the of the result set.
	Limit uint `url:"limit,omitempty"`
	// Offset the result set has from its base.
	Offset uint `url:"offset,omitempty"`
}

ListOptions specifies the optional parameters to various List methods that support result limits.

type Monitor

type Monitor struct {
	// ID is the unique ID of the monitor.
	ID string `json:"id"`
	// Dataset the monitor belongs to.
	Dataset string `json:"dataset"`
	// Name is the display name of the monitor.
	Name string `json:"name"`
	// Description of the monitor.
	Description string `json:"description"`
	// DisabledUntil is the time until the monitor is being executed again.
	DisabledUntil time.Time `json:"disabledUntil"`
	// Query is executed by the monitor and the result is compared using the
	// monitors configured comparison operator against the configured threshold.
	Query query.Query `json:"query"`
	// IsAPL is true if the query is an APL query.
	IsAPL bool `json:"aplQuery"`
	// Threshold the query result is compared against, which evalutes if the
	// monitor acts or not.
	Threshold float64 `json:"threshold"`
	// Comparison operator to use for comparing the query result and threshold
	// value.
	Comparison Comparison `json:"comparison"`
	// NoDataCloseWait specifies after which amount of laking a query result,
	// the monitor is closed.
	NoDataCloseWait time.Duration `json:"noDataCloseWaitMinutes"`
	// Frequency the monitor is executed by.
	Frequency time.Duration `json:"frequencyMinutes"`
	// Duration the monitor goes back in time and looks at the data it acts on.
	Duration time.Duration `json:"durationMinutes"`
	// Notifiers attached to the monitor.
	Notifiers []string `json:"notifiers"`
	// LastCheckTime specifies the last time the monitor executed the query and
	// compared its result against the threshold.
	LastCheckTime time.Time `json:"lastCheckTime"`
	// LastCheckState is the state associated with the last monitor execution.
	LastCheckState map[string]string `json:"lastCheckState"`
	// Disabled is true, if the monitor is disabled and thus not running.
	Disabled bool `json:"disabled"`
	// LastError is the last error that was observed while running the monitor.
	LastError string `json:"lastError"`
}

A Monitor continuesly runs a query on a dataset and evaluates its result against a configured threshold. Upon reaching those it will invoke the configured notifiers.

func (Monitor) MarshalJSON

func (m Monitor) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler. It is in place to marshal the NoDataCloseWait, Frequency and Duration to minutes because that's what the server expects.

func (*Monitor) UnmarshalJSON

func (m *Monitor) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler. It is in place to unmarshal the RefreshTime into a proper time.Duration value because the server returns it in seconds.

type MonitorsService

type MonitorsService service

MonitorsService handles communication with the monitor related operations of the Axiom API.

Axiom API Reference: /api/v1/monitors

func (*MonitorsService) Create

func (s *MonitorsService) Create(ctx context.Context, req Monitor) (*Monitor, error)

Create a monitor with the given properties.

func (*MonitorsService) Delete

func (s *MonitorsService) Delete(ctx context.Context, id string) error

Delete the monitor identified by the given id.

func (*MonitorsService) Get

func (s *MonitorsService) Get(ctx context.Context, id string) (*Monitor, error)

Get a monitor by id.

func (*MonitorsService) List

func (s *MonitorsService) List(ctx context.Context) ([]*Monitor, error)

List all available monitors.

func (*MonitorsService) Update

func (s *MonitorsService) Update(ctx context.Context, id string, req Monitor) (*Monitor, error)

Update the monitor identified by the given id with the given properties.

type Notifier

type Notifier struct {
	// ID is the unique ID of the notifier.
	ID string `json:"id"`
	// Name is the display name of the notifier.
	Name string `json:"name"`
	// Type of a notifier.
	Type Type `json:"type"`
	// Properties of the notifier.
	Properties interface{} `json:"properties"`
	// DisabledUntil is the time until the notifier is being executed again.
	DisabledUntil time.Time `json:"disabledUntil"`
	// CreatedAt is the time the notifer was created.
	CreatedAt time.Time `json:"metaCreated"`
	// ModifiedAt is the time the notifer was last modified.
	ModifiedAt time.Time `json:"metaModified"`
	// Version of the notifier.
	Version int64 `json:"metaVersion"`
}

A Notifier alerts users by using the configured service to reach out to them.

type NotifiersService

type NotifiersService service

NotifiersService handles communication with the notifier related operations of the Axiom API.

Axiom API Reference: /api/v1/notifiers

func (*NotifiersService) Create

func (s *NotifiersService) Create(ctx context.Context, req Notifier) (*Notifier, error)

Create a notifier with the given properties.

func (*NotifiersService) Delete

func (s *NotifiersService) Delete(ctx context.Context, id string) error

Delete the notifier identified by the given id.

func (*NotifiersService) Get

func (s *NotifiersService) Get(ctx context.Context, id string) (*Notifier, error)

Get a notifier by id.

func (*NotifiersService) List

func (s *NotifiersService) List(ctx context.Context) ([]*Notifier, error)

List all available notifiers.

func (*NotifiersService) Update

func (s *NotifiersService) Update(ctx context.Context, id string, req Notifier) (*Notifier, error)

Update the notifier identified by the given id with the given properties.

type Option

type Option func(c *Client) error

An Option modifies the behaviour of the API client. If not otherwise specified by a specific option, they are safe to use even after API methods have been called. However, they are not safe to use while the client is performing an operation.

func SetAccessToken added in v0.1.2

func SetAccessToken(accessToken string) Option

SetAccessToken specifies the access token to use. Can also be specified using the `AXIOM_TOKEN` environment variable.

func SetClient

func SetClient(client *http.Client) Option

SetClient specifies a custom http client that should be used to make requests.

func SetCloudConfig added in v0.4.0

func SetCloudConfig(accessToken, orgID string) Option

SetCloudConfig specifies all properties needed in order to successfully connect to Axiom Cloud.

func SetNoEnv added in v0.6.1

func SetNoEnv() Option

SetNoEnv prevents the client from deriving its configuration from the environment.

func SetOrgID added in v0.1.1

func SetOrgID(orgID string) Option

SetOrgID specifies the organization ID to use when connecting to Axiom Cloud. When a personal access token is used, this method can be used to switch between organizations without creating a new client instance. Can also be specified using the `AXIOM_ORG_ID` environment variable.

func SetSelfhostConfig added in v0.4.0

func SetSelfhostConfig(deploymentURL, accessToken string) Option

SetSelfhostConfig specifies all properties needed in order to successfully connect to an Axiom Selfhost deployment.

func SetURL added in v0.4.0

func SetURL(baseURL string) Option

SetURL sets the base URL used by the client. Can also be specified using the `AXIOM_URL` environment variable.

func SetUserAgent

func SetUserAgent(userAgent string) Option

SetUserAgent sets the user agent used by the client.

type Organization

type Organization struct {
	// ID is the unique ID of the organization.
	ID string `json:"id"`
	// Name of the organization.
	Name string `json:"name"`
	// Slug of the organization.
	Slug string `json:"slug"`
	// Plan the deployment or organization is on.
	Plan Plan `json:"plan"`
	// PlanCreated is the time the plan was created.
	PlanCreated time.Time `json:"planCreated"`
	// PlanExpires is the time the plan will expire.
	PlanExpires time.Time `json:"planExpires"`
	// Trialed describes if the plan is trialed or not.
	Trialed bool `json:"trialed"`
	// PreviousPlan is the previous plan the deployment or organization was on.
	PreviousPlan Plan `json:"previousPlan"`
	// PreviousPlanCreated is the time the previous plan was created.
	PreviousPlanCreated time.Time `json:"previousPlanCreated"`
	// PreviousPlanExpired is the time the previous plan expired.
	PreviousPlanExpired time.Time `json:"previousPlanExpired"`
	// LastUsageSync is the last time the usage instance usage statistics were
	// synchronized.
	LastUsageSync time.Time `json:"lastUsageSync"`
	// Role the requesting user has on the deployment or the organization.
	Role UserRole `json:"role"`
	// PrimaryEmail of the user that issued the request.
	PrimaryEmail string `json:"primaryEmail"`
	// License of the deployment or organization.
	License License `json:"license"`
	// CreatedAt is the time the Organization was created.
	CreatedAt time.Time `json:"metaCreated"`
	// ModifiedAt is the time the Organization was last modified.
	ModifiedAt time.Time `json:"metaModified"`
	// Version of the organization.
	Version string `json:"metaVersion"`
}

Organization represents an organization. For selfhost deployments, there is only one main organization, therefor it is referred to as deployment.

type OrganizationUpdateRequest

type OrganizationUpdateRequest struct {
	// Name of the organization. Restricted to 30 characters.
	Name string `json:"name"`
}

OrganizationUpdateRequest is a request used to update an organization.

type OrganizationsService

type OrganizationsService service

OrganizationsService handles communication with the organization related operations of the Axiom API.

Axiom API Reference: /api/v1/orgs

func (*OrganizationsService) Get

Get an organization by id.

func (*OrganizationsService) License

func (s *OrganizationsService) License(ctx context.Context, organizationID string) (*License, error)

License gets an organizations license.

func (*OrganizationsService) List

List all available organizations.

func (*OrganizationsService) Update

Update the organization identified by the given id with the given properties.

type OwnerKind

type OwnerKind uint8

OwnerKind represents the kind of a starred queries owner.

const (
	OwnedByUser OwnerKind = iota // user
	OwnedByTeam                  // team
)

All available query kinds.

func (OwnerKind) EncodeValues

func (ok OwnerKind) EncodeValues(key string, v *url.Values) error

EncodeValues implements `query.Encoder`. It is in place to encode the OwnerKind into a string URL value because that's what the server expects.

func (OwnerKind) String

func (i OwnerKind) String() string

type PersonalTokensService

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

PersonalTokensService handles communication with the personal token related operations of the Axiom API.

Axiom API Reference: /api/v1/tokens/personal

func (*PersonalTokensService) Create added in v0.6.0

func (s *PersonalTokensService) Create(ctx context.Context, req TokenCreateUpdateRequest) (*Token, error)

Create a token with the given properties.

func (*PersonalTokensService) Delete added in v0.6.0

func (s *PersonalTokensService) Delete(ctx context.Context, id string) error

Delete the token identified by the given id.

func (*PersonalTokensService) Get added in v0.6.0

func (s *PersonalTokensService) Get(ctx context.Context, id string) (*Token, error)

Get a token by id.

func (*PersonalTokensService) List added in v0.6.0

func (s *PersonalTokensService) List(ctx context.Context) ([]*Token, error)

List all available tokens.

func (*PersonalTokensService) Update added in v0.6.0

func (s *PersonalTokensService) Update(ctx context.Context, id string, req TokenCreateUpdateRequest) (*Token, error)

Update the token identified by the given id with the given properties.

func (*PersonalTokensService) View added in v0.6.0

func (s *PersonalTokensService) View(ctx context.Context, id string) (*RawToken, error)

View a raw token secret by id.

type Plan

type Plan uint8

Plan represents the plan of a deployment or organization.

const (
	Free       Plan = iota + 1 // free
	Trial                      // trial
	Pro                        // pro
	Enterprise                 // enterprise
	Comped                     // comped
)

All available deployment or organization plans.

func (Plan) MarshalJSON

func (plan Plan) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler. It is in place to marshal the Plan to its string representation because that's what the server expects.

func (Plan) String

func (i Plan) String() string

func (*Plan) UnmarshalJSON

func (plan *Plan) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler. It is in place to unmarshal the Plan from the string representation the server returns.

type RawToken

type RawToken struct {
	// Token is the actual secret value of the token.
	Token string `json:"token"`
	// Scopes of the token. Only used by api and ingest tokens.
	Scopes []string `json:"scopes"`
	// Permissions of the token. Only used by api and ingest tokens.
	Permissions []string `json:"permissions"`
}

RawToken represents a raw token secret and its attached scopes.

type StarredQueriesListOptions

type StarredQueriesListOptions struct {
	// Kind of queries to list. Required.
	Kind query.Kind `url:"kind"`
	// Dataset to list starred queries for.
	Dataset string `url:"dataset,omitempty"`
	// Owner specifies if the starred queries of a users teams or personal ones
	// are listed.
	Owner OwnerKind `url:"who,omitempty"`

	ListOptions
}

StarredQueriesListOptions specifies the parameters for the List method of the StarredQuerys service.

type StarredQueriesService

type StarredQueriesService service

StarredQueriesService handles communication with the starred query related operations of the Axiom API.

Axiom API Reference: /api/v1/starred

func (*StarredQueriesService) Create

Create a starred query with the given properties.

func (*StarredQueriesService) Delete

func (s *StarredQueriesService) Delete(ctx context.Context, id string) error

Delete the starred query identified by the given id.

func (*StarredQueriesService) Get

Get a starred query by id.

func (*StarredQueriesService) List

List all available starred queries.

func (*StarredQueriesService) Update

Update the starred query identified by the given id with the given properties.

type StarredQuery

type StarredQuery struct {
	// ID is the unique ID of the starred query.
	ID string `json:"id"`
	// Kind of the starred query.
	Kind query.Kind `json:"kind"`
	// Dataset the starred query belongs to.
	Dataset string `json:"dataset"`
	// Owner is the team or user ID of the starred queries owner.
	Owner string `json:"who"`
	// Name is the display name of the starred query.
	Name string `json:"name"`
	// Query is the actual query.
	Query query.Query `json:"query"`
	// Metadata associated with the query.
	Metadata map[string]string `json:"metadata"`
	// CreatedAt is the time the starred query was created.
	CreatedAt time.Time `json:"created"`
}

StarredQuery represents a starred query of a dataset.

type Team

type Team struct {
	// ID is the unique ID of the team.
	ID string `json:"id"`
	// Name of the team.
	Name string `json:"name"`
	// Members are the IDs of the teams members.
	Members []string `json:"members"`
	// Datasets are the IDs of the teams assigned datasets.
	Datasets []string `json:"datasets"`
}

Team represents a team.

type TeamCreateUpdateRequest added in v0.7.0

type TeamCreateUpdateRequest struct {
	// Name of the team.
	Name string `json:"name"`
	// Members are the IDs of the teams members.
	Members []string `json:"members"`
	// Datasets are the IDs of the teams assigned datasets.
	Datasets []string `json:"datasets"`
}

TeamCreateUpdateRequest is a request used to create or update a team.

type TeamsService

type TeamsService service

TeamsService handles communication with the team related operations of the Axiom API.

Axiom API Reference: /api/v1/teams

func (*TeamsService) Create

Create a team with the given properties.

func (*TeamsService) Delete

func (s *TeamsService) Delete(ctx context.Context, id string) error

Delete the team identified by the given id.

func (*TeamsService) Get

func (s *TeamsService) Get(ctx context.Context, id string) (*Team, error)

Get a team by id.

func (*TeamsService) List

func (s *TeamsService) List(ctx context.Context) ([]*Team, error)

List all available teams.

func (*TeamsService) Update

func (s *TeamsService) Update(ctx context.Context, id string, req TeamCreateUpdateRequest) (*Team, error)

Update the team identified by the given id with the given properties.

type Token

type Token struct {
	// ID is the unique ID of the token.
	ID string `json:"id"`
	// Name of the token.
	Name string `json:"name"`
	// Description of the token.
	Description string `json:"description"`
	// Scopes of the token. Only used by api and ingest tokens.
	Scopes []string `json:"scopes"`
	// Permissions of the token. Only used by api and ingest tokens.
	Permissions []string `json:"permissions"`
}

Token represents an access token. Tokens can either be api tokens, valid across the whole Axiom API and granting access to the specified resources, ingest tokens, valid for ingestion into one or more datasets or personal tokens, granting access to the whole Axiom API only limited by the users role.

type TokenCreateUpdateRequest added in v0.8.0

type TokenCreateUpdateRequest struct {
	// Name of the token.
	Name string `json:"name"`
	// Description of the token.
	Description string `json:"description"`
	// Scopes of the token. Only used by api and ingest tokens.
	Scopes []string `json:"scopes"`
	// Permissions of the token. Only used by api and ingest tokens.
	Permissions []string `json:"permissions"`
}

TokenCreateUpdateRequest is a request used to create a token.

type TrimResult

type TrimResult struct {
	// BlocksDeleted is the amount of blocks deleted by the trim operation.
	BlocksDeleted int `json:"numDeleted"`
}

TrimResult is the result of a trim operation.

type Type

type Type uint8

Type represents the type of a notifier.

const (
	Pagerduty Type = iota + 1 // pagerduty
	Slack                     // slack
	Email                     // email
	Webhook                   // webhook
)

All available notifier types.

func (Type) MarshalJSON

func (t Type) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler. It is in place to marshal the Type to its string representation because that's what the server expects.

func (Type) String

func (i Type) String() string

func (*Type) UnmarshalJSON

func (t *Type) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler. It is in place to unmarshal the Type from the string representation the server returns.

type User

type User struct {
	// ID is the unique ID of the user.
	ID string `json:"id"`
	// Name of the user.
	Name string `json:"name"`
	// Email is the primary email of the user.
	Email string `json:"email"`
	// Role of the user.
	Role UserRole `json:"role"`
	// Permissions of the user.
	Permissions []string `json:"permissions"`
}

User represents an user.

type UserCreateRequest

type UserCreateRequest struct {
	// Name of the user.
	Name string `json:"name"`
	// Email is the primary email address of the user.
	Email string `json:"email"`
	// Role of the user.
	Role UserRole `json:"role"`
	// TeamIDs are the unique IDs of the teams the user will be part of.
	TeamIDs []string `json:"teamIds"`
}

UserCreateRequest is a request used to create an user.

type UserRole

type UserRole uint8

UserRole represents the role of a user.

const (
	RoleReadOnly UserRole = iota + 1 // read-only
	RoleUser                         // user
	RoleAdmin                        // admin
	RoleOwner                        // owner
)

All available user roles.

func (UserRole) MarshalJSON

func (ur UserRole) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler. It is in place to marshal the UserRole to its string representation because that's what the server expects.

func (UserRole) String

func (i UserRole) String() string

func (*UserRole) UnmarshalJSON

func (ur *UserRole) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler. It is in place to unmarshal the UserRole from the string representation the server returns.

type UserUpdateRequest

type UserUpdateRequest struct {
	// Name of the user.
	Name string `json:"name"`
}

UserUpdateRequest is a request used to update an user.

type UsersService

type UsersService service

UsersService handles communication with the user related operations of the Axiom API.

Axiom API Reference: /api/v1/users

func (*UsersService) Create

func (s *UsersService) Create(ctx context.Context, req UserCreateRequest) (*User, error)

Create a user with the given properties.

func (*UsersService) Current

func (s *UsersService) Current(ctx context.Context) (*AuthenticatedUser, error)

Current retrieves the authenticated user.

func (*UsersService) Delete

func (s *UsersService) Delete(ctx context.Context, id string) error

Delete the user identified by the given id.

func (*UsersService) Get

func (s *UsersService) Get(ctx context.Context, id string) (*User, error)

Get a user by id.

func (*UsersService) List

func (s *UsersService) List(ctx context.Context) ([]*User, error)

List all available users.

func (*UsersService) Update

func (s *UsersService) Update(ctx context.Context, id string, req UserUpdateRequest) (*User, error)

Update the user identified by the given id with the given properties.

func (*UsersService) UpdateRole

func (s *UsersService) UpdateRole(ctx context.Context, id string, role UserRole) (*User, error)

UpdateRole updates the role of the user identified by the given id with the given properties.

type VersionService

type VersionService service

VersionService handles communication with the version related operations of the Axiom API.

Axiom API Reference: /api/v1/version

func (*VersionService) Get

func (s *VersionService) Get(ctx context.Context) (string, error)

Get the version of a deployment.

type VirtualField

type VirtualField struct {
	// ID is the unique ID of the virtual field.
	ID string `json:"id"`
	// Dataset the virtual field belongs to.
	Dataset string `json:"dataset"`
	// Name the virtual field is referenced by.
	Name string `json:"name"`
	// Description of the virtual field.
	Description string `json:"description"`
	// Expression that evaluates the virtual fields value.
	Expression string `json:"expression"`
}

VirtualField represents a virtual field of a dataset.

type VirtualFieldListOptions

type VirtualFieldListOptions struct {
	// Dataset to list virtual fields for. Required.
	Dataset string `url:"dataset"`

	ListOptions
}

VirtualFieldListOptions specifies the parameters for the List method of the VirtualFields service.

type VirtualFieldsService

type VirtualFieldsService service

VirtualFieldsService handles communication with the virtual field related operations of the Axiom API.

Axiom API Reference: /api/v1/vfields

func (*VirtualFieldsService) Create

Create a virtual field with the given properties.

func (*VirtualFieldsService) Delete

func (s *VirtualFieldsService) Delete(ctx context.Context, id string) error

Delete the virtual field identified by the given id.

func (*VirtualFieldsService) Get

Get a virtual field by id.

func (*VirtualFieldsService) List

List all available virtual fields.

func (*VirtualFieldsService) Update

Update the virtual field identified by the given id with the given properties.

Directories

Path Synopsis
Package apl provides the datatypes for construction APL.
Package apl provides the datatypes for construction APL.
Package query provides the datatypes for construction queries and working with their results.
Package query provides the datatypes for construction queries and working with their results.

Jump to

Keyboard shortcuts

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