bench

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2023 License: Apache-2.0 Imports: 40 Imported by: 0

Documentation

Overview

Copyright 2019 grafana

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.

Copied from github.com/grafana/cortex-tools

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.

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.

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.

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.

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

View Source
var UserAgent = fmt.Sprintf("Benchtool/%s", version.Version)

Functions

func AddLabelToLabelSet

func AddLabelToLabelSet(labelSets [][]prompb.Label, lbl LabelDesc) [][]prompb.Label

func JitterUp

func JitterUp(duration time.Duration, jitter float64) time.Duration

JitterUp adds random jitter to the duration.

This adds or subtracts time from the duration within a given jitter fraction. For example for 10s and jitter 0.1, it will return a time within [9s, 11s])

Reference: https://godoc.org/github.com/grpc-ecosystem/go-grpc-middleware/util/backoffutils

func NewQueryClient

func NewQueryClient(url, tenantName, username, password string) (v1.API, error)

func ShardByAllLabels

func ShardByAllLabels(userID string, labels []prompb.Label) uint32

This function generates different values for different order of same labels.

func ShardByUser

func ShardByUser(userID string) uint32

Types

type BatchReq

type BatchReq struct {
	Batch   []prompb.TimeSeries
	Wg      *sync.WaitGroup
	PutBack chan []prompb.TimeSeries
}

type Config

type Config struct {
	ID               string `yaml:"id"`
	InstanceName     string `yaml:"instance_name"`
	WorkloadFilePath string `yaml:"workload_file_path"`

	RingCheck RingCheckConfig  `yaml:"ring_check"`
	Write     WriteBenchConfig `yaml:"writes"`
	Query     QueryConfig      `yaml:"query"`
}

func (*Config) RegisterFlags

func (cfg *Config) RegisterFlags(f *flag.FlagSet)

type ExprTemplateData

type ExprTemplateData struct {
	Name     string
	Matchers string
}

type LabelDesc

type LabelDesc struct {
	Name         string `yaml:"name"`
	ValuePrefix  string `yaml:"value_prefix"`
	UniqueValues int    `yaml:"unique_values"`
}

type Query

type Query struct {
	Interval  time.Duration
	TimeRange time.Duration
	Expr      string
}

type QueryConfig

type QueryConfig struct {
	Enabled           bool   `yaml:"enabled"`
	Endpoint          string `yaml:"endpoint"`
	BasicAuthUsername string `yaml:"basic_auth_username"`
	BasicAuthPasword  string `yaml:"basic_auth_password"`
}

func (*QueryConfig) RegisterFlags

func (cfg *QueryConfig) RegisterFlags(f *flag.FlagSet)

type QueryDesc

type QueryDesc struct {
	NumQueries               int           `yaml:"num_queries"`
	ExprTemplate             string        `yaml:"expr_template"`
	RequiredSeriesType       SeriesType    `yaml:"series_type"`
	Interval                 time.Duration `yaml:"interval"`
	TimeRange                time.Duration `yaml:"time_range,omitempty"`
	Regex                    bool          `yaml:"regex"`
	InjectExactSerierMatcher bool          `yaml:"inject_exact_series_matcher"`
}

type QueryRunner

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

func NewQueryRunner

func NewQueryRunner(id string, tenantName string, cfg QueryConfig, workload *QueryWorkload, logger log.Logger, reg prometheus.Registerer) (*QueryRunner, error)

func (*QueryRunner) ExecuteQuery

func (q *QueryRunner) ExecuteQuery(ctx context.Context, queryReq Query) error

func (*QueryRunner) GetRandomAPIClient

func (q *QueryRunner) GetRandomAPIClient() (v1.API, error)

func (*QueryRunner) QueryWorker

func (q *QueryRunner) QueryWorker(queryChan chan Query)

func (*QueryRunner) ResolveAddrs

func (q *QueryRunner) ResolveAddrs() error

func (*QueryRunner) ResolveAddrsLoop

func (q *QueryRunner) ResolveAddrsLoop(ctx context.Context)

func (*QueryRunner) Run

func (q *QueryRunner) Run(ctx context.Context) error

type QueryWorkload

type QueryWorkload struct {
	Queries []Query
}

func NewQueryWorkload

func NewQueryWorkload(id string, desc WorkloadDesc) (*QueryWorkload, error)

type RingCheckConfig

type RingCheckConfig struct {
	Enabled       bool                `yaml:"enabled"`
	MemberlistKV  memberlist.KVConfig `yaml:"memberlist"`
	RingConfig    ring.Config         `yaml:"ring"`
	CheckInterval time.Duration       `yaml:"check_interval"`
}

func (*RingCheckConfig) RegisterFlagsWithPrefix

func (cfg *RingCheckConfig) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet)

type RingChecker

type RingChecker struct {
	Ring         *ring.Ring
	MemberlistKV *memberlist.KVInitService
	// contains filtered or unexported fields
}

func NewRingChecker

func NewRingChecker(id string, instanceName string, cfg RingCheckConfig, workload *WriteWorkload, logger log.Logger) (*RingChecker, error)

func (*RingChecker) Check

func (r *RingChecker) Check()

func (*RingChecker) Run

