diff --git a/managed/services/agents/vmagent.go b/managed/services/agents/vmagent.go index cb04ce25e7..136a3451d4 100644 --- a/managed/services/agents/vmagent.go +++ b/managed/services/agents/vmagent.go @@ -16,19 +16,31 @@ package agents import ( + "os" "sort" "github.com/percona/pmm/api/agentpb" "github.com/percona/pmm/api/inventorypb" ) +var ( + maxScrapeSizeEnv = "PMM_PROMSCRAPE_MAX_SCRAPE_SIZE" + maxScrapeSizeDefault = "64MiB" +) + // vmAgentConfig returns desired configuration of vmagent process. func vmAgentConfig(scrapeCfg string) *agentpb.SetStateRequest_AgentProcess { + maxScrapeSize := maxScrapeSizeDefault + if space := os.Getenv(maxScrapeSizeEnv); space != "" { + maxScrapeSize = space + } + args := []string{ "-remoteWrite.url={{.server_url}}/victoriametrics/api/v1/write", "-remoteWrite.tlsInsecureSkipVerify={{.server_insecure}}", "-remoteWrite.tmpDataPath={{.tmp_dir}}/vmagent-temp-dir", "-promscrape.config={{.TextFiles.vmagentscrapecfg}}", + "-promscrape.maxScrapeSize=" + maxScrapeSize, // 1GB disk queue size. "-remoteWrite.maxDiskUsagePerURL=1073741824", "-loggerLevel=INFO", diff --git a/managed/services/agents/vmagent_test.go b/managed/services/agents/vmagent_test.go new file mode 100644 index 0000000000..2adc5fded8 --- /dev/null +++ b/managed/services/agents/vmagent_test.go @@ -0,0 +1,35 @@ +// Copyright (C) 2017 Percona LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package agents + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestMaxScrapeSize(t *testing.T) { + t.Run("by default 64MiB", func(t *testing.T) { + actual := vmAgentConfig("") + assert.Contains(t, actual.Args, "-promscrape.maxScrapeSize="+maxScrapeSizeDefault) + }) + t.Run("overridden with ENV", func(t *testing.T) { + newValue := "16MiB" + t.Setenv(maxScrapeSizeEnv, newValue) + actual := vmAgentConfig("") + assert.Contains(t, actual.Args, "-promscrape.maxScrapeSize="+newValue) + }) +}