diff --git a/cmd/avalanche/avalanche.go b/cmd/avalanche/avalanche.go index bf8f6f8..8872c76 100644 --- a/cmd/avalanche/avalanche.go +++ b/cmd/avalanche/avalanche.go @@ -18,13 +18,9 @@ import ( "crypto/tls" "fmt" "log" - "math/rand" "net/http" "os" - "strconv" - "sync" "syscall" - "time" "github.com/nelkinda/health-go" "github.com/oklog/run" @@ -34,7 +30,6 @@ import ( "gopkg.in/alecthomas/kingpin.v2" "github.com/prometheus-community/avalanche/metrics" - "github.com/prometheus-community/avalanche/pkg/download" ) func main() { @@ -68,9 +63,6 @@ func main() { cfg := metrics.NewConfigFromFlags(kingpin.Flag) port := kingpin.Flag("port", "Port to serve at").Default("9001").Int() remoteURL := kingpin.Flag("remote-url", "URL to send samples via remote_write API.").URL() - // TODO(bwplotka): Kill pprof feature, you can install OSS continuous profiling easily instead. - remotePprofURLs := kingpin.Flag("remote-pprof-urls", "a list of urls to download pprofs during the remote write: --remote-pprof-urls=http://127.0.0.1:10902/debug/pprof/heap --remote-pprof-urls=http://127.0.0.1:10902/debug/pprof/profile").URLList() - remotePprofInterval := kingpin.Flag("remote-pprof-interval", "how often to download pprof profiles. When not provided it will download a profile once before the end of the test.").Duration() remoteConcurrencyLimit := kingpin.Flag("remote-concurrency-limit", "how many concurrent writes can happen at any given time").Default("20").Int() remoteBatchSize := kingpin.Flag("remote-batch-size", "how many samples to send with each remote_write API request.").Default("2000").Int() remoteRequestCount := kingpin.Flag("remote-requests-count", "How many requests to send in total to the remote_write API. Set to -1 to run indefinitely.").Default("100").Int() @@ -119,48 +111,11 @@ func main() { OutOfOrder: *outOfOrder, } - // Collect Pprof during the write only if not collecting within a regular interval. - if *remotePprofInterval == 0 { - config.PprofURLs = *remotePprofURLs - } - - var ( - wg sync.WaitGroup - done = make(chan struct{}) - ) - if *remotePprofInterval > 0 { - if len(*remotePprofURLs) == 0 { - log.Fatal("remote profiling interval specified without any remote pprof urls") - } - suffix := rand.Intn(1000) - go func() { - ticker := time.NewTicker(*remotePprofInterval) - var dur time.Duration - loop: - for { - <-ticker.C - select { - case <-done: // Prevents a panic when calling wg.Add(1) after calling wg.Wait(). - break loop - default: - } - dur += *remotePprofInterval - wg.Add(1) - download.URLs(*remotePprofURLs, strconv.Itoa(suffix)+"-"+dur.String()) - wg.Done() - } - }() - } - ctx, cancel := context.WithCancel(context.Background()) g.Add(func() error { if err := metrics.SendRemoteWrite(ctx, config, reg); err != nil { return err } - if *remotePprofInterval > 0 { - done <- struct{}{} - wg.Wait() - } return nil // One-off. }, func(error) { cancel() }) } diff --git a/metrics/write.go b/metrics/write.go index 38808e3..4144cb5 100644 --- a/metrics/write.go +++ b/metrics/write.go @@ -27,7 +27,6 @@ import ( "sync" "time" - "github.com/prometheus-community/avalanche/pkg/download" "github.com/prometheus-community/avalanche/pkg/errors" "github.com/gogo/protobuf/proto" @@ -129,7 +128,6 @@ func (c *Client) write(ctx context.Context) error { totalSamplesAct int mtx sync.Mutex wgMetrics sync.WaitGroup - wgPprof sync.WaitGroup merr = &errors.MultiError{} ) @@ -153,19 +151,10 @@ func (c *Client) write(ctx context.Context) error { } if !shouldRunForever { - if i < c.config.RequestCount { + if i >= c.config.RequestCount { break } i++ - // Download the pprofs during half of the iteration to get avarege readings. - // Do that only when it is not set to take profiles at a given interval. - if len(c.config.PprofURLs) > 0 && i == c.config.RequestCount/2 { - wgPprof.Add(1) - go func() { - download.URLs(c.config.PprofURLs, time.Now().Format("2-Jan-2006-15:04:05")) - wgPprof.Done() - }() - } } <-ticker.C @@ -212,7 +201,6 @@ func (c *Client) write(ctx context.Context) error { return merr.Err() } } - wgPprof.Wait() if c.config.RequestCount*len(tss) != totalSamplesAct { merr.Add(fmt.Errorf("total samples mismatch, exp:%v , act:%v", totalSamplesExp, totalSamplesAct)) } diff --git a/pkg/download/download.go b/pkg/download/download.go deleted file mode 100644 index c827ccb..0000000 --- a/pkg/download/download.go +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2022 The Prometheus Authors -// 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. - -package download - -import ( - "io" - "log" - "net/http" - "net/url" - "os" - "path" - "path/filepath" - "sync" -) - -// URLs downloads a list of urls and saves the respond in a file. -func URLs(urls []*url.URL, suffix string) { - var wg sync.WaitGroup - for _, u := range urls { - wg.Add(1) - go func(url *url.URL) { - defer wg.Done() - fn := filepath.Clean(path.Base(url.Path)) + "-" + suffix - out, err := os.Create(fn) - if err != nil { - log.Printf("error creating the destination file:%v\n", err) - return - } - defer out.Close() - - resp, err := http.Get(url.String()) - if err != nil { - log.Printf("error downloading file:%v\n", err) - return - } - defer resp.Body.Close() - - if resp.StatusCode != http.StatusOK { - log.Printf("url:%v,bad status: %v\n", url.String(), resp.Status) - return - } - - _, err = io.Copy(out, resp.Body) - if err != nil { - log.Printf("error while reading the response: %v\n", err) - return - } - - log.Printf("downloaded:%v saved as: %v\n", url.String(), fn) - }(u) - } - wg.Wait() -}