func (r *RingChecker) Run(ctx context.Context) error

type Runner

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

func NewBenchRunner

func NewBenchRunner(cfg Config, logger log.Logger, reg prometheus.Registerer) (*Runner, error)

func (*Runner) Run

func (b *Runner) Run(ctx context.Context) error

type SeriesDesc

type SeriesDesc struct {
	Name         string            `yaml:"name"`
	Type         SeriesType        `yaml:"type"`
	StaticLabels map[string]string `yaml:"static_labels"`
	Labels       []LabelDesc       `yaml:"labels"`
}

type SeriesType

type SeriesType string
const (
	GaugeZero     SeriesType = "gauge-zero"
	GaugeRandom   SeriesType = "gauge-random"
	CounterOne    SeriesType = "counter-one"
	CounterRandom SeriesType = "counter-random"
)

type TenantIDRoundTripper

type TenantIDRoundTripper struct {
	TenantName string
	Next       http.RoundTripper
}

func (*TenantIDRoundTripper) RoundTrip

func (r *TenantIDRoundTripper) RoundTrip(req *http.Request) (*http.Response, error)

type Timeseries

type Timeseries struct {
	LabelSets  [][]prompb.Label
	LastValue  float64
	SeriesType SeriesType
}

func SeriesDescToSeries

func SeriesDescToSeries(seriesDescs []SeriesDesc) ([]*Timeseries, map[SeriesType]int)

type WorkloadDesc

type WorkloadDesc struct {
	Replicas  int          `yaml:"replicas"`
	Series    []SeriesDesc `yaml:"series"`
	QueryDesc []QueryDesc  `yaml:"queries"`
	Write     WriteDesc    `yaml:"write_options"`
}

type WriteBenchConfig

type WriteBenchConfig struct {
	Enabled           bool   `yaml:"enabled"`
	Endpoint          string `yaml:"endpoint"`
	BasicAuthUsername string `yaml:"basic_auth_username"`
	BasicAuthPasword  string `yaml:"basic_auth_password"`
	ProxyURL          string `yaml:"proxy_url"`
}

func (*WriteBenchConfig) RegisterFlags

func (cfg *WriteBenchConfig) RegisterFlags(f *flag.FlagSet)

type WriteBenchmarkRunner

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

func NewWriteBenchmarkRunner

func NewWriteBenchmarkRunner(id string, tenantName string, cfg WriteBenchConfig, workload *WriteWorkload, logger log.Logger, reg prometheus.Registerer) (*WriteBenchmarkRunner, error)

func (*WriteBenchmarkRunner) GetRandomWriteClient

func (w *WriteBenchmarkRunner) GetRandomWriteClient() (*WriteClient, error)

func (*WriteBenchmarkRunner) ResolveAddrs

func (w *WriteBenchmarkRunner) ResolveAddrs() error

func (*WriteBenchmarkRunner) ResolveAddrsLoop

func (w *WriteBenchmarkRunner) ResolveAddrsLoop(ctx context.Context)

func (*WriteBenchmarkRunner) Run

Run starts a loop that forwards metrics to the configured remote write endpoint

func (*WriteBenchmarkRunner) SendBatch

func (w *WriteBenchmarkRunner) SendBatch(ctx context.Context, batch []prompb.TimeSeries) error

func (*WriteBenchmarkRunner) WriteWorker

func (w *WriteBenchmarkRunner) WriteWorker(batchChan chan BatchReq)

type WriteClient

type WriteClient struct {
	Client *http.Client
	// contains filtered or unexported fields
}

WriteClient allows reading and writing from/to a remote HTTP endpoint.

func NewWriteClient

func NewWriteClient(name string, tenantName string, conf *remote.ClientConfig, _ log.Logger, requestHistogram *prometheus.HistogramVec) (*WriteClient, error)

NewWriteClient creates a new client for remote write.

func (*WriteClient) Store

func (c *WriteClient) Store(ctx context.Context, req []byte) error

Store sends a batch of samples to the HTTP endpoint, the request is the proto marshalled and encoded bytes from codec.go.

type WriteDesc

type WriteDesc struct {
	Interval  time.Duration `yaml:"interval"`
	Timeout   time.Duration `yaml:"timeout"`
	BatchSize int           `yaml:"batch_size"`
}

type WriteWorkload

type WriteWorkload struct {
	Replicas           int
	Series             []*Timeseries
	TotalSeries        int
	TotalSeriesTypeMap map[SeriesType]int
	// contains filtered or unexported fields
}

func NewWriteWorkload

func NewWriteWorkload(workloadDesc WorkloadDesc, reg prometheus.Registerer) *WriteWorkload

func (*WriteWorkload) GenerateTimeSeries

func (w *WriteWorkload) GenerateTimeSeries(id string, t time.Time) []prompb.TimeSeries

func (*WriteWorkload) GenerateWriteBatch

func (w *WriteWorkload) GenerateWriteBatch(ctx context.Context, id string, numBuffers int, seriesChan chan BatchReq) error

func (*WriteWorkload) GetSeriesBuffer

func (w *WriteWorkload) GetSeriesBuffer(ctx context.Context) []prompb.TimeSeries

Jump to

Keyboard shortcuts

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