backend

package
v0.0.0-...-e560ebb Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2021 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddIncident

func AddIncident(c context.Context, id string, serviceID string, severity Severity) error

AddIncident writes an incident to datastore.

On success, nil is returned. If no Service with the given serviceID is found or if a ServiceIncident with the same ID is found, err is returned. If there is a datastore error err is returned.

func CloseIncident

func CloseIncident(c context.Context, id, serviceID string) error

CloseIncident updates an existing ServiceIncident by setting a value for the EndTime to the current time.

It returns nil on success. If there is an error getting the Incident or updating the Incident, or the Incident was never found, err will be returned.

func ConvertPlatforms

func ConvertPlatforms(platforms []*Platform) (convertedPlatforms []*dashpb.Platform)

ConvertPlatforms takes a slice of Platforms and returns equivalent dasphpb.Platforms.

func CreateLiveAnnouncement

func CreateLiveAnnouncement(c context.Context, message, creator string, platforms []*Platform) (*dashpb.Announcement, error)

CreateLiveAnnouncement takes announcement information and Platforms to build an Announcement and adds AnnouncementKeys to all platforms and puts all structs in Datastore.

It returns (announcement, nil) on success, and (nil, err) on datastore errors.

func GetAllAnnouncementsPlatforms

func GetAllAnnouncementsPlatforms(c context.Context, announcements []*Announcement) ([]*dashpb.Announcement, error)

GetAllAnnouncementsPlatforms takes Announcements that have incomplete or empty Platforms, fetches the platforms from datastore, and returns everything in dashpb.Announcements.

It returns (announcements, nil) on success, and (nil, err) on datastore or conversion errors.

func ListAnnouncements

func ListAnnouncements(c context.Context, announcementIDs ...int64) ([]*dashpb.Announcement, error)

ListAnnouncements returns dashpb.Announcements for all given announcementIDs.

It returns (announcements, nil) on success, and (nil, err) on datastore or conversion errors.

func RetireAnnouncement

func RetireAnnouncement(c context.Context, announcementID int64, closer string) error

RetireAnnouncement sets a given announcement's retired to true.

It returns nil on success and err on datastore errors.

func SearchAnnouncements

func SearchAnnouncements(c context.Context, platformName string, retired bool, limit, offset int32) ([]*dashpb.Announcement, error)

SearchAnnouncements returns dashpb.Announcements. If a platformName is specified, only Announcements that are ancestor to the platform will be returned. If offset or limit are < 0, they will be ignored. The returned Announcements will be either all retired, or all not retired.

It returns (announcements, nil) on success, and (nil, err) on datastore or conversion errors.

Types

type Announcement

type Announcement struct {
	ID            int64 `gae:"$id"`
	Retired       bool
	StartTime     time.Time
	EndTime       time.Time
	Message       string
	Creator       string
	Closer        string
	PlatformNames []string
}

Announcement contains details of an announcement

func (*Announcement) ToProto

func (a *Announcement) ToProto(platforms []*Platform) (*dashpb.Announcement, error)

ToProto takes a slice of Platforms that is assumed to belong to the Announcement a, and returns a dasphpb.Announcement equivalent.

It returns (aProto, nil) on successful conversion or (nil, err) if there was an error while converting timestamps.

type IncidentStatus

type IncidentStatus int

IncidentStatus represents a status category of a ServiceIncident.

const (
	// IncidentStatusAny represents a status that is either Open or Closed.
	IncidentStatusAny IncidentStatus = iota
	// IncidentStatusOpen represents the status of Open ServiceIncidents.
	IncidentStatusOpen
	// IncidentStatusClosed represents the status of Closed ServiceIncidents.
	IncidentStatusClosed
)

type Platform

type Platform struct {
	AnnouncementKey *datastore.Key `gae:"$parent"`
	Name            string         `gae:"$id"`
	URLPaths        []string
}

Platform contains information for where and how an ancestor Announcement should be displayed.

func (*Platform) ToProto

func (p *Platform) ToProto() *dashpb.Platform

ToProto returns a dasphpb.Platforms equivalent.

type QueryOptions

type QueryOptions struct {
	After  time.Time      // if non-zero, a start of time range to fetch
	Before time.Time      // if non-zero, an end of time range to fetch
	Status IncidentStatus // indicates the status the fetched incidents should have
}

QueryOptions contains maps for additional query options that indicate interface{} value the fields should match.

func (*QueryOptions) BuildQuery

func (q *QueryOptions) BuildQuery(query *datastore.Query, timeField string) (*datastore.Query, error)

BuildQuery builds a datastore Query from the values of this QueryOptions. If this QueryOptions has a non-zero After or a non-zero Before and a timeField is not provided, an error will be thrown.

It returns (query, nil) on success or (nil, err) if the timeField is empty while either After or Before is non-zero.

type Service

type Service struct {
	ID   string `gae:"$id"` // eg. "monorail", "som"
	Name string // eg. "Monorail", "Sheriff-O-Matic"
	SLA  string
}

Service contains basic service information and has ServiceIncidents as child entities.

func GetAllServices

func GetAllServices(c context.Context) ([]Service, error)

GetAllServices gets all Service entities from datastore.

It returns (services, nil) on success or () (nil, err) on datastore errors.

func GetService

func GetService(c context.Context, serviceID string) (*Service, error)

GetService gets the specified Service from datastore.

It returns (service, nil) on success, (nil, nil) if such service is not found or (nil, err) on datastore errors.

type ServiceIncident

type ServiceIncident struct {
	ID         string         `gae:"$id"`
	ServiceKey *datastore.Key `gae:"$parent"`
	Open       bool
	StartTime  time.Time
	EndTime    time.Time
	Severity   Severity
}

ServiceIncident contains incident details and its parent service key.

func GetIncident

func GetIncident(c context.Context, id string, serviceID string) (*ServiceIncident, error)

GetIncident gets the specified ServiceIncident from datastore.

It returns (incident, nil) on success, (nil, nil) if such incident is not found or (nil, err) on datastore errors

func GetServiceIncidents

func GetServiceIncidents(c context.Context, serviceID string, queryOpts *QueryOptions) ([]ServiceIncident, error)

GetServiceIncidents gets all the incidents of the given service. If onlyOpen is true, this will only return open Incidents. If it is false it will return all Incidents, open and closed.

It returns (incidents, nil) on success or (nil, err) on datastore errors. If no incidents for the service were found, incidents will be empty.

type Severity

type Severity int

Severity represents the alert type.

const (

	// SeverityRed represents paging alerts.
	SeverityRed Severity
	// SeverityYellow represents email alerts.
	SeverityYellow
)

Jump to

Keyboard shortcuts

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