Skip to content

Commit

Permalink
PMM-11727: make promscrape.maxScrapeSize 64MiB by default, allow over…
Browse files Browse the repository at this point in the history
…ride via ENV (#1862)
  • Loading branch information
ritbl authored Mar 13, 2023
1 parent d551ba7 commit b68c888
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
12 changes: 12 additions & 0 deletions managed/services/agents/vmagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
35 changes: 35 additions & 0 deletions managed/services/agents/vmagent_test.go
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.

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)
})
}

0 comments on commit b68c888

Please sign in to comment.