lib

package
v0.0.0-...-c0d2ad2 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var WebhookHandler = func(callback Webhook) func(w http.ResponseWriter, r *http.Request) {
	return func(w http.ResponseWriter, r *http.Request) {
		if r.Method != "POST" {
			w.WriteHeader(http.StatusMethodNotAllowed)
			return
		}

		decoder := json.NewDecoder(r.Body)
		var report v1alpha1.MetricReport
		err := decoder.Decode(&report)
		if err != nil {
			log.Printf("[Webhook] ERR: %v", err)
			w.WriteHeader(http.StatusBadRequest)
			return
		}
		callback(report)
	}
}

Functions

This section is empty.

Types

type AdjustmentCorrelator

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

func NewAdjustmentCorrelator

func NewAdjustmentCorrelator(adjustmentsBufferFlushCap int, overshoot float64) (*AdjustmentCorrelator, error)

func NewDefaultAdjustmentCorrelator

func NewDefaultAdjustmentCorrelator() *AdjustmentCorrelator

func (*AdjustmentCorrelator) Recorrelate

func (c *AdjustmentCorrelator) Recorrelate()

Recorrelate correlate changes in metric reports with adjustments made (Config changes) in response. This information is then used to calculate how changing a Config value by 1.0 improves metrics, i.e. allows to answer a question: how will changing Config X by 1.0 improve metric Y value?

Algorithm

	Given the following input:
		[0] measurements = [100 (cpu utilization), 40 (ram)], adjustments = [(quality = -8),(pages = -4)]
		[1] measurements = [60  (cpu utilization), 20 (ram)], adjustments = [(quality = -6),(pages = -2)]
		[2] measurements = [40  (cpu utilization), 10 (ram)], adjustments = []

	In Stage 1:
		[0] [(quality = -8),(pages = -4)] -> [40 (100[0] - 60[1], cpu improvement), 20 (40[0] - 20[1], ram improvement)]
		[1] [(quality = -6),(pages = -2)] -> [20 (60[1] - 40[2],  cpu improvement), 10 (20[1] - 10[2], ram improvement)]

 In Stage 2:
		(quality = 1) -> {
			"cpu improvement": [
				[0]		-2.5 (40/2/-8), 2 = len(improvements)
				[1]		-1.6 (20/2/-6),
			],
			"ram improvement": [
				[0]		-1.25 (20/2/-8),
				[1]		-0.83 (10/2/-6),
			]
		},
		(pages = 1)   -> {
			"cpu improvement": [
				[0]		-5   (40/2/-4),
				[1]		-5   (20/2/-2),
			],
			"ram improvement": [
				[0]		-2.5  (20/2/-4),
				[1]		-2.5  (20/2/-4),
			]
		}

	In Stage 3:
		(quality = 1) -> {
			"cpu improvement":	-2.05 ((-2.5 + -1.6) / 2),
			"ram improvement":	-1.04 ((-1.25 + -0.83) / 2),
		},
		(pages = 1)   -> {
			"cpu improvement":	-5    ((-5 + -5) / 2),
			"ram improvement":	-2.5  ((-2.5 + -2.5) / 2),
		},

func (*AdjustmentCorrelator) RegisterAdjustments

func (c *AdjustmentCorrelator) RegisterAdjustments(report v1alpha1.MetricReport, appliedAdjustments Adjustments)

func (*AdjustmentCorrelator) SuggestAdjustments

func (c *AdjustmentCorrelator) SuggestAdjustments(metricsReported v1alpha1.MetricReport) Adjustments

type AdjustmentRound

type AdjustmentRound struct {
	Measurements Measurements
	Adjustments  Adjustments
}

type Adjustments

type Adjustments = map[Config]float64

type AverageCorrelations

type AverageCorrelations = map[Config]map[Metric]AverageMeasurement

type AverageMeasurement

type AverageMeasurement struct {
	Value Measurement
	Among int
}

func NewAverageMeasurement

func NewAverageMeasurement(improvements ...Measurement) AverageMeasurement

func (AverageMeasurement) Concat

func (a AverageMeasurement) Concat(improvements ...Measurement) AverageMeasurement

type Config

type Config = string

type Correlations

type Correlations = map[Config]map[Metric][]Measurement

type Measurement

type Measurement struct {
	Value       float64
	Utilization float64
}

func NewMeasurement

func NewMeasurement(quantity resource.Quantity, utilization *int32) Measurement

func (Measurement) GoesInto

func (i Measurement) GoesInto(m Measurement) float64

func (Measurement) Scale

func (i Measurement) Scale(f float64) Measurement

func (Measurement) Sub

type Measurements

type Measurements = map[Metric]Measurement

type Metric

type Metric = string

type Webhook

type Webhook func(report v1alpha1.MetricReport)

type WebhookServer

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

func NewWebhookServer

func NewWebhookServer(callback Webhook, cfgs ...*WebhookServerConfig) *WebhookServer

func (*WebhookServer) ListenAndServe

func (srv *WebhookServer) ListenAndServe()

func (*WebhookServer) Shutdown

func (srv *WebhookServer) Shutdown(ctx context.Context) error

type WebhookServerConfig

type WebhookServerConfig struct {
	Addr         string
	ReadTimeout  time.Duration
	WriteTimeout time.Duration
	IdleTimeout  time.Duration
	WebhookPath  string
}

func DefaultWebhookServerConfig

func DefaultWebhookServerConfig() *WebhookServerConfig

Jump to

Keyboard shortcuts

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