diff --git a/benchmark/.gitignore b/benchmark/.gitignore deleted file mode 100644 index 3afc8fc2ff..0000000000 --- a/benchmark/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -thanosbench -vendor/ -terraform/.terraform -terraform/terraform.tfstate.backup -.idea/ diff --git a/benchmark/LICENSE b/benchmark/LICENSE deleted file mode 100644 index 8dada3edaf..0000000000 --- a/benchmark/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "{}" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright {yyyy} {name of copyright owner} - - 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. diff --git a/benchmark/Makefile b/benchmark/Makefile deleted file mode 100644 index 9c75562576..0000000000 --- a/benchmark/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -GOPATH ?= $(shell go env GOPATH) -GOIMPORTS ?= $(GOPATH)/bin/goimports -GO111MODULE ?= on -export GO111MODULE - -.PHONY: all -all: build - -.PHONY: build -build: - @echo ">> building thanosbench" - @go install github.com/thanos-io/thanos/benchmark/cmd/thanosbench - -format: $(GOIMPORTS) - @echo ">> formatting code" - @$(GOIMPORTS) -w $(shell find . -type f -name '*.go' -not -path "./vendor/*") - -$(GOIMPORTS): - @echo ">> fetching goimports" - @go get -u golang.org/x/tools/cmd/goimports diff --git a/benchmark/README.md b/benchmark/README.md deleted file mode 100644 index 21c9389f82..0000000000 --- a/benchmark/README.md +++ /dev/null @@ -1,58 +0,0 @@ -# Thanosbench -A series of benchmarking/stress test tools for [thanos](https://github.com/thanos-io/thanos). - -## Installation -1. Fetch thanosbench `go get github.com/thanos-io/thanosbench` -1. Install thanosbench with `make` -1. Create cloud resources for the load test k8s cluster. - * `cd terraform` - * `terraform init` - * `terraform plan` - * `terraform apply` -1. Run a benchmark `thanosbench --help` - -## Results -Thanos performance will depend heavily on the specific use case (number of scrapers, scrape interval, number of timeseries, etc..), so we recommend forking & adjusting this tool to suit your situation. However, we have included below some general results discovered from running these tools. - -### Thanos vs prometheus -We started a prometheus instance with thanos sidecar, scraping 50 targets every second. We used this to collect 15 minutes of metrics (4.5 million total samples). We ran the following queries over both `thanos query` and regular prometheus endpoints. -1. Rate over 4.5 million metrics: `rate({__name__=~"ts_.*"}[1m])` - * Thanos query - * 5.79s average query time (min: 3.06s, max: 6.16s) - * *0.172 queries per second* - * Prometheus - * 3.13 average query time (min: 3.06s, max: 3.91s) - * *0.320 queries per second* -1. Sum over 4.5 million metrics `sum({__name__=~”ts_.*”}) by (instance)` - * Thanos query - * 3.77s average query time (min: 3.62s, max: 3.98s) - * *0.265 queries per second* - * Prometheus - * 1.23 average query time (min: 1.14s, max: 1.47s) - * *0.812 queries per second* -1. Fetch 45 thousand metrics from a single timeseries `ts_00` - * Thanos query - * 0.055s average query time (min: 0.043s, max: 0.135s) - * *18.2 queries per second* - * Prometheus - * 0.022 average query time (min: 0.018s, max: 0.073s) - * *0.812 queries per second* - -This shows an added latency of *85-150%* when using thanos query. This is more or less expected, as network operations will have to be done twice. We took a profile of thanos query while under load, finding that about a third of the time is being spent evaluating the promql queries. We are looking into including newer versions of the prometheus libraries into thanos that include optimisations to this component. - -Although we have not tested federated prometheus in the same controlled environment, in theory it should incur a similar overhead, as we will still be performing two network hops. - -### Store performance -To test the store component, we generated 1 year of simulated metrics (100 timeseries taking random values every 15s, a total of 210 million samples). We were able to run heavy queries to touch all 210 million of these samples, e.g. a sum over 100 timeseries takes about 34.6 seconds. Smaller queries, for example fetching 1 year of samples from a single timeseries, were able to run in about 500 milliseconds. - -When enabling downsampling over these timeseries, we were able to reduce query times by over 90%. - -### Ingestion -To try to find the limits of a single thanos-query service, we spun up a number prometheus instances, each scraping 10 metric-producing endpoints every second. We attached a thanos-query endpoint in front of these scrapers, and ran queries that would touch fetch a most recent metric from each of them. Each metric producing endpoint would serve 100 metrics, taking random values, and the query would fetch the most recent value from each of these metrics: -* 10 scrapers, 100 total metric producing endpoints, ingesting 10k samples/second - * ~0.05 second query response -* 100 scrapers, 1000 total metric producing endpoints, ingesting 100k samples/second - * ~0.20 second query response -* 200 scrapers, 2000 total metric producing endpoints, ingesting 200k samples/second - * ~1.8 second query response time - diff --git a/benchmark/cmd/loadgen/main.go b/benchmark/cmd/loadgen/main.go deleted file mode 100644 index 8a0fbe06d9..0000000000 --- a/benchmark/cmd/loadgen/main.go +++ /dev/null @@ -1,48 +0,0 @@ -package main - -import ( - "flag" - "fmt" - "math/rand" - "net/http" - "os" - "time" -) - -// Loadgen is a lightweight server which will serve a number of randomly generated time series. This can be scraped by -// a prometheus instance to simulate noisy metrics. - -var ( - fNumTimeseries = flag.Int("num-timeseries", 100, "The number of unique timeseries to serve.") - fLifetime = flag.Duration("lifetime", 0, "If non-zero, the server will suicide after this amount of time.") - - // Use an RNG seeded with current time so we get unique metrics. - rng = rand.New(rand.NewSource(time.Now().UnixNano())) -) - -func main() { - flag.Parse() - - if *fLifetime > 0 { - time.AfterFunc(*fLifetime, func() { - os.Exit(0) - }) - } - - http.HandleFunc("/metrics", randomMetrics) - if err := http.ListenAndServe(":8080", nil); err != nil { - panic(err) - } -} - -func randomMetrics(w http.ResponseWriter, _ *http.Request) { - // TODO(adamhosier) these are dummy metrics. These should be more realistic & follow https://github.com/thanos-io/thanos/issues/346 - var metrics string - for i := 0; i < *fNumTimeseries; i++ { - metrics += fmt.Sprintf("ts_%d %f\n", i, rng.Float64()) - } - - if _, err := w.Write([]byte(metrics)); err != nil { - w.WriteHeader(500) - } -} diff --git a/benchmark/cmd/querier/main.go b/benchmark/cmd/querier/main.go deleted file mode 100644 index bcd67aa71f..0000000000 --- a/benchmark/cmd/querier/main.go +++ /dev/null @@ -1,310 +0,0 @@ -package main - -import ( - "encoding/json" - "flag" - "fmt" - "io/ioutil" - "math" - "math/rand" - "net/http" - "net/url" - "os" - "strconv" - "strings" - "sync" - "text/tabwriter" - "time" - - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/log/level" -) - -// Querier will repeatedly perform a number of queries at random against a Prometheus endpoint, collecting -// statistics about its performance. - -var ( - fHost = flag.String("host", "localhost:9090", "The Prometheus host or host:port to query.") - fPath = flag.String("path", "/api/v1/query_range", "Path to append to host.") - fHTTPScheme = flag.String("scheme", "http", "Scheme to use for calling into Prometheus.") - fUsername = flag.String("username", "", "Username for basic auth (if needed).") - fPassword = flag.String("password", "", "Password for basic auth (if needed).") - fQueries = flag.String("queries", "", "A semicolon separated list of queries to use.") - fQueryTotalTime = flag.Duration("query-time", time.Minute, "The length of time that queries will be run. As many queries as possible will be run within this time.") - fQueryRangeStart = flag.Duration("range-offset-start", 1*time.Hour, "The offset to the start of the range to use in queries.") - fQueryRangeEnd = flag.Duration("range-offset-end", 0, "The offset to the end of the range to use in queries.") - fConcurrentRequests = flag.Int("concurrent-requests", 1, "The maximum amount of concurrent requests to perform. Default is no concurrency.") - fLogLevel = flag.String("log-level", "info", "The logging verbosity. Values are debug, info, warn, error.") - fServer = flag.Bool("server", false, "Run Prometheus Querier as a server.") - fErrorThreshold = flag.Int("error-threshold", 250, "The maximum amount of errors per query before killing the run.") -) - -type totals struct { - Errors int `json:"errors"` - Successes int `json:"successes"` - AverageDuration float64 `json:"avg_duration"` - TotalDuration time.Duration `json:"total_duration"` - QueriesPerSecond float64 `json:"queries_per_second"` - - lock sync.Mutex - queryPool []*queryResult -} - -func (t *totals) getErrors() int { - t.lock.Lock() - defer t.lock.Unlock() - - return t.Errors -} - -func (t *totals) addError() { - t.lock.Lock() - defer t.lock.Unlock() - - t.Errors++ -} - -func (t *totals) addSuccess() { - t.lock.Lock() - defer t.lock.Unlock() - - t.Successes++ -} - -type queryResult struct { - Query string `json:"query"` - Errors int `json:"errors"` - Successes int `json:"successes"` - AverageDuration float64 `json:"avg_duration"` - MinDuration float64 `json:"min_duration"` - MaxDuration float64 `json:"max_duration"` - TotalDuration time.Duration `json:"total_duration"` - QueriesPerSecond float64 `json:"queries_per_second"` - - lock sync.Mutex - queryURL url.URL -} - -func (qr *queryResult) addError() { - qr.lock.Lock() - defer qr.lock.Unlock() - - qr.Errors++ -} - -type PromResult struct { - Status string `json:"status"` -} - -func main() { - flag.Parse() - - logger := log.NewLogfmtLogger(log.NewSyncWriter(os.Stdout)) - var lvl level.Option - switch *fLogLevel { - case "error": - lvl = level.AllowError() - case "warn": - lvl = level.AllowWarn() - case "info": - lvl = level.AllowInfo() - case "debug": - lvl = level.AllowDebug() - default: - panic("unexpected log level") - } - logger = level.NewFilter(logger, lvl) - - if *fQueries == "" { - level.Error(logger).Log("msg", "no Queries supplied") - os.Exit(1) - } - - queries := strings.Split(*fQueries, ";") - now := time.Now() - start := now.Add(-*fQueryRangeStart) - end := now.Add(-*fQueryRangeEnd) - step := int(end.Sub(start).Seconds() / 250) - - t := &totals{ - queryPool: []*queryResult{}, - } - - for _, query := range queries { - queryURL := url.URL{ - Scheme: *fHTTPScheme, - Host: *fHost, - Path: *fPath, - } - q := queryURL.Query() - q.Add("start", strconv.FormatInt(start.Unix(), 10)) - q.Add("end", strconv.FormatInt(end.Unix(), 10)) - q.Add("step", strconv.Itoa(step)) - q.Add("query", query) - queryURL.RawQuery = q.Encode() - - if *fUsername != "" && *fPassword != "" { - queryURL.User = url.UserPassword(*fUsername, *fPassword) - } - - t.queryPool = append(t.queryPool, &queryResult{ - Query: query, - queryURL: queryURL, - MinDuration: math.MaxInt64, - }) - } - - summaryStart := time.Now() - var wg sync.WaitGroup - for i := 0; i < *fConcurrentRequests; i++ { - wg.Add(1) - go performQuery(logger, t, *fQueryTotalTime, &wg) - } - wg.Wait() - t.TotalDuration = time.Since(summaryStart) - - if t.getErrors() >= *fErrorThreshold { - level.Error(logger).Log("msg", "too many errors, exiting early") - } - - if err := printResults(t); err != nil { - level.Error(logger).Log("err", err) - os.Exit(1) - } - - // If no server needs to be run return early. - if !*fServer { - return - } - - // Launch server to display queryPool if needed. - resultsBytes, err := json.Marshal(t.queryPool) - if err != nil { - level.Error(logger).Log("err", err) - os.Exit(1) - } - - http.HandleFunc("/queryPool", func(w http.ResponseWriter, req *http.Request) { - if _, err := w.Write(resultsBytes); err != nil { - level.Error(logger).Log("err", err) - w.WriteHeader(http.StatusInternalServerError) - } - }) - - level.Info(logger).Log("msg", "serving results") - if err := http.ListenAndServe(":8080", nil); err != nil { - level.Error(logger).Log("msg", "could not start http server") - os.Exit(1) - } -} - -func performQuery(logger log.Logger, totals *totals, timeout time.Duration, wg *sync.WaitGroup) { - defer wg.Done() - - s := rand.NewSource(time.Now().UnixNano()) - r := rand.New(s) - timeoutC := time.After(timeout) - for { - // Perform as many queries as possible within this time. - select { - case <-timeoutC: - return - default: - } - - n := r.Intn(len(totals.queryPool)) - resultStorage := totals.queryPool[n] - - // Drop out if we have too many errors. - if totals.getErrors() >= *fErrorThreshold { - return - } - - queryStart := time.Now() - resp, err := http.Get(resultStorage.queryURL.String()) - duration := time.Since(queryStart) - if err != nil { - totals.addError() - level.Info(logger).Log("msg", "query failed") - continue - } - - // Check prometheus response success code. - body, err := ioutil.ReadAll(resp.Body) - resp.Body.Close() - if err != nil || resp.StatusCode != 200 { - totals.addError() - resultStorage.addError() - - if resp != nil { - level.Info(logger).Log("msg", "query failed with %d", resp.StatusCode) - } else { - level.Info(logger).Log("err", err) - } - continue - } - - var promResult PromResult - if err := json.Unmarshal(body, &promResult); err != nil { - totals.addError() - resultStorage.addError() - level.Info(logger).Log("err", err) - continue - } - - if promResult.Status != "success" { - totals.addError() - resultStorage.addError() - level.Info(logger).Log("err", fmt.Sprintf("prometheus query reported failure: %s", resp.Body)) - continue - } - - totals.addSuccess() - resultStorage.lock.Lock() - resultStorage.TotalDuration += duration - - if duration.Seconds() > resultStorage.MaxDuration { - resultStorage.MaxDuration = duration.Seconds() - } - if duration.Seconds() < resultStorage.MinDuration { - resultStorage.MinDuration = duration.Seconds() - } - - resultStorage.Successes++ - resultStorage.lock.Unlock() - } -} - -// printResults will calculate totals and print queryPool for individual queries and for the run overall. -func printResults(totals *totals) error { - var totalTime time.Duration - for _, resultStorage := range totals.queryPool { - if resultStorage.Successes > 0 { - totalTime += resultStorage.TotalDuration - resultStorage.AverageDuration = resultStorage.TotalDuration.Seconds() / float64(resultStorage.Successes) - resultStorage.QueriesPerSecond = float64(resultStorage.Successes) / resultStorage.TotalDuration.Seconds() - } - } - - avg := totalTime.Seconds() / float64(totals.Successes) - const tableFormat = "%s\t%f\t%f\t%d\t%d\t\n" - table := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', tabwriter.Debug) - fmt.Fprintf(table, "%s\t%s\t%s\t%s\t%s\t\n", "Query", "avg", "qps", "success_total", "errors_total") - fmt.Fprintf(table, tableFormat, - "ALL", - avg, - float64(totals.Successes)/totals.TotalDuration.Seconds(), - totals.Successes, - totals.Errors, - ) - - for _, result := range totals.queryPool { - fmt.Fprintf(table, tableFormat, - result.Query, - result.AverageDuration, - result.QueriesPerSecond, - result.Successes, - result.Errors) - } - return table.Flush() -} diff --git a/benchmark/cmd/thanosbench/ingest.go b/benchmark/cmd/thanosbench/ingest.go deleted file mode 100644 index c280ead8e9..0000000000 --- a/benchmark/cmd/thanosbench/ingest.go +++ /dev/null @@ -1,102 +0,0 @@ -package main - -import ( - "fmt" - - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/log/level" - "github.com/pkg/errors" - "k8s.io/client-go/kubernetes" - "k8s.io/client-go/tools/clientcmd" -) - -// This test will: -// 1. Spin up a number of prometheus+thanos sidecars. -// 2. Spin up a number of metrics producers for each scraper. -// 3. Run a thanos-query in front of all the scrapers & expose it. - -func testIngest(logger log.Logger, opts *opts) error { - // Create k8s client. - k8sConfig, err := clientcmd.NewNonInteractiveDeferredLoadingClientConfig( - &clientcmd.ClientConfigLoadingRules{ExplicitPath: *opts.kubeConfig}, - &clientcmd.ConfigOverrides{CurrentContext: *opts.cluster}, - ).ClientConfig() - if err != nil { - return errors.Wrap(err, "failed to create client config for cluster") - } - k8sClient, err := kubernetes.NewForConfig(k8sConfig) - if err != nil { - return errors.Wrap(err, "failed to create client set") - } - - // Remove any resources in the cluster. - if err := cleanCluster(logger, k8sClient); err != nil { - return err - } - - // Create resources. - if err := bootstrapIngestCluster(logger, opts, k8sClient); err != nil { - return err - } - - return nil -} - -func bootstrapIngestCluster(logger log.Logger, opts *opts, k8sClient *kubernetes.Clientset) error { - // Create namespaces. - if err := createNamespaces(logger, k8sClient); err != nil { - return errors.Wrap(err, "failed to create namespaces") - } - - // Create admin role for prometheus. - crb, sa := createAdminRole() - if _, err := k8sClient.CoreV1().ServiceAccounts(promNamespace).Create(sa); err != nil { - return errors.Wrap(err, "failed to create monitoring service account") - } - if _, err := k8sClient.RbacV1().ClusterRoleBindings().Create(crb); err != nil { - return errors.Wrap(err, "failed to create clusterrolebinding") - } - - // Create headless services for thanos gossip members. - if _, err := k8sClient.CoreV1().Services(thanosNamespace).Create(createThanosGossipService(thanosNamespace)); err != nil { - return errors.Wrap(err, "failed to create headless service for thanos gossip") - } - if _, err := k8sClient.CoreV1().Services(promNamespace).Create(createThanosGossipService(promNamespace)); err != nil { - return errors.Wrap(err, "failed to create headless service for thanos gossip") - } - - cfg, err := createPrometheusConfig("^loadgen-$(MON_ID)-.*$") - if err != nil { - return err - } - - if _, err := k8sClient.CoreV1().ConfigMaps(promNamespace).Create(cfg); err != nil { - return errors.Wrap(err, "failed to create prometheus configmap") - } - - for i := 0; i < *opts.numPrometheus; i++ { - name := fmt.Sprintf("mon-%d", i) - - loadgenName := fmt.Sprintf("loadgen-%s", name) - level.Info(logger).Log("msg", "Creating loadgen", "name", loadgenName) - if _, err := k8sClient.AppsV1().ReplicaSets(loadgenNamespace).Create(createLoadgen(loadgenName, int32(*opts.numLoadgen))); err != nil { - return errors.Wrapf(err, "failed to create loadgen (%s)", loadgenName) - } - - level.Info(logger).Log("msg", "Creating prometheus", "name", name) - if _, err := k8sClient.AppsV1().StatefulSets(promNamespace).Create(createPrometheus(opts, name, "")); err != nil { - return errors.Wrapf(err, "failed to create prometheus (%s)", name) - } - } - - // Create thanos query layer. - level.Info(logger).Log("msg", "Creating thanos query layer") - svc, pod := createThanosQuery(opts) - if _, err := k8sClient.CoreV1().Services(thanosNamespace).Create(svc); err != nil { - return errors.Wrap(err, "failed to create thanos query service") - } - if _, err := k8sClient.CoreV1().Pods(thanosNamespace).Create(pod); err != nil { - return errors.Wrap(err, "failed to create thanos query pod") - } - return nil -} diff --git a/benchmark/cmd/thanosbench/latency.go b/benchmark/cmd/thanosbench/latency.go deleted file mode 100644 index 9f8532d4e3..0000000000 --- a/benchmark/cmd/thanosbench/latency.go +++ /dev/null @@ -1,179 +0,0 @@ -package main - -import ( - "fmt" - "io/ioutil" - "net/http" - "strings" - "time" - - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/log/level" - "github.com/pkg/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/client-go/kubernetes" - "k8s.io/client-go/tools/clientcmd" -) - -const ( - scrapeInterval = time.Second - numMetricsProducers = 50 - resultsPollInterval = 30 * time.Second -) - -// This test will attempt to quantify the latency added by a thanos installation compared to vanilla prometheus: -// 1. Start a prometheus instance & thanos sidecar configured to scrape some metrics producers. -// 2. Start a thanos query layer targeting the sidecar on this prometheus. -// 3. Run various queries against both the query layer, and the direct prometheus endpoint. -// 4. Measure response times for both endpoints to find latency added by thanos. - -func testLatency(logger log.Logger, opts *opts) error { - // Create k8s client. - k8sConfig, err := clientcmd.NewNonInteractiveDeferredLoadingClientConfig( - &clientcmd.ClientConfigLoadingRules{ExplicitPath: *opts.kubeConfig}, - &clientcmd.ConfigOverrides{CurrentContext: *opts.cluster}, - ).ClientConfig() - if err != nil { - return errors.Wrap(err, "failed to create client config for cluster") - } - k8sClient, err := kubernetes.NewForConfig(k8sConfig) - if err != nil { - return errors.Wrap(err, "failed to create client set") - } - - // Remove any resources in the cluster. - if err := cleanCluster(logger, k8sClient); err != nil { - return err - } - - // Get the cluster ready. - if err := bootstrapLatencyCluster(logger, opts, k8sClient); err != nil { - return err - } - - // Collect metrics for some time. - level.Info(logger).Log("msg", "Deployment completed, pausing to collect metrics", "time", opts.gatherTime) - time.Sleep(*opts.gatherTime) - - // Remove metric producers. - level.Info(logger).Log("msg", "Deleting metrics producers") - if err := k8sClient.AppsV1().ReplicaSets(loadgenNamespace).Delete("loadgen", nil); err != nil { - return errors.Wrap(err, "failed to delete loadgen replicaset") - } - - promResults, err := getQueryTimes(logger, opts, k8sClient, "mon-0", promNamespace, "querier-prom", 9090) - if err != nil { - return err - } - - thanosResults, err := getQueryTimes(logger, opts, k8sClient, "thanos-query", thanosNamespace, "querier-thanos", thanosHTTPPort) - if err != nil { - return err - } - - level.Info(logger).Log("component", "thanos", "results", string(thanosResults)) - level.Info(logger).Log("component", "prometheus", "results", string(promResults)) - return nil -} - -func getQueryTimes(logger log.Logger, opts *opts, k8sClient *kubernetes.Clientset, podName string, podNamespace string, querierName string, port int32) ([]byte, error) { - // Get query endpoint. - queryPod, err := k8sClient.CoreV1().Pods(podNamespace).Get(podName, metav1.GetOptions{}) - if err != nil { - return []byte{}, errors.Wrapf(err, "failed to get pod (%s)", podName) - } - - // Deploy querier. - level.Info(logger).Log("msg", "Running querier", "name", querierName) - pod, service := createPrometheusQuerier(opts, querierName, fmt.Sprintf("%s:%d", queryPod.Status.PodIP, port), strings.Join(*opts.queries, ";")) - if _, err := k8sClient.CoreV1().Pods(thanosNamespace).Create(pod); err != nil { - return []byte{}, errors.Wrap(err, "failed to create querier pod") - } - if _, err := k8sClient.CoreV1().Services(thanosNamespace).Create(service); err != nil { - return []byte{}, errors.Wrap(err, "failed to create querier service") - } - - // Wait for queries to finish. - var waitTime time.Duration - for { - svc, err := k8sClient.CoreV1().Services(thanosNamespace).Get(querierName, metav1.GetOptions{}) - if err != nil || len(svc.Status.LoadBalancer.Ingress) == 0 { - time.Sleep(resultsPollInterval) - waitTime += resultsPollInterval - level.Info(logger).Log("msg", "Waiting for test results", "time", waitTime) - continue - } - - resp, err := http.Get(fmt.Sprintf("http://%s:%d/results", svc.Status.LoadBalancer.Ingress[0].IP, prometheusQuerierPort)) - // Retry on failure. - if err != nil || resp.StatusCode != http.StatusOK { - time.Sleep(resultsPollInterval) - waitTime += resultsPollInterval - level.Info(logger).Log("msg", "Waiting for test result", "time", waitTime) - continue - } - - body, err := ioutil.ReadAll(resp.Body) - if err != nil { - return []byte{}, errors.Wrap(err, "failed to read response body") - } - - return body, nil - } -} - -func bootstrapLatencyCluster(logger log.Logger, opts *opts, k8sClient *kubernetes.Clientset) error { - // Create namespaces. - if err := createNamespaces(logger, k8sClient); err != nil { - return errors.Wrap(err, "failed to create namespaces") - } - - // Create admin role for prometheus. - crb, sa := createAdminRole() - if _, err := k8sClient.CoreV1().ServiceAccounts(promNamespace).Create(sa); err != nil { - return errors.Wrap(err, "failed to create monitoring service account") - } - if _, err := k8sClient.RbacV1().ClusterRoleBindings().Create(crb); err != nil { - return errors.Wrap(err, "failed to create clusterrolebinding") - } - - cfg, err := createPrometheusConfig("^loadgen-.*$") - if err != nil { - return err - } - - if _, err := k8sClient.CoreV1().ConfigMaps(promNamespace).Create(cfg); err != nil { - return errors.Wrap(err, "failed to create prometheus configmap") - } - - // Create headless services for thanos gossip members. - if _, err := k8sClient.CoreV1().Services(thanosNamespace).Create(createThanosGossipService(thanosNamespace)); err != nil { - return errors.Wrap(err, "failed to create headless service for thanos gossip") - } - if _, err := k8sClient.CoreV1().Services(promNamespace).Create(createThanosGossipService(promNamespace)); err != nil { - return errors.Wrap(err, "failed to create headless service for thanos gossip") - } - - // Create prometheus instance. - level.Info(logger).Log("msg", "Creating prometheus statefulset") - if _, err := k8sClient.AppsV1().StatefulSets(promNamespace).Create(createPrometheus(opts, "mon", "")); err != nil { - return errors.Wrap(err, "failed to create prometheus statefulset") - } - - level.Info(logger).Log("msg", "Creating metrics producers") - if _, err := k8sClient.AppsV1().ReplicaSets(loadgenNamespace).Create(createLoadgen("loadgen", numMetricsProducers)); err != nil { - return errors.Wrap(err, "failed to create metrics producer replicaset") - } - - // Create thanos query layer. - level.Info(logger).Log("msg", "Creating thanos query layer") - svc, pod := createThanosQuery(opts) - if _, err := k8sClient.CoreV1().Services(thanosNamespace).Create(svc); err != nil { - return errors.Wrap(err, "failed to create thanos query service") - } - if _, err := k8sClient.CoreV1().Pods(thanosNamespace).Create(pod); err != nil { - return errors.Wrap(err, "failed to create thanos query pod") - } - - return nil -} diff --git a/benchmark/cmd/thanosbench/main.go b/benchmark/cmd/thanosbench/main.go deleted file mode 100644 index c412e11718..0000000000 --- a/benchmark/cmd/thanosbench/main.go +++ /dev/null @@ -1,71 +0,0 @@ -package main - -import ( - "os" - "path/filepath" - "time" - - "github.com/go-kit/kit/log" - "github.com/prometheus/common/version" - kingpin "gopkg.in/alecthomas/kingpin.v2" - "k8s.io/client-go/tools/clientcmd" -) - -type opts struct { - cluster, kubeConfig, bucket, thanosImage *string - queries *[]string - numTimeseries, numPrometheus, numLoadgen *int - gatherTime, queryTime, queryRangeOffsetStart, queryRangeOffsetEnd, tsdbLength, blockLength *time.Duration -} - -func main() { - logger := log.NewLogfmtLogger(log.NewSyncWriter(os.Stdout)) - - app := kingpin.New(filepath.Base(os.Args[0]), "A benchmark for Thanos") - app.Version(version.Print("thanosbench")) - app.HelpFlag.Short('h') - - opts := &opts{ - cluster: app.Flag("cluster", "The kubernetes cluster to run the loadtest in.").Required().String(), - kubeConfig: app.Flag("kube-config", "Path to kube config file.").Default(clientcmd.RecommendedHomeFile).String(), - thanosImage: app.Flag("thanos-image", "Image to use when running Thanos components.").Default("improbable/thanos:v0.1.0").String(), - queryRangeOffsetStart: app.Flag("query-range-offset-start", "The offset to the start of the range to use in queries.").Default("1h").Duration(), - queryRangeOffsetEnd: app.Flag("query-range-offset-end", "The offset to the end of the range to use in queries.").Default("0").Duration(), - queries: app.Flag("queries", "Queries to run.").Strings(), - } - - registerIngest(app, logger, opts) - registerResponsiveness(app, logger, opts) - registerLatency(app, logger, opts) - - kingpin.MustParse(app.Parse(os.Args[1:])) -} - -func registerIngest(app *kingpin.Application, logger log.Logger, opts *opts) { - cmd := app.Command("ingest", "Loadtest Thanos ingestion rate.") - opts.numPrometheus = cmd.Flag("num-prometheus", "The number of prometheus/sidecar instances to create.").Default("10").Int() - opts.numLoadgen = cmd.Flag("num-loadgen", "The number of load generation servers to deploy per prometheus instance.").Default("10").Int() - cmd.Action(func(_ *kingpin.ParseContext) error { - return testIngest(logger, opts) - }) -} - -func registerResponsiveness(app *kingpin.Application, logger log.Logger, opts *opts) { - cmd := app.Command("responsiveness", "Benchmark Thanos responsiveness.") - opts.numTimeseries = cmd.Flag("num-timeseries", "The number of timeseries to generate historic data for.").Default("100").Int() - opts.tsdbLength = cmd.Flag("tsdb-length", "The length of time to generate historic metrics (default 1 year).").Default("8760h").Duration() - opts.blockLength = cmd.Flag("block-length", "The TSDB will be divided into blocks of this size (default 4 weeks).").Default("672h").Duration() - opts.bucket = cmd.Flag("bucket", "The bucket containing Thanos TSDB data.").Required().String() - cmd.Action(func(_ *kingpin.ParseContext) error { - return testStoreResponsiveness(logger, opts) - }) -} - -func registerLatency(app *kingpin.Application, logger log.Logger, opts *opts) { - cmd := app.Command("latency", "Benchmark Thanos vs Prometheus latency.") - opts.gatherTime = cmd.Flag("gather-time", "Time to gather metrics before testing latency.").Default("5m").Duration() - opts.queryTime = cmd.Flag("query-time", "The amount of time each query will be run for.").Default("2m").Duration() - cmd.Action(func(_ *kingpin.ParseContext) error { - return testLatency(logger, opts) - }) -} diff --git a/benchmark/cmd/thanosbench/resources.go b/benchmark/cmd/thanosbench/resources.go deleted file mode 100644 index c76cac5f48..0000000000 --- a/benchmark/cmd/thanosbench/resources.go +++ /dev/null @@ -1,571 +0,0 @@ -package main - -import ( - "fmt" - "path/filepath" - "time" - - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/log/level" - "github.com/pkg/errors" - "github.com/prometheus/common/model" - prom "github.com/prometheus/prometheus/config" - yaml "gopkg.in/yaml.v2" - appsv1 "k8s.io/api/apps/v1" - v1 "k8s.io/api/core/v1" - rbacv1 "k8s.io/api/rbac/v1" - "k8s.io/apimachinery/pkg/api/resource" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/util/intstr" - "k8s.io/client-go/kubernetes" - _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" -) - -const ( - promNamespace = "mon" - thanosNamespace = "thanos" - loadgenNamespace = "gen" - cleanupPollInterval = 2 * time.Second - - adminSAName = "admin" - - scraperConfigTemplatePath = "/opt/prometheus/config.yaml.tmpl" - scraperConfigPath = "/etc/prometheus/config.yaml" - scraperDataPath = "/var/prometheus" - scraperDataVolumeSize = "5Gi" - - thanosGossipServiceName = "thanos-gossip" - thanosGossipPort = int32(10900) - thanosHTTPPort = int32(10902) - - prometheusQuerierPort = int32(8080) -) - -var ( - thanosGossipTmpl = fmt.Sprintf("%s.%%s.svc.cluster.local:%d", thanosGossipServiceName, thanosGossipPort) -) - -// Deletes all deployed resources from the cluster. -func cleanCluster(logger log.Logger, k8sClient *kubernetes.Clientset) error { - level.Info(logger).Log("msg", "Cleaning cluster") - listOpts := metav1.ListOptions{ - LabelSelector: "group=loadtest", - } - - // Delete namespaces (and everything in them). - nss, err := k8sClient.CoreV1().Namespaces().List(listOpts) - if err != nil { - return errors.Wrap(err, "failed to list namespaces") - } - - for _, ns := range nss.Items { - level.Info(logger).Log("msg", "Deleting namespace", "name", ns.Name) - if err := k8sClient.CoreV1().Namespaces().Delete(ns.Name, nil); err != nil { - return errors.Wrapf(err, "failed to delete namespace (%s)", ns.Name) - } - } - - // Delete clusterrolebindings as they don't live in a namespace. - crbs, err := k8sClient.RbacV1().ClusterRoleBindings().List(listOpts) - if err != nil { - return errors.Wrap(err, "failed to list clusterrolebindings") - } - for _, crb := range crbs.Items { - level.Info(logger).Log("msg", "Deleting CRB", "name", crb.Name) - if err := k8sClient.RbacV1().ClusterRoleBindings().Delete(crb.Name, nil); err != nil { - return errors.Wrapf(err, "failed to delete crb (%s)", crb.Name) - } - } - - // Block until namespaces have finished deleting. - level.Info(logger).Log("msg", "Waiting for namespaces to delete") - var totalTime time.Duration - for { - nss, err := k8sClient.CoreV1().Namespaces().List(listOpts) - if err != nil { - return errors.Wrap(err, "failed to list namespaces") - } - - // Return if all namespaces are active. - allActive := true - for _, ns := range nss.Items { - allActive = allActive && ns.Status.Phase == v1.NamespaceActive - } - - if allActive { - return nil - } - - time.Sleep(cleanupPollInterval) - totalTime += cleanupPollInterval - level.Info(logger).Log("msg", "Still deleting", "time", totalTime) - } -} - -// Creates a namespace with a given name. -func createNamespace(name string) *v1.Namespace { - return &v1.Namespace{ - ObjectMeta: metav1.ObjectMeta{ - Name: name, - Labels: map[string]string{ - "group": "loadtest", - }, - }, - } -} - -// Creates a serviceacconut & rolebinding to for a cluster-admin role. -func createAdminRole() (*rbacv1.ClusterRoleBinding, *v1.ServiceAccount) { - om := metav1.ObjectMeta{ - Name: adminSAName, - Namespace: promNamespace, - Labels: map[string]string{ - "group": "loadtest", - }, - } - - return &rbacv1.ClusterRoleBinding{ - TypeMeta: metav1.TypeMeta{ - Kind: "ClusterRoleBinding", - APIVersion: "rbac.authorization.k8s.io/v1", - }, - ObjectMeta: om, - Subjects: []rbacv1.Subject{{ - Kind: "ServiceAccount", - Name: adminSAName, - Namespace: promNamespace, - }}, - RoleRef: rbacv1.RoleRef{ - Kind: "ClusterRole", - Name: "cluster-admin", - }, - }, &v1.ServiceAccount{ - TypeMeta: metav1.TypeMeta{ - Kind: "ServiceAccount", - APIVersion: "v1", - }, - ObjectMeta: om, - } -} - -// Returns a configmap holding prometheus config. -func createPrometheusConfig(podNameSelectorRegex string) (*v1.ConfigMap, error) { - // Prometheus config. - cfg := prom.Config{ - GlobalConfig: prom.GlobalConfig{ - ScrapeInterval: model.Duration(scrapeInterval), - ScrapeTimeout: model.Duration(scrapeInterval), - - ExternalLabels: model.LabelSet{ - "id": "$(MON_ID)", - }, - }, - ScrapeConfigs: []*prom.ScrapeConfig{{ - JobName: "loadgen", - MetricsPath: "/metrics", - ServiceDiscoveryConfig: prom.ServiceDiscoveryConfig{ - KubernetesSDConfigs: []*prom.KubernetesSDConfig{{ - Role: prom.KubernetesRolePod, - }}, - }, - RelabelConfigs: []*prom.RelabelConfig{ - { // Only scrape pods that are assigned to this prometheus. - SourceLabels: model.LabelNames{"__meta_kubernetes_pod_name"}, - Regex: prom.MustNewRegexp(podNameSelectorRegex), - Action: prom.RelabelKeep, - }, - { - SourceLabels: model.LabelNames{"__address__"}, - Replacement: "${1}:8080", - TargetLabel: "__address__", - }, - }, - }}, - } - cfgBytes, err := yaml.Marshal(cfg) - if err != nil { - return nil, errors.Wrap(err, "failed to marshal prometheus config") - } - - return &v1.ConfigMap{ - TypeMeta: metav1.TypeMeta{ - Kind: "ConfigMap", - APIVersion: "v1", - }, - ObjectMeta: metav1.ObjectMeta{ - Name: "prom", - Namespace: promNamespace, - }, - Data: map[string]string{ - filepath.Base(scraperConfigTemplatePath): string(cfgBytes), - }, - }, nil -} - -// Returns a statefulset representation containing a prometheus pod & thanos sidecar. -func createPrometheus(opts *opts, name string, bucket string) *appsv1.StatefulSet { - om := metav1.ObjectMeta{ - Name: name, - Namespace: promNamespace, - Labels: map[string]string{ - "app": name, - "thanos-gossip-member": "true", - }, - } - - fsGroup := int64(2000) - runAsNonRoot := true - runAsUser := int64(1000) - ps := v1.PodSpec{ - ServiceAccountName: adminSAName, - Containers: []v1.Container{ - { // Prometheus. - Name: "prom", - Image: "eu.gcr.io/io-crafty-shelter/prometheus:v2.2.1", - Args: []string{ - "--config.file=" + scraperConfigPath, - "--storage.tsdb.path=" + scraperDataPath, - "--storage.tsdb.no-lockfile", - "--web.enable-lifecycle", - "--storage.tsdb.min-block-duration=2h", - "--storage.tsdb.max-block-duration=2h", - "--storage.tsdb.retention=2h", - "--query.timeout=10m", - }, - VolumeMounts: []v1.VolumeMount{ - { - Name: name, - MountPath: scraperDataPath, - }, - { - Name: "prom-config", - MountPath: filepath.Dir(scraperConfigPath), - }, - }, - }, - { // Thanos. - Name: "thanos", - Image: *opts.thanosImage, - Args: []string{ - "sidecar", - "--prometheus.url=http://localhost:9090", - "--tsdb.path=" + scraperDataPath, - "--gcs.bucket=" + bucket, - "--reloader.config-file=" + scraperConfigTemplatePath, - "--reloader.config-envsubst-file=" + scraperConfigPath, - "--cluster.peers=" + fmt.Sprintf(thanosGossipTmpl, thanosNamespace), - "--cluster.peers=" + fmt.Sprintf(thanosGossipTmpl, promNamespace), - }, - Env: []v1.EnvVar{ - {Name: "MON_ID", Value: name}, - }, - VolumeMounts: []v1.VolumeMount{ - { - Name: name, - MountPath: scraperDataPath, - }, - { - Name: "prom-config", - MountPath: filepath.Dir(scraperConfigPath), - }, - { - Name: "prom-config-tmpl", - MountPath: filepath.Dir(scraperConfigTemplatePath), - }, - }, - }, - }, - SecurityContext: &v1.PodSecurityContext{ - FSGroup: &fsGroup, - RunAsNonRoot: &runAsNonRoot, - RunAsUser: &runAsUser, - }, - Volumes: []v1.Volume{ - { - Name: "prom-config-tmpl", - VolumeSource: v1.VolumeSource{ - ConfigMap: &v1.ConfigMapVolumeSource{ - LocalObjectReference: v1.LocalObjectReference{ - Name: "prom", - }, - }, - }, - }, - { - Name: "prom-config", - VolumeSource: v1.VolumeSource{ - EmptyDir: &v1.EmptyDirVolumeSource{}, - }, - }, - }, - } - - vc := []v1.PersistentVolumeClaim{{ - TypeMeta: metav1.TypeMeta{ - Kind: "VolumeClaim", - APIVersion: "v1", - }, - ObjectMeta: om, - Spec: v1.PersistentVolumeClaimSpec{ - AccessModes: []v1.PersistentVolumeAccessMode{v1.ReadWriteOnce}, - Resources: v1.ResourceRequirements{ - Requests: map[v1.ResourceName]resource.Quantity{ - v1.ResourceStorage: resource.MustParse(scraperDataVolumeSize), - }, - }, - }, - }} - - replicas := int32(1) - return &appsv1.StatefulSet{ - TypeMeta: metav1.TypeMeta{ - Kind: "StatefulSet", - APIVersion: "apps/v1", - }, - ObjectMeta: om, - Spec: appsv1.StatefulSetSpec{ - Replicas: &replicas, - Selector: &metav1.LabelSelector{ - MatchLabels: map[string]string{ - "app": name, - }, - }, - Template: v1.PodTemplateSpec{ - ObjectMeta: om, - Spec: ps, - }, - VolumeClaimTemplates: vc, - }, - } -} - -// Returns a headless service for a namespace, to allow thanos to discover cluster peers. Peers should contain the -// "thanos-gossip-member=true" label to be selected for these services. -func createThanosGossipService(namespace string) *v1.Service { - return &v1.Service{ - TypeMeta: metav1.TypeMeta{ - Kind: "Service", - APIVersion: "v1", - }, - ObjectMeta: metav1.ObjectMeta{ - Name: thanosGossipServiceName, - Namespace: namespace, - }, - Spec: v1.ServiceSpec{ - Selector: map[string]string{ - "thanos-gossip-member": "true", - }, - Ports: []v1.ServicePort{{ - Name: "gossip", - Port: thanosGossipPort, - }}, - Type: v1.ServiceTypeClusterIP, - ClusterIP: v1.ClusterIPNone, - }, - } -} - -// The global query layer for thanos. -func createThanosQuery(opts *opts) (*v1.Service, *v1.Pod) { - om := metav1.ObjectMeta{ - Name: "thanos-query", - Namespace: thanosNamespace, - Labels: map[string]string{ - "app": "thanos-query", - "thanos-gossip-member": "true", - }, - } - - return &v1.Service{ - TypeMeta: metav1.TypeMeta{ - Kind: "Service", - APIVersion: "v1", - }, - ObjectMeta: om, - Spec: v1.ServiceSpec{ - Ports: []v1.ServicePort{ - {Name: "http", Port: int32(80), TargetPort: intstr.FromInt(10902)}, - }, - // NOTE(adam) this does not need to be external, is only enabled for debugging. - Type: v1.ServiceTypeLoadBalancer, - Selector: map[string]string{ - "app": "thanos-query", - }, - }, - }, &v1.Pod{ - TypeMeta: metav1.TypeMeta{ - Kind: "Pod", - APIVersion: "v1", - }, - ObjectMeta: om, - Spec: v1.PodSpec{ - Containers: []v1.Container{{ - Name: "thanos", - Image: *opts.thanosImage, - Args: []string{ - "query", - "--log.level=debug", - "--cluster.peers=" + fmt.Sprintf(thanosGossipTmpl, thanosNamespace), - "--cluster.peers=" + fmt.Sprintf(thanosGossipTmpl, promNamespace), - }, - Resources: v1.ResourceRequirements{ - Limits: v1.ResourceList{ - v1.ResourceCPU: resource.MustParse("1"), - v1.ResourceMemory: resource.MustParse("4000Mi"), - }, - }, - }}, - }, - } -} - -// The service allowing us to query the backend. -func createThanosStore(opts *opts, bucket string) *v1.Pod { - return &v1.Pod{ - TypeMeta: metav1.TypeMeta{ - Kind: "Pod", - APIVersion: "v1", - }, - ObjectMeta: metav1.ObjectMeta{ - Name: "thanos-store", - Namespace: thanosNamespace, - Labels: map[string]string{ - "thanos-gossip-member": "true", - }, - }, - Spec: v1.PodSpec{ - Containers: []v1.Container{{ - Name: "thanos", - Image: *opts.thanosImage, - Args: []string{ - "store", - "--log.level=debug", - "--cluster.peers=" + fmt.Sprintf(thanosGossipTmpl, thanosNamespace), - "--cluster.peers=" + fmt.Sprintf(thanosGossipTmpl, promNamespace), - "--gcs.bucket=" + bucket, - "--index-cache-size=250MB", - "--chunk-pool-size=2GB", - }, - }}, - }, - } -} - -// Creates a replicaset containing some number of metrics producers. -func createLoadgen(name string, numProducers int32) *appsv1.ReplicaSet { - om := metav1.ObjectMeta{ - Name: name, - Namespace: loadgenNamespace, - Labels: map[string]string{ - "app": name, - }, - } - - return &appsv1.ReplicaSet{ - TypeMeta: metav1.TypeMeta{ - Kind: "ReplicaSet", - APIVersion: "apps/v1", - }, - ObjectMeta: om, - Spec: appsv1.ReplicaSetSpec{ - Replicas: &numProducers, - Selector: &metav1.LabelSelector{ - MatchLabels: map[string]string{ - "app": name, - }, - }, - Template: v1.PodTemplateSpec{ - ObjectMeta: om, - Spec: v1.PodSpec{ - Containers: []v1.Container{{ - Name: "loadgen", - Image: "eu.gcr.io/io-crafty-shelter/thanos-loadgen:latest", - Resources: v1.ResourceRequirements{ - Limits: v1.ResourceList{ - v1.ResourceCPU: resource.MustParse("50m"), - v1.ResourceMemory: resource.MustParse("10Mi"), - }, - }, - }}, - }, - }, - }, - } -} - -// Creates a pod with a querier targeting a prometheus endpoint. -func createPrometheusQuerier(opts *opts, name string, endpoint string, queries string) (*v1.Pod, *v1.Service) { - om := metav1.ObjectMeta{ - Name: name, - Namespace: thanosNamespace, - Labels: map[string]string{ - "app": name, - }, - } - - return &v1.Pod{ - TypeMeta: metav1.TypeMeta{ - Kind: "Pod", - APIVersion: "v1", - }, - ObjectMeta: om, - Spec: v1.PodSpec{ - Containers: []v1.Container{{ - Name: "querier", - //TODO(domgreen): move this to the same repository as Thanos - Image: "eu.gcr.io/io-crafty-shelter/thanos-querier:latest", - Args: []string{ - "--host=" + endpoint, - "--queries=" + queries, - "--range-offset-start=" + opts.queryRangeOffsetStart.String(), - "--range-offset-end=" + opts.queryRangeOffsetEnd.String(), - "--query-time=" + opts.queryTime.String(), - "--server=true", - }, - }}, - }, - }, &v1.Service{ - TypeMeta: metav1.TypeMeta{ - Kind: "Service", - APIVersion: "v1", - }, - ObjectMeta: om, - Spec: v1.ServiceSpec{ - Ports: []v1.ServicePort{{ - Name: "http", - Port: prometheusQuerierPort, - }}, - Type: v1.ServiceTypeLoadBalancer, - Selector: map[string]string{ - "app": name, - }, - }, - } -} - -func createNamespaces(logger log.Logger, k8sClient *kubernetes.Clientset) error { - if promNamespace == "default" { - return errors.New("prometheus namespace cannot be default") - } - level.Info(logger).Log("msg", "Creating namespace for prometheus", "namespace", promNamespace) - if _, err := k8sClient.CoreV1().Namespaces().Create(createNamespace(promNamespace)); err != nil { - return err - } - - if loadgenNamespace == "default" { - return errors.New("loadgen namespace cannot be default") - } - level.Info(logger).Log("msg", "Creating namespace for loadgen", "namespace", loadgenNamespace) - if _, err := k8sClient.CoreV1().Namespaces().Create(createNamespace(loadgenNamespace)); err != nil { - return err - } - - if thanosNamespace == "default" { - return errors.New("thanos namespace cannot be default") - } - level.Info(logger).Log("msg", "Creating namespace for thanos", "namespace", thanosNamespace) - if _, err := k8sClient.CoreV1().Namespaces().Create(createNamespace(thanosNamespace)); err != nil { - return err - } - return nil -} diff --git a/benchmark/cmd/thanosbench/responsiveness.go b/benchmark/cmd/thanosbench/responsiveness.go deleted file mode 100644 index 23a57755bd..0000000000 --- a/benchmark/cmd/thanosbench/responsiveness.go +++ /dev/null @@ -1,189 +0,0 @@ -package main - -import ( - "context" - "fmt" - "io" - "io/ioutil" - "os" - "path/filepath" - "strings" - "time" - - "cloud.google.com/go/storage" - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/log/level" - "github.com/pkg/errors" - "github.com/thanos-io/thanos/benchmark/pkg/tsdb" - "google.golang.org/api/iterator" - "k8s.io/client-go/kubernetes" - "k8s.io/client-go/tools/clientcmd" -) - -// This test will: -// 1. Generate a large amount of historic metric data, and store it in GCS. -// 2. Bootstrap a cluster containing a thanos-store and a thanos-query. -// 3. Perform queries over the store & measure responsiveness. - -func testStoreResponsiveness(logger log.Logger, opts *opts) error { - tmpDir, err := ioutil.TempDir("", "thanos") - if err != nil { - return errors.Wrap(err, "failed to create temporary directory for holding tsdb data") - } - tsdbDir := filepath.Join(tmpDir, "tsdb") - - defer func() { - if err := os.RemoveAll(tsdbDir); err != nil { - level.Error(logger).Log("failed to remove tsdb dir", tsdbDir) - } - }() - - // Create local tsdb. - level.Info(logger).Log("msg", "Writing historic timeseries", "num-timeseries", opts.numTimeseries, "output-dir", tsdbDir) - tsdbEndTime := time.Now() - tsdbStartTime := tsdbEndTime.Add(-*opts.tsdbLength) - if err := tsdb.CreateThanosTSDB(tsdb.Opts{ - OutputDir: tsdbDir, - NumTimeseries: *opts.numTimeseries, - StartTime: tsdbStartTime, - EndTime: tsdbEndTime, - SampleInterval: time.Second * 15, - BlockLength: *opts.blockLength, - }); err != nil { - return errors.Wrap(err, "failed to generate tsdb") - } - - // Create k8s client. - k8sConfig, err := clientcmd.NewNonInteractiveDeferredLoadingClientConfig( - &clientcmd.ClientConfigLoadingRules{ExplicitPath: *opts.kubeConfig}, - &clientcmd.ConfigOverrides{CurrentContext: *opts.cluster}, - ).ClientConfig() - if err != nil { - return errors.Wrap(err, "failed to create client config for cluster") - } - k8sClient, err := kubernetes.NewForConfig(k8sConfig) - if err != nil { - return errors.Wrap(err, "failed to create client set") - } - - // Remove any resources in the cluster. - if err := cleanCluster(logger, k8sClient); err != nil { - return err - } - - // Create resources for this cluster. - if err := bootstrapStoreResponsivenessCluster(logger, opts, k8sClient); err != nil { - return err - } - - // Safety prompt. - fmt.Printf("WARNING: this will delete all data in the bucket (%s). Do you want to continue? Y/n: ", *opts.bucket) - var resp string - if _, err := fmt.Scanln(&resp); err != nil { - return errors.Wrap(err, "failed to confirm input") - } - if resp != "Y" && resp != "y" { - return nil - } - level.Info(logger).Log("msg", "Uploading timeseries to GCS") - - // Upload TSDB. - if err := pushToGCS(logger, opts, tsdbDir); err != nil { - return errors.Wrap(err, "failed to upload data to gcs") - } - - // Collect query information. - results, err := getQueryTimes(logger, opts, k8sClient, "thanos-query", thanosNamespace, "querier-thanos", thanosHTTPPort) - if err != nil { - return err - } - - level.Info(logger).Log("results", string(results)) - - return nil -} - -func bootstrapStoreResponsivenessCluster(logger log.Logger, opts *opts, k8sClient *kubernetes.Clientset) error { - // Create namespaces. - if err := createNamespaces(logger, k8sClient); err != nil { - return errors.Wrap(err, "failed to create namespaces") - } - - // Create headless service for thanos gossip members. - if _, err := k8sClient.CoreV1().Services(thanosNamespace).Create(createThanosGossipService(thanosNamespace)); err != nil { - return errors.Wrap(err, "failed to create headless service for thanos gossip") - } - - // Create thanos store. - level.Info(logger).Log("msg", "Creating thanos store") - if _, err := k8sClient.CoreV1().Pods(thanosNamespace).Create(createThanosStore(opts, "improbable-thanos-loadtest")); err != nil { - return errors.Wrap(err, "failed to create thanos store pod") - } - - // Create thanos query layer. - level.Info(logger).Log("msg", "Creating thanos query layer") - svc, pod := createThanosQuery(opts) - if _, err := k8sClient.CoreV1().Services(thanosNamespace).Create(svc); err != nil { - return errors.Wrap(err, "failed to create thanos query service") - } - if _, err := k8sClient.CoreV1().Pods(thanosNamespace).Create(pod); err != nil { - return errors.Wrap(err, "failed to create thanos query pod") - } - - return nil -} - -func pushToGCS(logger log.Logger, opts *opts, uploadDir string) error { - ctx := context.Background() - client, err := storage.NewClient(ctx) - if err != nil { - return err - } - - bkt := client.Bucket(*opts.bucket) - - objIt := bkt.Objects(ctx, nil) - for { - obj, err := objIt.Next() - if err == iterator.Done { - break - } else if err != nil { - return err - } - - level.Info(logger).Log("Deleting file", obj.Name) - if err := bkt.Object(obj.Name).Delete(ctx); err != nil { - level.Warn(logger).Log("failed to delete file", obj.Name, "error", err) - continue - } - } - - return filepath.Walk(uploadDir, func(path string, info os.FileInfo, err error) error { - if err != nil { - return err - } - - if info.IsDir() { - return nil - } - - f, err := os.Open(path) - if err != nil { - return errors.Wrapf(err, "failed to open file (%s)", path) - } - - trimmedPath := strings.TrimPrefix(path, uploadDir+string(filepath.Separator)) - level.Info(logger).Log("Uploading file", trimmedPath) - w := bkt.Object(trimmedPath).NewWriter(ctx) - - if _, err := io.Copy(w, f); err != nil { - return errors.Wrapf(err, "failed to upload file (%s)", trimmedPath) - } - - if err := w.Close(); err != nil { - return errors.Wrapf(err, "failed to close file (%s)", trimmedPath) - } - - return nil - }) -} diff --git a/benchmark/go.mod b/benchmark/go.mod deleted file mode 100644 index 2a3144328b..0000000000 --- a/benchmark/go.mod +++ /dev/null @@ -1,58 +0,0 @@ -module github.com/thanos-io/thanos/benchmark - -require ( - cloud.google.com/go v0.25.0 - github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc // indirect - github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf // indirect - github.com/aws/aws-sdk-go v0.0.0-20161102215928-707203bc5511 // indirect - github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 // indirect - github.com/cespare/xxhash v1.0.0 // indirect - github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680 // indirect - github.com/go-ini/ini v1.38.1 // indirect - github.com/go-kit/kit v0.7.0 - github.com/go-logfmt/logfmt v0.3.0 // indirect - github.com/go-stack/stack v1.7.0 // indirect - github.com/gogo/protobuf v0.0.0-20170330071051-c0656edd0d9e // indirect - github.com/golang/glog v0.0.0-20141105023935-44145f04b68c // indirect - github.com/golang/protobuf v1.1.0 // indirect - github.com/google/btree v0.0.0-20180124185431-e89373fe6b4a // indirect - github.com/google/gofuzz v0.0.0-20161122191042-44d81051d367 // indirect - github.com/googleapis/gax-go v2.0.0+incompatible // indirect - github.com/googleapis/gnostic v0.0.0-20170729233727-0c5108395e2d // indirect - github.com/gregjones/httpcache v0.0.0-20170728041850-787624de3eb7 // indirect - github.com/imdario/mergo v0.0.0-20141206190957-6633656539c1 // indirect - github.com/jmespath/go-jmespath v0.0.0-20151117175822-3433f3ea46d9 // indirect - github.com/json-iterator/go v0.0.0-20180612202835-f2b4162afba3 // indirect - github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515 // indirect - github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect - github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect - github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 // indirect - github.com/oklog/ulid v0.3.0 - github.com/petar/GoLLRB v0.0.0-20130427215148-53be0d36a84c // indirect - github.com/peterbourgon/diskv v2.0.1+incompatible // indirect - github.com/pkg/errors v0.8.0 - github.com/prometheus/client_golang v0.8.0 // indirect - github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910 // indirect - github.com/prometheus/common v0.0.0-20180518154759-7600349dcfe1 - github.com/prometheus/procfs v0.0.0-20180705121852-ae68e2d4c00f // indirect - github.com/prometheus/prometheus v2.0.0+incompatible - github.com/prometheus/tsdb v0.0.0-20180711112126-99a2c4314ff7 - github.com/spf13/pflag v1.0.1 // indirect - go.opencensus.io v0.14.0 // indirect - golang.org/x/crypto v0.0.0-20180222182404-49796115aa4b // indirect - golang.org/x/net v0.0.0-20180712045933-cffdcf672aee // indirect - golang.org/x/oauth2 v0.0.0-20180620175406-ef147856a6dd // indirect - golang.org/x/sys v0.0.0-20180709060233-1b2967e3c290 // indirect - golang.org/x/text v0.3.0 // indirect - golang.org/x/time v0.0.0-20161028155119-f51c12702a4d // indirect - google.golang.org/api v0.0.0-20180711000437-1d2d9cc0ae74 - google.golang.org/appengine v1.1.0 // indirect - google.golang.org/genproto v0.0.0-20180709204101-e92b11657268 // indirect - google.golang.org/grpc v1.13.0 // indirect - gopkg.in/alecthomas/kingpin.v2 v2.2.6 - gopkg.in/inf.v0 v0.9.0 // indirect - gopkg.in/yaml.v2 v2.2.1 - k8s.io/api v0.0.0-20180628040859-072894a440bd - k8s.io/apimachinery v0.0.0-20180621070125-103fd098999d - k8s.io/client-go v8.0.0+incompatible -) diff --git a/benchmark/go.sum b/benchmark/go.sum deleted file mode 100644 index 274a4498b1..0000000000 --- a/benchmark/go.sum +++ /dev/null @@ -1,108 +0,0 @@ -cloud.google.com/go v0.25.0 h1:6vD6xZTc8Jo6To8gHxFDRVsMvWFDgY3rugNszcDalN8= -cloud.google.com/go v0.25.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc h1:cAKDfWh5VpdgMhJosfJnn5/FoN2SRZ4p7fJNX58YPaU= -github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= -github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf h1:qet1QNfXsQxTZqLG4oE62mJzwPIB8+Tee4RNCL9ulrY= -github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= -github.com/aws/aws-sdk-go v0.0.0-20161102215928-707203bc5511 h1:YdsDRm32rw2q3AMQXdvWu6AWC3anV5i4OROH4CpRxCM= -github.com/aws/aws-sdk-go v0.0.0-20161102215928-707203bc5511/go.mod h1:ZRmQr0FajVIyZ4ZzBYKG5P3ZqPz9IHG41ZoMu1ADI3k= -github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 h1:xJ4a3vCFaGF/jqvzLMYoU8P317H5OQ+Via4RmuPwCS0= -github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= -github.com/cespare/xxhash v1.0.0 h1:naDmySfoNg0nKS62/ujM6e71ZgM2AoVdaqGwMG0w18A= -github.com/cespare/xxhash v1.0.0/go.mod h1:fX/lfQBkSCDXZSUgv6jVIu/EVA3/JNseAX5asI4c4T4= -github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680 h1:ZktWZesgun21uEDrwW7iEV1zPCGQldM2atlJZ3TdvVM= -github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= -github.com/go-ini/ini v1.38.1 h1:hbtfM8emWUVo9GnXSloXYyFbXxZ+tG6sbepSStoe1FY= -github.com/go-ini/ini v1.38.1/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8= -github.com/go-kit/kit v0.7.0 h1:ApufNmWF1H6/wUbAG81hZOHmqwd0zRf8mNfLjYj/064= -github.com/go-kit/kit v0.7.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= -github.com/go-logfmt/logfmt v0.3.0 h1:8HUsc87TaSWLKwrnumgC8/YconD2fJQsRJAsWaPg2ic= -github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= -github.com/go-stack/stack v1.7.0 h1:S04+lLfST9FvL8dl4R31wVUC/paZp/WQZbLmUgWboGw= -github.com/go-stack/stack v1.7.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= -github.com/gogo/protobuf v0.0.0-20170330071051-c0656edd0d9e h1:ago6fNuQ6IhszPsXkeU7qRCyfsIX7L67WDybsAPkLl8= -github.com/gogo/protobuf v0.0.0-20170330071051-c0656edd0d9e/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= -github.com/golang/glog v0.0.0-20141105023935-44145f04b68c h1:CbdkBQ1/PiAo0FYJhQGwASD8wrgNvTdf01g6+O9tNuA= -github.com/golang/glog v0.0.0-20141105023935-44145f04b68c/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/protobuf v1.1.0 h1:0iH4Ffd/meGoXqF2lSAhZHt8X+cPgkfn/cb6Cce5Vpc= -github.com/golang/protobuf v1.1.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/google/btree v0.0.0-20180124185431-e89373fe6b4a h1:ZJu5NB1Bk5ms4vw0Xu4i+jD32SE9jQXyfnOvwhHqlT0= -github.com/google/btree v0.0.0-20180124185431-e89373fe6b4a/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= -github.com/google/gofuzz v0.0.0-20161122191042-44d81051d367 h1:ScAXWS+TR6MZKex+7Z8rneuSJH+FSDqd6ocQyl+ZHo4= -github.com/google/gofuzz v0.0.0-20161122191042-44d81051d367/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI= -github.com/googleapis/gax-go v2.0.0+incompatible h1:j0GKcs05QVmm7yesiZq2+9cxHkNK9YM6zKx4D2qucQU= -github.com/googleapis/gax-go v2.0.0+incompatible/go.mod h1:SFVmujtThgffbyetf+mdk2eWhX2bMyUtNHzFKcPA9HY= -github.com/googleapis/gnostic v0.0.0-20170729233727-0c5108395e2d h1:7XGaL1e6bYS1yIonGp9761ExpPPV1ui0SAC59Yube9k= -github.com/googleapis/gnostic v0.0.0-20170729233727-0c5108395e2d/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY= -github.com/gregjones/httpcache v0.0.0-20170728041850-787624de3eb7 h1:6TSoaYExHper8PYsJu23GWVNOyYRCSnIFyxKgLSZ54w= -github.com/gregjones/httpcache v0.0.0-20170728041850-787624de3eb7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= -github.com/imdario/mergo v0.0.0-20141206190957-6633656539c1 h1:FeeCi0I2Fu8kA8IXrdVPtGzym+mW9bzfj9f26EaES9k= -github.com/imdario/mergo v0.0.0-20141206190957-6633656539c1/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= -github.com/jmespath/go-jmespath v0.0.0-20151117175822-3433f3ea46d9 h1:1SlajWtS+u/6x2Be5vrHyrbSxkeIf/+ISBu//kmjpnc= -github.com/jmespath/go-jmespath v0.0.0-20151117175822-3433f3ea46d9/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= -github.com/json-iterator/go v0.0.0-20180612202835-f2b4162afba3 h1:/UewZcckqhvnnS0C6r3Sher2hSEbVmM6Ogpcjen08+Y= -github.com/json-iterator/go v0.0.0-20180612202835-f2b4162afba3/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= -github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515 h1:T+h1c/A9Gawja4Y9mFVWj2vyii2bbUNDw3kt9VxK2EY= -github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= -github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= -github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= -github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= -github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg= -github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= -github.com/oklog/ulid v0.3.0 h1:yEMMWFnYiPX/ytx1StIE0E1a35sm8MmWD/uSL9ZtKhg= -github.com/oklog/ulid v0.3.0/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= -github.com/petar/GoLLRB v0.0.0-20130427215148-53be0d36a84c/go.mod h1:HUpKUBZnpzkdx0kD/+Yfuft+uD3zHGtXF/XJB14TUr4= -github.com/peterbourgon/diskv v2.0.1+incompatible h1:UBdAOUP5p4RWqPBg048CAvpKN+vxiaj6gdUUzhl4XmI= -github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU= -github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw= -github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/prometheus/client_golang v0.8.0 h1:1921Yw9Gc3iSc4VQh3PIoOqgPCZS7G/4xQNVUp8Mda8= -github.com/prometheus/client_golang v0.8.0/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= -github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910 h1:idejC8f05m9MGOsuEi1ATq9shN03HrxNkD/luQvxCv8= -github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= -github.com/prometheus/common v0.0.0-20180518154759-7600349dcfe1 h1:osmNoEW2SCW3L7EX0km2LYM8HKpNWRiouxjE3XHkyGc= -github.com/prometheus/common v0.0.0-20180518154759-7600349dcfe1/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= -github.com/prometheus/procfs v0.0.0-20180705121852-ae68e2d4c00f h1:c9M4CCa6g8WURSsbrl3lb/w/G1Z5xZpYvhhjdcVDOkE= -github.com/prometheus/procfs v0.0.0-20180705121852-ae68e2d4c00f/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= -github.com/prometheus/prometheus v2.0.0+incompatible h1:C/Yz2tUD/mTqxClcOy8bhC00CRxll1OPiKTzoe/yeTM= -github.com/prometheus/prometheus v2.0.0+incompatible/go.mod h1:oAIUtOny2rjMX0OWN5vPR5/q/twIROJvdqnQKDdil/s= -github.com/prometheus/tsdb v0.0.0-20180711112126-99a2c4314ff7 h1:S+l5+6F0SDyoivQOhEud9UK8kZpj/NmXJ2UhLFDs1eQ= -github.com/prometheus/tsdb v0.0.0-20180711112126-99a2c4314ff7/go.mod h1:lFf/o1J2a31WmWQbxYXfY1azJK5Xp5D8hwKMnVMBTGU= -github.com/spf13/pflag v1.0.1 h1:aCvUg6QPl3ibpQUxyLkrEkCHtPqYJL4x9AuhqVqFis4= -github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= -go.opencensus.io v0.14.0 h1:1eTLxqxSIAylcKoxnNkdhvvBNZDA8JwkKNXxgyma0IA= -go.opencensus.io v0.14.0/go.mod h1:UffZAU+4sDEINUGP/B7UfBBkq4fqLu9zXAX7ke6CHW0= -golang.org/x/crypto v0.0.0-20180222182404-49796115aa4b h1:/GxqO8gbyb+sNnviFY2IIMrtm8vGg6NEJDft68wJY/g= -golang.org/x/crypto v0.0.0-20180222182404-49796115aa4b/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/net v0.0.0-20180712045933-cffdcf672aee h1:14ys0HdxY0i4v47fOrFhh1R/aGsvoAVTV8+HOKtULEE= -golang.org/x/net v0.0.0-20180712045933-cffdcf672aee/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/oauth2 v0.0.0-20180620175406-ef147856a6dd h1:QQhib242ErYDSMitlBm8V7wYCm/1a25hV8qMadIKLPA= -golang.org/x/oauth2 v0.0.0-20180620175406-ef147856a6dd/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/sys v0.0.0-20180709060233-1b2967e3c290 h1:lPmtvIvpa5gZbfK5Ms5fXR7KNpdSKkKE0W15ED+0p/U= -golang.org/x/sys v0.0.0-20180709060233-1b2967e3c290/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/time v0.0.0-20161028155119-f51c12702a4d h1:TnM+PKb3ylGmZvyPXmo9m/wktg7Jn/a/fNmr33HSj8g= -golang.org/x/time v0.0.0-20161028155119-f51c12702a4d/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -google.golang.org/api v0.0.0-20180711000437-1d2d9cc0ae74 h1:eSwjMEK8/4LOQckMIFCadse9TbkoPVbpenWFtVVDldI= -google.golang.org/api v0.0.0-20180711000437-1d2d9cc0ae74/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0= -google.golang.org/appengine v1.1.0 h1:igQkv0AAhEIvTEpD5LIpAfav2eeVO9HBTjvKHVJPRSs= -google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= -google.golang.org/genproto v0.0.0-20180709204101-e92b11657268 h1:ZxmDkz4oA3H5lKSXr68Ziv+dzLc6g/eMFgC0dg8wNtU= -google.golang.org/genproto v0.0.0-20180709204101-e92b11657268/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= -google.golang.org/grpc v1.13.0 h1:bHIbVsCwmvbArgCJmLdgOdHFXlKqTOVjbibbS19cXHc= -google.golang.org/grpc v1.13.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw= -gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc= -gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/inf.v0 v0.9.0 h1:3zYtXIO92bvsdS3ggAdA8Gb4Azj0YU+TVY1uGYNFA8o= -gopkg.in/inf.v0 v0.9.0/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= -gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE= -gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -k8s.io/api v0.0.0-20180628040859-072894a440bd h1:HzgYeLDS1jLxw8DGr68KJh9cdQ5iZJizG0HZWstIhfQ= -k8s.io/api v0.0.0-20180628040859-072894a440bd/go.mod h1:iuAfoD4hCxJ8Onx9kaTIt30j7jUFS00AXQi6QMi99vA= -k8s.io/apimachinery v0.0.0-20180621070125-103fd098999d h1:MZjlsu9igBoVPZkXpIGoxI6EonqNsXXZU7hhvfQLkd4= -k8s.io/apimachinery v0.0.0-20180621070125-103fd098999d/go.mod h1:ccL7Eh7zubPUSh9A3USN90/OzHNSVN6zxzde07TDCL0= -k8s.io/client-go v8.0.0+incompatible h1:tTI4hRmb1DRMl4fG6Vclfdi6nTM82oIrTT7HfitmxC4= -k8s.io/client-go v8.0.0+incompatible/go.mod h1:7vJpHMYJwNQCWgzmNV+VYUl1zCObLyodBc8nIyt8L5s= diff --git a/benchmark/pkg/tsdb/tsdb.go b/benchmark/pkg/tsdb/tsdb.go deleted file mode 100644 index 971c5ba04c..0000000000 --- a/benchmark/pkg/tsdb/tsdb.go +++ /dev/null @@ -1,310 +0,0 @@ -package tsdb - -import ( - "fmt" - "io/ioutil" - "math" - "math/rand" - "path/filepath" - "sort" - "time" - - "github.com/oklog/ulid" - "github.com/pkg/errors" - "github.com/prometheus/prometheus/tsdb/chunkenc" - "github.com/prometheus/prometheus/tsdb/chunks" - "github.com/prometheus/prometheus/tsdb/index" - "github.com/prometheus/prometheus/tsdb/labels" -) - -const ( - // The amount of overhead data per chunk. This assume 2 bytes to hold data length, 1 byte for version & 4 bytes for - // CRC hash. - chunkOverheadSize = 7 - - // TSDB enforces that each segment must be at most 512MB. - maxSegmentSize = 1024 * 1024 * 512 - - // Keep chunks small for performance. - maxChunkSize = 1024 * 16 - - // TSDB allows a maximum of 120 samples per chunk. - samplesPerChunk = 120 - - // The size of the header for each segment file. - segmentStartOffset = 8 - - blockMetaTemplate = `{ - "version": 1, - "ulid": "%s", - "minTime": %d, - "maxTime": %d, - "stats": { - "numSamples": %d, - "numSeries": %d, - "numChunks": %d - }, - "compaction": { - "level": 1, - "sources": [ - "%s" - ] - }, - "thanos": { - "labels": { - "id": "loadtest" - }, - "downsample": { - "resolution": 0 - } - } -}` -) - -type Opts struct { - OutputDir string // The directory to place the generated TSDB blocks. Default /tmp/tsdb. - NumTimeseries int // The number of timeseries to generate. Default 1. - StartTime time.Time // Metrics will be produced from this time. Default now. - EndTime time.Time // Metrics will be produced until this time. Default 1 week. - SampleInterval time.Duration // How often to sample the metrics. Default 15s. - BlockLength time.Duration // The length of time each block will cover. Default 2 hours. -} - -type timeseries struct { - ID uint64 - Name string - Chunks []chunks.Meta -} - -func CreateThanosTSDB(opts Opts) error { - if opts.OutputDir == "" { - opts.OutputDir = "/tmp/tsdb" - } - - if opts.NumTimeseries == 0 { - opts.NumTimeseries = 1 - } - - now := time.Now() - if opts.StartTime.IsZero() { - opts.StartTime = now.Add(-time.Hour * 24 * 7) - } - - if opts.EndTime.IsZero() { - opts.EndTime = now - } - - if opts.StartTime.After(opts.EndTime) { - return errors.New("end time cannot come after start time") - } - - if opts.SampleInterval == 0 { - opts.SampleInterval = time.Second * 15 - } - - if opts.BlockLength == 0 { - opts.BlockLength = time.Hour * 2 - } - - rng := rand.New(rand.NewSource(now.UnixNano())) - - for blockStart := opts.StartTime; blockStart.Before(opts.EndTime); blockStart = blockStart.Add(opts.BlockLength) { - if err := createBlock(opts, rng, blockStart, blockStart.Add(opts.BlockLength)); err != nil { - return err - } - } - - return nil -} - -func createBlock(opts Opts, rng *rand.Rand, blockStart time.Time, blockEnd time.Time) error { - // Generate block ID. - blockULID, err := ulid.New(uint64(blockEnd.Unix()), rng) - if err != nil { - return errors.Wrap(err, "failed to create ULID for block") - } - outputDir := filepath.Join(opts.OutputDir, blockULID.String()) - - // Create sorted list of timeseries to write. These will not be populated with data yet. - series := createEmptyTimeseries(opts.NumTimeseries) - - // Store chunks in series & write them to disk. - if err := populateChunks(series, outputDir, blockStart, blockEnd, opts.SampleInterval); err != nil { - return errors.Wrap(err, "failed to create chunks") - } - - // Store references to these chunks in the index. - if err := createIndex(series, outputDir); err != nil { - return errors.Wrap(err, "failed to create index") - } - - // Add thanos metadata for this block. - numChunks := int64(opts.NumTimeseries) * (blockEnd.Sub(blockStart).Nanoseconds() / (opts.SampleInterval * samplesPerChunk).Nanoseconds()) - thanosMeta := fmt.Sprintf(blockMetaTemplate, blockULID, blockStart.Unix()*1000, blockEnd.Unix()*1000, numChunks*samplesPerChunk, opts.NumTimeseries, numChunks, blockULID) - if err := ioutil.WriteFile(filepath.Join(outputDir, "meta.json"), []byte(thanosMeta), 0755); err != nil { - return errors.Wrap(err, "failed to write thanos metadata") - } - - return nil -} - -// createEmptyTimeseries will return `numTimeseries` unique timeseries structs. Does not populate these timeseries with -// data yet. -func createEmptyTimeseries(numTimeseries int) []*timeseries { - // Ensure names are generated in alphabetical order by padding names with leading zeroes. - nameTmpl := fmt.Sprintf("ts_%%0%dd", int(math.Ceil(math.Log10(float64(numTimeseries))))) - - series := make([]*timeseries, numTimeseries) - for i := 0; i < numTimeseries; i++ { - series[i] = ×eries{ - ID: uint64(i), - Name: fmt.Sprintf(nameTmpl, i), - } - } - - sort.Slice(series, func(i, j int) bool { - return series[i].Name < series[j].Name - }) - - return series -} - -// populateChunks will populate `series` with a list of chunks for each timeseries. The chunks will span the entire -// duration from blockStart to blockEnd. It will also write these chunks to the block's output directory. -func populateChunks(series []*timeseries, outputDir string, blockStart time.Time, blockEnd time.Time, sampleInterval time.Duration) error { - cw, err := chunks.NewWriter(filepath.Join(outputDir, "chunks")) - if err != nil { - return err - } - - // The reference into the chunk where a timeseries starts. - ref := uint64(segmentStartOffset) - seg := uint64(0) - - // The total size of the chunk. - chunkLength := sampleInterval * samplesPerChunk - - // Populate each series with fake metrics. - for _, s := range series { - // Segment block into small chunks. - for chunkStart := blockStart; chunkStart.Before(blockEnd); chunkStart = chunkStart.Add(chunkLength) { - ch := chunkenc.NewXORChunk() - app, err := ch.Appender() - if err != nil { - return err - } - - // Write series data for this chunk. - for sample := chunkStart; sample.Before(chunkStart.Add(chunkLength)); sample = sample.Add(sampleInterval) { - // Write a random value at this time. Time must be specified in ms. - // TODO: Give wider control of the values written. We do not always want random timeseries. - app.Append(sample.Unix()*1000, rand.Float64()) - } - - // Calcuate size of this chunk. This is the amount of bytes written plus the chunk overhead. See - // https://github.com/prometheus/tsdb/blob/master/docs/format/chunks.md for a breakdown of the overhead. - // Assumes that the len uvarint has size 2. - size := uint64(len(ch.Bytes())) + chunkOverheadSize - if size > maxChunkSize { - return errors.Errorf("chunk too big, calculated size %d > %d", size, maxChunkSize) - } - - // Reference a new segment if the current is out of space. - if ref+size > maxSegmentSize { - ref = segmentStartOffset - seg++ - } - - chunkStartMs := chunkStart.Unix() * 1000 - cm := chunks.Meta{ - Chunk: ch, - MinTime: chunkStartMs, - MaxTime: chunkStartMs + sampleInterval.Nanoseconds()/(1000*1000), - Ref: ref | (seg << 32), - } - - s.Chunks = append(s.Chunks, cm) - - ref += size - } - - if err := cw.WriteChunks(s.Chunks...); err != nil { - return err - } - } - - if err := cw.Close(); err != nil { - return err - } - - return nil -} - -// createIndex will write the index file. It should reference the chunks previously created. -func createIndex(series []*timeseries, outputDir string) error { - iw, err := index.NewWriter(filepath.Join(outputDir, "index")) - if err != nil { - return err - } - - // Add the symbol table from all symbols we use. - if err := iw.AddSymbols(getSymbols(series)); err != nil { - return err - } - - // Add chunk references. - for _, s := range series { - if err := iw.AddSeries(s.ID, labels.Labels{{Name: "__name__", Value: s.Name}}, s.Chunks...); err != nil { - return errors.Wrapf(err, "failed to write timeseries for %s", s.Name) - } - } - - // Add mapping of label names to label values that we use. - if err := iw.WriteLabelIndex([]string{"__name__"}, getLabelValues(series)); err != nil { - return err - } - - // Create & populate postings. - postings := index.NewMemPostings() - for _, s := range series { - postings.Add(s.ID, labels.Labels{labels.Label{Name: "__name__", Value: s.Name}}) - } - - // Add references to index for each label name/value pair. - for _, l := range postings.SortedKeys() { - if err := iw.WritePostings(l.Name, l.Value, postings.Get(l.Name, l.Value)); err != nil { - return errors.Wrap(err, "write postings") - } - } - - // Output index to file. - if err := iw.Close(); err != nil { - return err - } - - return nil -} - -// getSymbols returns a set of symbols that we use in all timeseries labels & values. -func getSymbols(series []*timeseries) map[string]struct{} { - symbols := map[string]struct{}{ - "__name__": {}, - } - - for _, s := range series { - symbols[s.Name] = struct{}{} - } - - return symbols -} - -// getLabelValues returns a list of all labels that we use for series values. -func getLabelValues(series []*timeseries) []string { - labs := make([]string, len(series)) - - for i, s := range series { - labs[i] = s.Name - } - - return labs -} diff --git a/benchmark/terraform/gcp.tf b/benchmark/terraform/gcp.tf deleted file mode 100644 index 6265308774..0000000000 --- a/benchmark/terraform/gcp.tf +++ /dev/null @@ -1,70 +0,0 @@ -# Bucket for thanos sidecars to ship metrics. -variable "store_bucket_name" {} - -# Location of the bucket holding metrics. -variable "location" { - default = "EU" -} - -# Region to use with provider. -variable "region" { - default = "europe-west1" -} - -# Zone to run GKE cluster running thanos. -variable "thanos_zone" { - default = "europe-west1-b" -} - -# Gcloud project to use. -variable "project" {} - -# Storage of terraform state. -terraform { - backend "gcs" { - bucket = "terraform-state" - path = "thanos-loadtest/terraform.tfstate" - project = "alert-diode-174314" - } -} - -# Provider options. -provider "google" { - project = "${var.project}" - region = "europe-west1" - version = "~> 1.2" -} - -# Service account kubernetes nodes will run as. -data "google_compute_default_service_account" "default" {} - -# Bucket to hold metrics. -resource "google_storage_bucket" "bucket" { - name = "${var.store_bucket_name}" - location = "${var.location}" - force_destroy = true -} - -# Ensure service account has permissions for the storage bucket. -resource "google_storage_bucket_iam_member" "default" { - bucket = "${var.store_bucket_name}" - role = "roles/storage.admin" - member = "serviceAccount:${data.google_compute_default_service_account.default.id}" -} - -# GKE cluster to run thanos. -resource "google_container_cluster" "cluster" { - name = "thanos-loadtest" - zone = "${var.thanos_zone}" - initial_node_count = 1 - min_master_version = "1.9.7-gke.3" - - node_config { - oauth_scopes = [ - "https://www.googleapis.com/auth/devstorage.read_write", - "https://www.googleapis.com/auth/logging.write", - "https://www.googleapis.com/auth/monitoring", - ] - machine_type = "n1-standard-16" - } -}