datastore

package
v0.2.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Emulator

func Emulator(ctx context.Context) <-chan struct{}

Emulator instantiates datastore emulator for use in tests.

Background: this was devised due to aetest package no longer being available for 1.12+ runtimes as dev_appserver.py cannot run runtimes past go111, see: https://github.com/googleapis/google-cloud-go/issues/644

  Usage:

	 ctx, cancel := context.WithCancel(context.Background())
	 // Save the emulator's quit channel.
	 quit := Emulator(ctx)
	 code := m.Run()
	 cancel()
	 // Wait for channel close
	 <-quit

Types

type Manager

type Manager struct {
	Client *datastore.Client
}

Manager struct implementing the storage.Manager interface

func New

func New(ctx context.Context, options *Options) *Manager

New initializes the Manager struct implementing a generic storage.Manager interface

func (*Manager) CleanupRecords

func (d *Manager) CleanupRecords(ctx context.Context, keep []string) error

CleanupRecords removes obsolete metric records from Datastore.

`keep` represents metrics to be kept, all others will be purged

func (*Manager) Close

func (d *Manager) Close() error

Close function exists here for compatibility as Datastore doesn't need to be closed

func (*Manager) NewMetricRecord

func (d *Manager) NewMetricRecord(ctx context.Context, name, query string) (storage.MetricRecord, error)

NewMetricRecord returns a Datastore-based metric record for a given metric name.

type Options

type Options struct {
	// Project sets the GCP project to use for communicating to datastore.
	Project string
}

Options holds settings specific to datastore

type StoredMetricRecord

type StoredMetricRecord struct {
	Name        string
	Query       string
	LastUpdate  time.Time // last time we wrote any points to SD.
	LastAttempt time.Time // last time we attempted an update.
	LastStatus  string

	// CounterStartTime is used to keep start timestamp for cumulative metrics.
	CounterStartTime time.Time

	// Storage provides access to
	Storage *Manager
}

StoredMetricRecord defines a Datastore entity that is used to store status information about an imported metric.

func (*StoredMetricRecord) GetCounterStartTime

func (m *StoredMetricRecord) GetCounterStartTime() time.Time

GetCounterStartTime returns CounterStartTime.

func (*StoredMetricRecord) GetLastUpdate

func (m *StoredMetricRecord) GetLastUpdate() time.Time

GetLastUpdate returns LastUpdate timestamp.

func (*StoredMetricRecord) SetCounterStartTime

func (m *StoredMetricRecord) SetCounterStartTime(ctx context.Context, start time.Time) error

SetCounterStartTime sets CounterStartTime and persists metric data.

func (*StoredMetricRecord) UpdateError

func (m *StoredMetricRecord) UpdateError(ctx context.Context, e error) error

UpdateError updates metric status in Datastore with a given error message.

func (*StoredMetricRecord) UpdateSuccess

func (m *StoredMetricRecord) UpdateSuccess(ctx context.Context, points int, msg string) error

UpdateSuccess updates metric status in Datastore with a given message.

Jump to

Keyboard shortcuts

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