strategies

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Copyright 2020 Pradyumna Kaushik

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Build

func Build(s Interface, options ...Option) error

Build the strategy object.

Types

type Interface

type Interface interface {
	// Initialize any other internal data structure and perform any further setup operations.
	Init()
	// SetPrometheusScrapeInterval sets the prometheus scrape interval.
	SetPrometheusScrapeInterval(time.Duration)
	// SetTaskRanksReceiver registers a receiver of the task ranking results.
	// This receiver is a callback and is used to pass the result of applying
	// the strategy to rank tasks.
	SetTaskRanksReceiver(TaskRanksReceiver)
	// Execute the strategy.
	Execute(model.Value)
	// GetMetric returns the metric to pull data for.
	// Note: This has to be a single metric name.
	GetMetric() string
	// SetLabelMatchers sets the label matchers to use to filter data.
	// Strategy implementations can perform additional validations on the provided label matchers.
	SetLabelMatchers([]*query.LabelMatcher) error
	// GetLabelMatchers returns the labels and corresponding matching operators to use
	// filter out data that is not required by this strategy.
	GetLabelMatchers() []*query.LabelMatcher
	// Range returns the duration specifying how far back in time data needs to be fetched.
	// Returns the unit of time along with an integer quantifying the duration.
	GetRange() (query.TimeUnit, uint)
	// SetRange sets the time duration for the range query.
	SetRange(query.TimeUnit, uint)
}

type Option added in v0.5.0

type Option func(Interface) error

Options for configuring strategies.

func WithLabelMatchers added in v0.5.0

func WithLabelMatchers(labelMatchers []*query.LabelMatcher) Option

WithLabelMatchers returns an option that initializes the label matchers to be used by the strategy.

func WithPrometheusScrapeInterval added in v0.5.0

func WithPrometheusScrapeInterval(prometheusScrapeInterval time.Duration) Option

WithPrometheusScrapeInterval returns an option that initializes the prometheus scrape interval.

func WithRange added in v0.5.0

func WithRange(timeUnit query.TimeUnit, qty uint) Option

WithRange returns an option that initializes the time unit and duration, if using range queries.

func WithTaskRanksReceiver added in v0.5.0

func WithTaskRanksReceiver(receiver TaskRanksReceiver) Option

WithTaskRanksReceiver returns an option that initializes the receiver to which the task ranking results are submitted.

type TaskRankCpuSharesStrategy

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

TaskRankCpuSharesStrategy is a task ranking strategy that ranks the tasks in non-increasing order based on the cpu-shares allocated to tasks.

func (*TaskRankCpuSharesStrategy) Execute

func (s *TaskRankCpuSharesStrategy) Execute(data model.Value)

Execute the strategy using the provided data.

func (TaskRankCpuSharesStrategy) GetLabelMatchers

func (s TaskRankCpuSharesStrategy) GetLabelMatchers() []*query.LabelMatcher

GetLabelMatchers returns the label matchers to be used to filter data.

func (TaskRankCpuSharesStrategy) GetMetric

func (s TaskRankCpuSharesStrategy) GetMetric() string

GetMetric returns the name of the metric to query.

func (TaskRankCpuSharesStrategy) GetRange

func (s TaskRankCpuSharesStrategy) GetRange() (query.TimeUnit, uint)

GetRange returns the time unit and duration for how far back values need to be fetched.

func (*TaskRankCpuSharesStrategy) Init added in v0.4.0

func (s *TaskRankCpuSharesStrategy) Init()

func (*TaskRankCpuSharesStrategy) SetLabelMatchers

func (s *TaskRankCpuSharesStrategy) SetLabelMatchers(labelMatchers []*query.LabelMatcher) error

SetLabelMatchers sets the label matchers to use to filter data. This strategy mandates that a dedicated label be provided for filtering metrics based on TaskID and Hostname.

func (*TaskRankCpuSharesStrategy) SetPrometheusScrapeInterval added in v0.5.0

func (s *TaskRankCpuSharesStrategy) SetPrometheusScrapeInterval(_ time.Duration)

func (*TaskRankCpuSharesStrategy) SetRange added in v0.5.0

func (s *TaskRankCpuSharesStrategy) SetRange(timeUnit query.TimeUnit, qty uint)

SetRange sets the time duration for the range query.

func (*TaskRankCpuSharesStrategy) SetTaskRanksReceiver

func (s *TaskRankCpuSharesStrategy) SetTaskRanksReceiver(receiver TaskRanksReceiver)

SetTaskRanksReceiver sets the receiver of the results of task ranking.

type TaskRankCpuUtilStrategy added in v0.4.0

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

TaskRankCpuUtilStrategy is a task ranking strategy that ranks the tasks in non-increasing order based on the cpu utilization (%) in the past 5 intervals of time.

For example, if Prometheus scrapes metrics every 1s, then each time interval is 1s long. This strategy then would then rank tasks based on their cpu utilization in the past 5 seconds.

func (*TaskRankCpuUtilStrategy) Execute added in v0.4.0

func (s *TaskRankCpuUtilStrategy) Execute(data model.Value)

Execute the strategy using the provided data.

func (TaskRankCpuUtilStrategy) GetLabelMatchers added in v0.4.0

func (s TaskRankCpuUtilStrategy) GetLabelMatchers() []*query.LabelMatcher

GetLabelMatchers returns the label matchers to be used to filter data.

func (TaskRankCpuUtilStrategy) GetMetric added in v0.4.0

func (s TaskRankCpuUtilStrategy) GetMetric() string

GetMetric returns the name of the metric to query.

func (TaskRankCpuUtilStrategy) GetRange added in v0.4.0

func (s TaskRankCpuUtilStrategy) GetRange() (query.TimeUnit, uint)

GetRange returns the time unit and duration for how far back (in seconds) values need to be fetched.

func (*TaskRankCpuUtilStrategy) Init added in v0.4.0

func (s *TaskRankCpuUtilStrategy) Init()

func (*TaskRankCpuUtilStrategy) SetLabelMatchers added in v0.4.0

func (s *TaskRankCpuUtilStrategy) SetLabelMatchers(labelMatchers []*query.LabelMatcher) error

SetLabelMatchers sets the label matchers to use when filtering data. This strategy mandates that a dedicated label be provided for filtering metrics based on TaskID and Hostname.

func (*TaskRankCpuUtilStrategy) SetPrometheusScrapeInterval added in v0.5.0

func (s *TaskRankCpuUtilStrategy) SetPrometheusScrapeInterval(prometheusScrapeInterval time.Duration)

SetPrometheusScrapeInterval sets the scrape interval of prometheus.

func (*TaskRankCpuUtilStrategy) SetRange added in v0.5.0

func (s *TaskRankCpuUtilStrategy) SetRange(timeUnit query.TimeUnit, qty uint)

SetRange sets the time duration for the range query. For cpu-util ranking strategy the time duration has to be > 1s as you need two data points to calculate cpu utilization. If the provided time duration <= 1s, the default duration of 5 intervals of time is used, where each interval of time is equal to the prometheus scrape interval.

func (*TaskRankCpuUtilStrategy) SetTaskRanksReceiver added in v0.4.0

func (s *TaskRankCpuUtilStrategy) SetTaskRanksReceiver(receiver TaskRanksReceiver)

SetTaskRanksReceiver sets the receiver of the task ranking results.

type TaskRanksReceiver

type TaskRanksReceiver interface {
	// Receive the ranked tasks and their corresponding information.
	// Task at position i is ranked higher than task at position i+1.
	Receive(entities.RankedTasks)
}

TaskRanksReceiver defines an API to be implemented by all receivers of task ranking results.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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