Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge upstream prometheus/prometheus at 37b408c #639

Merged
merged 71 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from 67 commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
34072ff
makefile: let golangci-lint also run on arm64
mickael-carl May 6, 2023
420b324
docs: add a quick note on linting in contributing guidelines
mickael-carl May 6, 2023
c5a1cc9
chore(tsdb): add a sandboxDir to DBReadOnly, the directory can be use…
machine424 Nov 29, 2023
0cd3a22
docs: [ovh sd] Added missing label for OVH dedicated server in servic…
Apr 30, 2024
8742768
bugfix: allow opting-out of multi-cluster setups
rexagod May 7, 2024
aabe4d6
promql.ActiveQueryTracker: Unmap mmapped file when done
aknuds1 Apr 29, 2024
fdfc6d4
Benchmark zeroOrOneCharacterStringMatcher.Matches
colega May 13, 2024
bcff505
Use utf8.DecodeRuneInString(s)
colega May 13, 2024
dbe88fa
Add invalid utf8 test cases to regexp
colega May 13, 2024
8b4c945
Check utf8.RuneError result
colega May 13, 2024
548bd9d
adds TestNativeHistogramRate func to promql test framework
NeerajGartia21 Feb 25, 2024
8b838a0
adds test for native histogram rate func in promql testing framework
NeerajGartia21 Mar 21, 2024
adf5a36
adds test for sum, count, stddev, stdvar, quantile and fraction func …
NeerajGartia21 Apr 10, 2024
6119124
some nits
NeerajGartia21 Apr 11, 2024
661856c
removes the added tests from engine_test.go
NeerajGartia21 May 6, 2024
10eb23b
[TEST] Rules: Sleep 15ms to fit Windows behaviour better
bboreham May 14, 2024
f10c345
Enable perfsprint linter and fix up code
alexandear May 13, 2024
806073a
Merge pull request #14091 from alexandear/enable-perfsprint-linter
beorn7 May 15, 2024
bf8d88f
Merge remote-tracking branch 'origin/main' into arve/query-logger-munmap
aknuds1 May 15, 2024
0b1a0c0
Merge pull request #14062 from rexagod/multicluster-opt-out
metalmatze May 15, 2024
0f01d4b
Fix flaky test
aknuds1 May 15, 2024
1e0b0e2
Merge pull request #14090 from colega/improve-zeroOrOneCharacterStrin…
bboreham May 16, 2024
5ca56ee
tsdb/index: Refactor Reader tests (#14071)
aknuds1 May 16, 2024
d1eff95
Merge pull request #14100 from bboreham/windows-flake
roidelapluie May 16, 2024
edf5ebd
Merge pull request #13970 from jiekun/doc/ovh-dedicated-server-label
roidelapluie May 16, 2024
0fea106
added line When set, query.max-concurrency may need to be adjusted ac…
kushalShukla-web May 18, 2024
52f68a9
web/api: export defaultStatsRenderer (#14121)
krajorama May 18, 2024
114dc5c
Merge pull request #13638 from NeerajGartia21/promql-test
beorn7 May 19, 2024
fe9cb5a
Check context every 128 labels instead of 100 (#14118)
colega May 21, 2024
3119b8a
Merge pull request #13218 from machine424/ro-promtool
beorn7 May 21, 2024
3127a40
doc: Clarify the limits of dumping/backfilling via OpenMetrics
beorn7 May 21, 2024
5c85a55
Merge pull request #14120 from kushalShukla-web/remote
beorn7 May 21, 2024
fabcd7e
fix(api): Send warnings only if the limit is really exceeded (#14116)
machine424 May 21, 2024
2d2b440
fix: correct the typo in azuread sdk auth (#14106)
slashpai May 21, 2024
1081e33
Merge pull request #14129 from prometheus/beorn7/doc
beorn7 May 23, 2024
5be753f
.gitpod.Dockerfile: Auto-fetch Go and goyacc vers
mohamedawnallah May 24, 2024
0512ebf
Merge branch 'main' into mcarl/lint
roidelapluie May 24, 2024
a895265
Merge pull request #12339 from mickael-carl/mcarl/lint
roidelapluie May 24, 2024
c0221d9
Merge pull request #14130 from mohamedawnallah/fetchGoVersionGitpodDo…
ArthurSens May 24, 2024
8894d65
Fix head stats and hooks when replaying a corrupted snapshot (#14079)
alanprot May 25, 2024
7b56353
Merge remote-tracking branch 'prometheus/main' into arve/query-logger…
aknuds1 May 27, 2024
f3b8750
Join errors
aknuds1 May 27, 2024
e6f1f7e
docs/configuration: clarify OpenStack metadata labels (#14149)
simonpasquier May 27, 2024
707e9d9
Merge pull request #14000 from aknuds1/arve/query-logger-munmap
aknuds1 May 27, 2024
b2396c0
Upgrade to golangci-lint v1.59.0
aknuds1 May 27, 2024
1971a58
Merge pull request #14153 from aknuds1/arve/upgrade-linter
SuperQ May 28, 2024
013998f
Bump golangci-lint action (#14154)
mmorel-35 May 28, 2024
25b0991
Enable additional Go metrics
SuperQ May 27, 2024
a6316a5
Merge pull request #14148 from prometheus/superq/more_go_metrics
SuperQ May 28, 2024
6683895
optimize regex matching for empty label values in posting match (#14075)
yeya24 May 29, 2024
37b408c
Feature: Allow configuration of a rule evaluation delay (#14061)
gotjosh May 30, 2024
648eff1
Merge remote-tracking branch 'upstream/main' into gotjosh/update-mimi…
gotjosh May 30, 2024
8d8d930
fix perfsprint linter
gotjosh May 31, 2024
c9bb46a
Fix more linters
gotjosh May 31, 2024
e92d09d
introduce backwards compatibility between evaluation interval and que…
gotjosh May 31, 2024
786bf30
linter
gotjosh Jun 3, 2024
e17a684
Use oleg's fork of YAML v3 to ensure custom marshallers have backward…
gotjosh Jun 3, 2024
28fa973
test backwards compatbility of `query_offset` when marshalling
gotjosh Jun 3, 2024
7a6e325
Use the `goleak` version that excludes the dependecies that produce f…
gotjosh Jun 3, 2024
86722a6
Address review comments
gotjosh Jun 3, 2024
9433b57
Remove closure of reader on `TestIndexRW_Postings`
gotjosh Jun 4, 2024
06f1651
Avoid duplication in createFileReaderWithOptions
gotjosh Jun 4, 2024
3836920
Revert "Fix more linters"
gotjosh Jun 5, 2024
2e6cc9b
Revert "fix perfsprint linter"
gotjosh Jun 5, 2024
9cce125
update golangcilint to match Prometheus
gotjosh Jun 5, 2024
199a070
Fix lint
gotjosh Jun 6, 2024
a8dec7c
Preserve both `evaluation_delay` and `query_offset`
gotjosh Jun 6, 2024
969d5ee
Fixed typo
pracucci Jun 6, 2024
c210ff7
Do not handle the migration at YAML serialization, but giving prefere…
pracucci Jun 6, 2024
29c0c58
Fix linter issue
pracucci Jun 6, 2024
03092b6
Trigger CI
pracucci Jun 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,21 @@ on:

jobs:
golangci:
name: lint
name: golangci-lint
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: install Go
uses: actions/setup-go@v2
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
- name: Install Go
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
with:
go-version: '>=1.21 <1.22'
go-version: 1.22.x
- name: Install snmp_exporter/generator dependencies
run: sudo apt-get update && sudo apt-get -y install libsnmp-dev
if: github.repository == 'prometheus/snmp_exporter'
- name: Lint
uses: golangci/golangci-lint-action@v4.0.0
uses: golangci/golangci-lint-action@a4f60bb28d35aeee14e6880718e0c85ff1882e64 # v6.0.1
with:
# # Make sure to sync this with Makefile.common.
version: v1.56.2
args: --verbose
# Make sure to sync this with Makefile.common and scripts/golangci-lint.yml.
version: v1.59.0
32 changes: 25 additions & 7 deletions .gitpod.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
FROM gitpod/workspace-full

# Set Node.js version as an environment variable.
ENV CUSTOM_NODE_VERSION=16
ENV CUSTOM_GO_VERSION=1.19
ENV GOPATH=$HOME/go-packages
ENV GOROOT=$HOME/go
ENV PATH=$GOROOT/bin:$GOPATH/bin:$PATH

# Install and use the specified Node.js version via nvm.
RUN bash -c ". .nvm/nvm.sh && nvm install ${CUSTOM_NODE_VERSION} && nvm use ${CUSTOM_NODE_VERSION} && nvm alias default ${CUSTOM_NODE_VERSION}"

# Ensure nvm uses the default Node.js version in all new shells.
RUN echo "nvm use default &>/dev/null" >> ~/.bashrc.d/51-nvm-fix
RUN curl -fsSL https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz | tar xzs \
&& printf '%s\n' 'export GOPATH=/workspace/go' \
'export PATH=$GOPATH/bin:$PATH' > $HOME/.bashrc.d/300-go

# Remove any existing Go installation in $HOME path.
RUN rm -rf $HOME/go $HOME/go-packages

# Export go environment variables.
RUN echo "export GOPATH=/workspace/go" >> ~/.bashrc.d/300-go && \
echo "export GOBIN=\$GOPATH/bin" >> ~/.bashrc.d/300-go && \
echo "export GOROOT=${HOME}/go" >> ~/.bashrc.d/300-go && \
echo "export PATH=\$GOROOT/bin:\$GOBIN:\$PATH" >> ~/.bashrc

# Reload the environment variables to ensure go environment variables are
# available in subsequent commands.
RUN bash -c "source ~/.bashrc && source ~/.bashrc.d/300-go"

# Fetch the Go version dynamically from the Prometheus go.mod file and Install Go in $HOME path.
RUN export CUSTOM_GO_VERSION=$(curl -sSL "https://raw.githubusercontent.com/prometheus/prometheus/main/go.mod" | awk '/^go/{print $2".0"}') && \
curl -fsSL "https://dl.google.com/go/go${CUSTOM_GO_VERSION}.linux-amd64.tar.gz" | \
tar -xz -C $HOME

# Fetch the goyacc parser version dynamically from the Prometheus Makefile
# and install it globally in $GOBIN path.
RUN GOYACC_VERSION=$(curl -fsSL "https://raw.githubusercontent.com/prometheus/prometheus/main/Makefile" | awk -F'=' '/GOYACC_VERSION \?=/{gsub(/ /, "", $2); print $2}') && \
go install "golang.org/x/tools/cmd/goyacc@${GOYACC_VERSION}"
8 changes: 7 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ linters:
- goimports
- misspell
- nolintlint
- perfsprint
- predeclared
- revive
- testifylint
Expand All @@ -44,7 +45,9 @@ issues:
- linters:
- godot
source: "^// ==="

- linters:
- perfsprint
text: "fmt.Sprintf can be replaced with string concatenation"
linters-settings:
depguard:
rules:
Expand Down Expand Up @@ -85,6 +88,9 @@ linters-settings:
local-prefixes: github.com/prometheus/prometheus
gofumpt:
extra-rules: true
perfsprint:
# Optimizes `fmt.Errorf`.
errorf: false
revive:
# By default, revive will enable only the linting rules that are named in the configuration file.
# So, it's needed to explicitly set in configuration all required rules.
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## unreleased

* [CHANGE] Rules: Execute 1 query instead of N (where N is the number of alerts within alert rule) when restoring alerts. #13980
* [FEATURE] Rules: Add new option `query_offset` for each rule group via rule group configuration file and `rule_query_offset` as part of the global configuration to have more resilience for remote write delays. #14061
* [ENHANCEMENT] Rules: Add `rule_group_last_restore_duration_seconds` to measure the time it takes to restore a rule group. #13974
* [ENHANCEMENT] OTLP: Improve remote write format translation performance by using label set hashes for metric identifiers instead of string based ones. #14006 #13991
* [ENHANCEMENT] TSDB: Optimize querying with regexp matchers. #13620
Expand Down
7 changes: 6 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ go build ./cmd/prometheus/
make test # Make sure all the tests pass before you commit and push :)
```

We use [`golangci-lint`](https://github.com/golangci/golangci-lint) for linting the code. If it reports an issue and you think that the warning needs to be disregarded or is a false-positive, you can add a special comment `//nolint:linter1[,linter2,...]` before the offending line. Use this sparingly though, fixing the code to comply with the linter's recommendation is in general the preferred course of action.
To run a collection of Go linters through [`golangci-lint`](https://github.com/golangci/golangci-lint), do:
```bash
make lint
```

If it reports an issue and you think that the warning needs to be disregarded or is a false-positive, you can add a special comment `//nolint:linter1[,linter2,...]` before the offending line. Use this sparingly though, fixing the code to comply with the linter's recommendation is in general the preferred course of action. See [this section of the golangci-lint documentation](https://golangci-lint.run/usage/false-positives/#nolint-directive) for more information.

All our issues are regularly tagged so that you can also filter down the issues involving the components you want to work on. For our labeling policy refer [the wiki page](https://github.com/prometheus/prometheus/wiki/Label-Names-and-Descriptions).

Expand Down
2 changes: 1 addition & 1 deletion Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_
SKIP_GOLANGCI_LINT :=
GOLANGCI_LINT :=
GOLANGCI_LINT_OPTS ?=
GOLANGCI_LINT_VERSION ?= v1.56.2
GOLANGCI_LINT_VERSION ?= v1.59.0
# golangci-lint only supports linux, darwin and windows platforms on i386/amd64/arm64.
# windows isn't included here because of the path separator being different.
ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux darwin))
Expand Down
18 changes: 17 additions & 1 deletion cmd/prometheus/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
"github.com/mwitkow/go-conntrack"
"github.com/oklog/run"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/collectors"
versioncollector "github.com/prometheus/client_golang/prometheus/collectors/version"
"github.com/prometheus/common/model"
"github.com/prometheus/common/promlog"
Expand Down Expand Up @@ -252,6 +253,18 @@ func main() {
newFlagRetentionDuration model.Duration
)

// Unregister the default GoCollector, and reregister with our defaults.
if prometheus.Unregister(collectors.NewGoCollector()) {
prometheus.MustRegister(
collectors.NewGoCollector(
collectors.WithGoCollectorRuntimeMetrics(
collectors.MetricsGC,
collectors.MetricsScheduler,
),
),
)
}

cfg := flagConfig{
notifier: notifier.Options{
Registerer: prometheus.DefaultRegisterer,
Expand Down Expand Up @@ -418,7 +431,7 @@ func main() {
serverOnlyFlag(a, "rules.alert.resend-delay", "Minimum amount of time to wait before resending an alert to Alertmanager.").
Default("1m").SetValue(&cfg.resendDelay)

serverOnlyFlag(a, "rules.max-concurrent-evals", "Global concurrency limit for independent rules that can run concurrently.").
serverOnlyFlag(a, "rules.max-concurrent-evals", "Global concurrency limit for independent rules that can run concurrently. When set, \"query.max-concurrency\" may need to be adjusted accordingly.").
Default("4").Int64Var(&cfg.maxConcurrentEvals)

a.Flag("scrape.adjust-timestamps", "Adjust scrape timestamps by up to `scrape.timestamp-tolerance` to align them to the intended schedule. See https://github.com/prometheus/prometheus/issues/7846 for more context. Experimental. This flag will be removed in a future release.").
Expand Down Expand Up @@ -772,6 +785,9 @@ func main() {
ResendDelay: time.Duration(cfg.resendDelay),
MaxConcurrentEvals: cfg.maxConcurrentEvals,
ConcurrentEvalsEnabled: cfg.enableConcurrentRuleEval,
DefaultRuleQueryOffset: func() time.Duration {
return time.Duration(cfgFile.GlobalConfig.RuleQueryOffset)
},
})
}

Expand Down
3 changes: 2 additions & 1 deletion cmd/prometheus/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"os/exec"
"path/filepath"
"runtime"
"strconv"
"strings"
"syscall"
"testing"
Expand Down Expand Up @@ -189,7 +190,7 @@ func TestSendAlerts(t *testing.T) {

for i, tc := range testCases {
tc := tc
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
t.Run(strconv.Itoa(i), func(t *testing.T) {
senderFunc := senderFunc(func(alerts ...*notifier.Alert) {
require.NotEmpty(t, tc.in, "sender called with 0 alert")
require.Equal(t, tc.exp, alerts)
Expand Down
4 changes: 2 additions & 2 deletions cmd/prometheus/query_log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ func (p *queryLogTest) run(t *testing.T) {
if p.exactQueryCount() {
require.Equal(t, 1, qc)
} else {
require.Greater(t, qc, 0, "no queries logged")
require.Positive(t, qc, "no queries logged")
}
p.validateLastQuery(t, ql)

Expand Down Expand Up @@ -366,7 +366,7 @@ func (p *queryLogTest) run(t *testing.T) {
if p.exactQueryCount() {
require.Equal(t, 1, qc)
} else {
require.Greater(t, qc, 0, "no queries logged")
require.Positive(t, qc, "no queries logged")
}
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/promtool/backfill.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func createBlocks(input []byte, mint, maxt, maxBlockDuration int64, maxSamplesIn
blockDuration := getCompatibleBlockDuration(maxBlockDuration)
mint = blockDuration * (mint / blockDuration)

db, err := tsdb.OpenDBReadOnly(outputDir, nil)
db, err := tsdb.OpenDBReadOnly(outputDir, "", nil)
if err != nil {
return err
}
Expand Down
8 changes: 5 additions & 3 deletions cmd/promtool/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,14 @@ func main() {

tsdbDumpCmd := tsdbCmd.Command("dump", "Dump samples from a TSDB.")
dumpPath := tsdbDumpCmd.Arg("db path", "Database path (default is "+defaultDBPath+").").Default(defaultDBPath).String()
dumpSandboxDirRoot := tsdbDumpCmd.Flag("sandbox-dir-root", "Root directory where a sandbox directory would be created in case WAL replay generates chunks. The sandbox directory is cleaned up at the end.").Default(defaultDBPath).String()
dumpMinTime := tsdbDumpCmd.Flag("min-time", "Minimum timestamp to dump.").Default(strconv.FormatInt(math.MinInt64, 10)).Int64()
dumpMaxTime := tsdbDumpCmd.Flag("max-time", "Maximum timestamp to dump.").Default(strconv.FormatInt(math.MaxInt64, 10)).Int64()
dumpMatch := tsdbDumpCmd.Flag("match", "Series selector. Can be specified multiple times.").Default("{__name__=~'(?s:.*)'}").Strings()

tsdbDumpOpenMetricsCmd := tsdbCmd.Command("dump-openmetrics", "[Experimental] Dump samples from a TSDB into OpenMetrics format. Native histograms are not dumped.")
tsdbDumpOpenMetricsCmd := tsdbCmd.Command("dump-openmetrics", "[Experimental] Dump samples from a TSDB into OpenMetrics text format, excluding native histograms and staleness markers, which are not representable in OpenMetrics.")
dumpOpenMetricsPath := tsdbDumpOpenMetricsCmd.Arg("db path", "Database path (default is "+defaultDBPath+").").Default(defaultDBPath).String()
dumpOpenMetricsSandboxDirRoot := tsdbDumpOpenMetricsCmd.Flag("sandbox-dir-root", "Root directory where a sandbox directory would be created in case WAL replay generates chunks. The sandbox directory is cleaned up at the end.").Default(defaultDBPath).String()
dumpOpenMetricsMinTime := tsdbDumpOpenMetricsCmd.Flag("min-time", "Minimum timestamp to dump.").Default(strconv.FormatInt(math.MinInt64, 10)).Int64()
dumpOpenMetricsMaxTime := tsdbDumpOpenMetricsCmd.Flag("max-time", "Maximum timestamp to dump.").Default(strconv.FormatInt(math.MaxInt64, 10)).Int64()
dumpOpenMetricsMatch := tsdbDumpOpenMetricsCmd.Flag("match", "Series selector. Can be specified multiple times.").Default("{__name__=~'(?s:.*)'}").Strings()
Expand Down Expand Up @@ -396,9 +398,9 @@ func main() {
os.Exit(checkErr(listBlocks(*listPath, *listHumanReadable)))

case tsdbDumpCmd.FullCommand():
os.Exit(checkErr(dumpSamples(ctx, *dumpPath, *dumpMinTime, *dumpMaxTime, *dumpMatch, formatSeriesSet)))
os.Exit(checkErr(dumpSamples(ctx, *dumpPath, *dumpSandboxDirRoot, *dumpMinTime, *dumpMaxTime, *dumpMatch, formatSeriesSet)))
case tsdbDumpOpenMetricsCmd.FullCommand():
os.Exit(checkErr(dumpSamples(ctx, *dumpOpenMetricsPath, *dumpOpenMetricsMinTime, *dumpOpenMetricsMaxTime, *dumpOpenMetricsMatch, formatSeriesSetOpenMetrics)))
os.Exit(checkErr(dumpSamples(ctx, *dumpOpenMetricsPath, *dumpOpenMetricsSandboxDirRoot, *dumpOpenMetricsMinTime, *dumpOpenMetricsMaxTime, *dumpOpenMetricsMatch, formatSeriesSetOpenMetrics)))
// TODO(aSquare14): Work on adding support for custom block size.
case openMetricsImportCmd.FullCommand():
os.Exit(backfillOpenMetrics(*importFilePath, *importDBPath, *importHumanReadable, *importQuiet, *maxBlockDuration))
Expand Down
3 changes: 2 additions & 1 deletion cmd/promtool/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"os/exec"
"path/filepath"
"runtime"
"strconv"
"strings"
"syscall"
"testing"
Expand Down Expand Up @@ -410,7 +411,7 @@ func TestExitCodes(t *testing.T) {
} {
t.Run(c.file, func(t *testing.T) {
for _, lintFatal := range []bool{true, false} {
t.Run(fmt.Sprintf("%t", lintFatal), func(t *testing.T) {
t.Run(strconv.FormatBool(lintFatal), func(t *testing.T) {
args := []string{"-test.main", "check", "config", "testdata/" + c.file}
if lintFatal {
args = append(args, "--lint-fatal")
Expand Down
14 changes: 7 additions & 7 deletions cmd/promtool/tsdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ func readPrometheusLabels(r io.Reader, n int) ([]labels.Labels, error) {
}

func listBlocks(path string, humanReadable bool) error {
db, err := tsdb.OpenDBReadOnly(path, nil)
db, err := tsdb.OpenDBReadOnly(path, "", nil)
if err != nil {
return err
}
Expand Down Expand Up @@ -393,7 +393,7 @@ func getFormatedBytes(bytes int64, humanReadable bool) string {
}

func openBlock(path, blockID string) (*tsdb.DBReadOnly, tsdb.BlockReader, error) {
db, err := tsdb.OpenDBReadOnly(path, nil)
db, err := tsdb.OpenDBReadOnly(path, "", nil)
if err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -708,8 +708,8 @@ func analyzeCompaction(ctx context.Context, block tsdb.BlockReader, indexr tsdb.

type SeriesSetFormatter func(series storage.SeriesSet) error

func dumpSamples(ctx context.Context, path string, mint, maxt int64, match []string, formatter SeriesSetFormatter) (err error) {
db, err := tsdb.OpenDBReadOnly(path, nil)
func dumpSamples(ctx context.Context, dbDir, sandboxDirRoot string, mint, maxt int64, match []string, formatter SeriesSetFormatter) (err error) {
db, err := tsdb.OpenDBReadOnly(dbDir, sandboxDirRoot, nil)
if err != nil {
return err
}
Expand Down Expand Up @@ -856,9 +856,9 @@ func displayHistogram(dataType string, datas []int, total int) {
}
avg := sum / len(datas)
fmt.Printf("%s (min/avg/max): %d/%d/%d\n", dataType, datas[0], avg, datas[len(datas)-1])
maxLeftLen := strconv.Itoa(len(fmt.Sprintf("%d", end)))
maxRightLen := strconv.Itoa(len(fmt.Sprintf("%d", end+step)))
maxCountLen := strconv.Itoa(len(fmt.Sprintf("%d", maxCount)))
maxLeftLen := strconv.Itoa(len(strconv.Itoa(end)))
maxRightLen := strconv.Itoa(len(strconv.Itoa(end + step)))
maxCountLen := strconv.Itoa(len(strconv.Itoa(maxCount)))
for bucket, count := range buckets {
percentage := 100.0 * count / total
fmt.Printf("[%"+maxLeftLen+"d, %"+maxRightLen+"d]: %"+maxCountLen+"d %s\n", bucket*step+start+1, (bucket+1)*step+start, count, strings.Repeat("#", percentage))
Expand Down
1 change: 1 addition & 0 deletions cmd/promtool/tsdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func getDumpedSamples(t *testing.T, path string, mint, maxt int64, match []strin
err := dumpSamples(
context.Background(),
path,
t.TempDir(),
mint,
maxt,
match,
Expand Down
2 changes: 1 addition & 1 deletion cmd/promtool/unittest.go
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ func (la labelsAndAnnotations) String() string {
}
s := "[\n0:" + indentLines("\n"+la[0].String(), " ")
for i, l := range la[1:] {
s += ",\n" + fmt.Sprintf("%d", i+1) + ":" + indentLines("\n"+l.String(), " ")
s += ",\n" + strconv.Itoa(i+1) + ":" + indentLines("\n"+l.String(), " ")
}
s += "\n]"

Expand Down
4 changes: 4 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ var (
ScrapeInterval: model.Duration(1 * time.Minute),
ScrapeTimeout: model.Duration(10 * time.Second),
EvaluationInterval: model.Duration(1 * time.Minute),
RuleQueryOffset: model.Duration(0 * time.Minute),
// When native histogram feature flag is enabled, ScrapeProtocols default
// changes to DefaultNativeHistogramScrapeProtocols.
ScrapeProtocols: DefaultScrapeProtocols,
Expand Down Expand Up @@ -397,6 +398,8 @@ type GlobalConfig struct {
ScrapeProtocols []ScrapeProtocol `yaml:"scrape_protocols,omitempty"`
// How frequently to evaluate rules by default.
EvaluationInterval model.Duration `yaml:"evaluation_interval,omitempty"`
// Offset the rule evaluation timestamp of this particular group by the specified duration into the past to ensure the underlying metrics have been received.
RuleQueryOffset model.Duration `yaml:"rule_query_offset"`
pracucci marked this conversation as resolved.
Show resolved Hide resolved
// File to which PromQL queries are logged.
QueryLogFile string `yaml:"query_log_file,omitempty"`
// The labels to add to any timeseries that this Prometheus instance scrapes.
Expand Down Expand Up @@ -556,6 +559,7 @@ func (c *GlobalConfig) isZero() bool {
c.ScrapeInterval == 0 &&
c.ScrapeTimeout == 0 &&
c.EvaluationInterval == 0 &&
c.RuleQueryOffset == 0 &&
c.QueryLogFile == "" &&
c.ScrapeProtocols == nil
}
Expand Down
3 changes: 2 additions & 1 deletion discovery/aws/ec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"errors"
"fmt"
"net"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -279,7 +280,7 @@ func (d *EC2Discovery) refresh(ctx context.Context) ([]*targetgroup.Group, error
if inst.PrivateDnsName != nil {
labels[ec2LabelPrivateDNS] = model.LabelValue(*inst.PrivateDnsName)
}
addr := net.JoinHostPort(*inst.PrivateIpAddress, fmt.Sprintf("%d", d.cfg.Port))
addr := net.JoinHostPort(*inst.PrivateIpAddress, strconv.Itoa(d.cfg.Port))
labels[model.AddressLabel] = model.LabelValue(addr)

if inst.Platform != nil {
Expand Down
3 changes: 2 additions & 1 deletion discovery/aws/lightsail.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"errors"
"fmt"
"net"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -229,7 +230,7 @@ func (d *LightsailDiscovery) refresh(ctx context.Context) ([]*targetgroup.Group,
lightsailLabelRegion: model.LabelValue(d.cfg.Region),
}

addr := net.JoinHostPort(*inst.PrivateIpAddress, fmt.Sprintf("%d", d.cfg.Port))
addr := net.JoinHostPort(*inst.PrivateIpAddress, strconv.Itoa(d.cfg.Port))
labels[model.AddressLabel] = model.LabelValue(addr)

if inst.PublicIpAddress != nil {
Expand Down
Loading
Loading