genericadapter

package
v0.0.0-...-d38b3e6 Latest Latest
Warning

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

Go to latest
Published: May 11, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package genericadapter provides a configurable MonitoringAdapter that works with advanced agreement schema.

Usage:

ma := genericadapter.New(retriever, processor)
ma = ma.Initialize(&agreement)
for _, gt := range gts {
	for values := range ma.GetValues(gt, ...) {
		...
	}
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Aggregate

func Aggregate(v model.Variable, values []model.MetricValue) []model.MetricValue

Aggregate performs an aggregation function on the input.

This expects that all the values are in the appropriate window. For that, the Retrieve function needs to return only the values in the window. If not, this function will return an invalid result.

func Identity

func Identity(v model.Variable, values []model.MetricValue) []model.MetricValue

Identity returns the input

func Mount

func Mount(valuesmap map[model.Variable][]model.MetricValue,
	lastvalues map[string]model.MetricValue,
	maxdelta float64) amodel.GuaranteeData

Mount builds the GuaranteeData structure, directly used for agreement assessment, considering constant interpolation.

Constant interpolation means that for a variable whose value is not known at a time t, it is considered that it has the value of last known value.

It receives the metric series separated by metric name and returns the metric series grouped by point sets that occur at the same time (actually, in a delta minor than the maxdelta parameter).

A point is considered a MetricValue. An amodel.ExpressionData is called here a point set, i.e. the set of MetricValues needed for evaluating an agreement at some instant t. The current point of a series is the next value to consider, and it is determined by the series index.

The algorithm is:

	1 take the first in time of all current points
	2 build a pointset with all the points that happen in a delta less than deltamax
  		- if for a variable there is no point in delta, take the last known value for it.
	 	- if not all values of variables can have a value
		(this can happen if there are not values in lastvalues), discard the point set.
	3 goto 1 if there are more values to consider

Example (considering no last values):

3        o-----
2    o---      o----
1      x----   x----
0           x--

The point sets are: (o=2,x=1), (o=3,x=1), (o=3,x=0), (o=2,x=1). The first pointset is discarded, as there it not known value for x.

func New

func New(retrieve Retrieve, process Process) monitor.MonitoringAdapter

New is a helper function to build an Adapter from a Retriever and the Process function.

Types

type Adapter

type Adapter struct {
	Retrieve Retrieve
	Process  Process
	// contains filtered or unexported fields
}

Adapter is the type of a customizable adapter.

The Retrieve field is a function to query data to monitoring; the Process field is a function to perform additional processing on data.

Two Process functions are provided in the package: Identity (returns the input) and Aggregation (aggregates values according to the aggregation type)

func (*Adapter) GetValues

func (ga *Adapter) GetValues(gt model.Guarantee, varnames []string, now time.Time) amodel.GuaranteeData

GetValues implements Monitoring.GetValues().

func (*Adapter) Initialize

func (ga *Adapter) Initialize(a *model.Agreement) monitor.MonitoringAdapter

Initialize implements MonitoringAdapter.Initialize().

Usage:

ga := GenericAdapter{
	Retrieve: randomRetrieve,
	Process: Aggregation,
}
ga := ga.Initialize(agreement)
for _, gt := range gts {
	for values := range ga.GetValues(gt, ...) {
		...
	}
}

type DummyRetriever

type DummyRetriever struct {
	// Size is the number of values that the retrieval returns per metric
	Size int
}

DummyRetriever is a simple struct that generates a RetrieveFunction that works similar to the DummyAdapter, returning random values for each variable.

Usage:

adapter := Adapter { Retrieve: DummyRetriever{3}.RetrieveFunction() }

func (DummyRetriever) Retrieve

func (r DummyRetriever) Retrieve() Retrieve

Retrieve returns a Retrieve function.

type Process

type Process func(v model.Variable, values []model.MetricValue) []model.MetricValue

Process is the type of the function that performs additional custom processing on retrieved data.

type Retrieve

type Retrieve func(agreement model.Agreement, items []monitor.RetrievalItem) map[model.Variable][]model.MetricValue

Retrieve is the type of the function that makes the actual request to monitoring.

It receives the list of variables to be able to retrieve all of them at once if possible.

Jump to

Keyboard shortcuts

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