Documentation
¶
Overview ¶
Copyright 2025 SGNL.ai, Inc.
Copyright 2025 SGNL.ai, Inc.
Copyright 2025 SGNL.ai, Inc.
Copyright 2025 SGNL.ai, Inc.
Copyright 2025 SGNL.ai, Inc.
Copyright 2025 SGNL.ai, Inc.
ABOUTME: Response processing utilities for Rootly JSON:API responses. ABOUTME: Handles enrichment of incident data with included relationships.
Copyright 2025 SGNL.ai, Inc.
Index ¶
- func ConstructEndpoint(request *Request) string
- func EnrichAllIncidentData(data []map[string]any, included []map[string]any) []map[string]any
- func EnrichIncidentData(dataObject map[string]any, included []map[string]any) map[string]any
- func NewAdapter(client Client) framework.Adapter[Config]
- type Adapter
- func (a *Adapter) GetPage(ctx context.Context, request *framework.Request[Config]) framework.Response
- func (a *Adapter) RequestPageFromDatasource(ctx context.Context, request *framework.Request[Config]) framework.Response
- func (a *Adapter) ValidateGetPageRequest(ctx context.Context, request *framework.Request[Config]) *framework.Error
- type Client
- type Config
- type Datasource
- type DatasourceErrorResponse
- type DatasourceResponse
- type IncludedItemProcessor
- type Request
- type Response
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConstructEndpoint ¶
ConstructEndpoint constructs the endpoint URL for the given request.
func EnrichAllIncidentData ¶ added in v1.61.1
EnrichAllIncidentData enriches all incident data objects with their included items.
func EnrichIncidentData ¶ added in v1.61.1
EnrichIncidentData enriches a single incident data object with its included items.
Types ¶
type Adapter ¶
type Adapter struct {
RootlyClient Client
}
Adapter implements the framework.Adapter interface to query pages of objects from datasources.
func (*Adapter) GetPage ¶
func (a *Adapter) GetPage(ctx context.Context, request *framework.Request[Config]) framework.Response
GetPage is called by SGNL's ingestion service to query a page of objects from a datasource.
type Client ¶
type Client interface {
GetPage(ctx context.Context, request *Request) (*Response, *framework.Error)
}
Client is a client that allows querying the Rootly datasource which contains JSON objects.
type Config ¶
type Config struct {
// Common configuration
*config.CommonConfig
// APIVersion is the Rootly API version to use for requests.
APIVersion string `json:"apiVersion,omitempty"`
// Filters contains a map of filters for each entity associated with this
// datasource. The key is the entity's external_name, and the value is the filter string.
Filters map[string]string `json:"filters,omitempty"`
// Includes contains a map of fields to include for each entity associated with this
// datasource. The key is the entity's external_name, and the value is a comma-separated
// list of fields to include in the response.
Includes map[string]string `json:"includes,omitempty"`
}
Config is the configuration passed in each GetPage calls to the adapter. Adapter configuration example: nolint: godot
{
"requestTimeoutSeconds": 10,
"apiVersion": "v1",
"filters": {
"users": "email=rufus_raynor@hegmann.test",
"incidents": "status=started&severity=high"
},
"includes": {
"users": "role,email_addresses",
"incidents": "roles"
}
}
type Datasource ¶
Datasource directly implements a Client interface to allow querying an external datasource.
type DatasourceErrorResponse ¶
type DatasourceResponse ¶
type IncludedItemProcessor ¶ added in v1.61.1
type IncludedItemProcessor struct {
// contains filtered or unexported fields
}
IncludedItemProcessor processes included items and enriches incident data. It handles the extraction and flattening of nested relationships from Rootly's JSON:API format.
func NewIncludedItemProcessor ¶ added in v1.61.1
func NewIncludedItemProcessor(incidentID string, included []map[string]any) *IncludedItemProcessor
NewIncludedItemProcessor creates a new processor for the given incident ID.
func (*IncludedItemProcessor) ExtractEntities ¶ added in v1.61.1
func (p *IncludedItemProcessor) ExtractEntities() map[string][]any
ExtractEntities extracts and flattens entities of a specific type from all matching included items. Each entity will have a field_id property added for filtering. Returns a map where keys are entity types (e.g., "selected_users") and values are slices of flattened entities ([]any), to ensure compatibility with JSONPath filter expressions.
func (*IncludedItemProcessor) FindMatching ¶ added in v1.61.1
func (p *IncludedItemProcessor) FindMatching() []map[string]any
FindMatching returns all included items that belong to this incident. It matches based on the incident_id field in the attributes.
func (*IncludedItemProcessor) ProcessAndExpand ¶ added in v1.61.1
func (p *IncludedItemProcessor) ProcessAndExpand() []any
ProcessAndExpand processes matching included items and expands nested arrays. It flattens all selected_* entity types into individual items with metadata. Returns []any to ensure compatibility with JSONPath filter expressions.
type Request ¶
type Request struct {
// BaseURL is the Base URL of the datasource to query.
BaseURL string
// HTTPAuthorization is the HTTP authorization header value to authenticate a request.
// This will be provided in the form "Bearer <token>".
HTTPAuthorization string
// PageSize is the maximum number of objects to return from the entity.
PageSize int64
// EntityExternalID is the external ID of the entity.
// The external ID should match the API's resource name.
EntityExternalID string
// Cursor identifies the first object of the page to return, as returned by
// the last request for the entity.
// nil in the request for the first page.
Cursor *string
// Filter contains the optional filter to apply to the current request.
Filter string
// Includes contains the optional list of fields to include in the response.
Includes string
// RequestTimeoutSeconds is the timeout duration for requests made to datasources.
// This should be set to the number of seconds to wait before timing out.
RequestTimeoutSeconds int
}
Request is a request to Rootly.
type Response ¶
type Response struct {
// Objects contains the list of objects returned by the datasource.
Objects []map[string]any
// NextCursor identifies the first object of the next page to return.
// nil if the current page is the last page for the entity.
NextCursor *string
}
Response is a response returned by the datasource.