Skip to content

Commit

Permalink
test(bench): add ch-bench compose
Browse files Browse the repository at this point in the history
  • Loading branch information
ernado committed Dec 16, 2023
1 parent c8d1cee commit 9df21b1
Show file tree
Hide file tree
Showing 8 changed files with 576 additions and 0 deletions.
21 changes: 21 additions & 0 deletions cmd/prombench/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 VictoriaMetrics

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
86 changes: 86 additions & 0 deletions cmd/prombench/cfg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package main

import (
"fmt"
"time"

"gopkg.in/yaml.v2"
)

func (c *config) marshalYAML() []byte {
data, err := yaml.Marshal(c)
if err != nil {
panic(err)
}
return data
}

func newConfig(targetsCount int, scrapeInterval time.Duration, targetAddr string) *config {
scs := make([]*staticConfig, 0, targetsCount)
for i := 0; i < targetsCount; i++ {
scs = append(scs, &staticConfig{
Targets: []string{targetAddr},
Labels: map[string]string{
"instance": fmt.Sprintf("host-%d", i),
"revision": "r0",
},
})
}
return &config{
Global: globalConfig{
ScrapeInterval: scrapeInterval,
},
ScrapeConfigs: []*scrapeConfig{
{
JobName: "node_exporter",
StaticConfigs: scs,
Path: "/node",
},
},
}
}

// config represents essential parts from Prometheus config defined at https://prometheus.io/docs/prometheus/latest/configuration/configuration/
type config struct {
Global globalConfig `yaml:"global"`
ScrapeConfigs []*scrapeConfig `yaml:"scrape_configs,omitempty"`
RemoteWrites []*remoteWriteConfig `yaml:"remote_write,omitempty"`
}

// globalConfig represents essential parts for `global` section of Prometheus config.
//
// See https://prometheus.io/docs/prometheus/latest/configuration/configuration/
type globalConfig struct {
ScrapeInterval time.Duration `yaml:"scrape_interval"`
}

// rapeConfig represents essential parts for `scrape_config` section of Prometheus config.
//
// See https://prometheus.io/docs/prometheus/latest/configuration/configuration/#scrape_config
type scrapeConfig struct {
JobName string `yaml:"job_name"`
Path string `yaml:"metrics_path,omitempty"`
StaticConfigs []*staticConfig `yaml:"static_configs"`
}

// staticConfig represents essential parts for `static_config` section of Prometheus config.
//
// See https://prometheus.io/docs/prometheus/latest/configuration/configuration/#static_config
type staticConfig struct {
Targets []string `yaml:"targets"`
Labels map[string]string `yaml:"labels"`
}

// remoteWriteConfig represents essential parts for `remote_write` section of Prometheus config.
//
// https://prometheus.io/docs/prometheus/latest/configuration/configuration/#remote_write
type remoteWriteConfig struct {
URL string `yaml:"url"`
Name string `yaml:"name,omitempty"`
Metadata *remoteWriteMetadataConfig `yaml:"metadata_config,omitempty"`
}

type remoteWriteMetadataConfig struct {
Send bool `yaml:"send"`
SendInterval time.Duration `yaml:"send_interval,omitempty"`
}
Loading

0 comments on commit 9df21b1

Please sign in to comment.