Skip to content

Commit 8d0288a

Browse files
authored
Merge branch 'main' into pmm-2.26.0
2 parents 6c79b52 + f6d864f commit 8d0288a

20 files changed

+737
-126
lines changed

.github/check-license.go

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -21,53 +21,61 @@
2121
package main
2222

2323
import (
24-
"bufio"
2524
"flag"
2625
"fmt"
2726
"io"
2827
"log"
2928
"os"
3029
"path/filepath"
3130
"regexp"
32-
"runtime"
3331
)
3432

35-
func getHeader() string {
36-
_, file, _, ok := runtime.Caller(0)
37-
if !ok {
38-
panic("runtime.Caller(0) failed")
39-
}
40-
f, err := os.Open(file)
41-
if err != nil {
42-
log.Fatal(err)
43-
}
44-
defer f.Close()
33+
var (
34+
generatedHeader = regexp.MustCompile(`^// Code generated .* DO NOT EDIT\.`)
4535

46-
var header string
47-
s := bufio.NewScanner(f)
48-
for s.Scan() {
49-
if s.Text() == "" {
50-
break
51-
}
52-
header += s.Text() + "\n"
53-
}
54-
header += "\n"
55-
if err := s.Err(); err != nil {
56-
log.Fatal(err)
57-
}
58-
return header
59-
}
36+
copyrightText = `// mongodb_exporter
37+
// Copyright (C) 2022 Percona LLC
38+
//
39+
// This program is free software: you can redistribute it and/or modify
40+
// it under the terms of the GNU Affero General Public License as published by
41+
// the Free Software Foundation, either version 3 of the License, or
42+
// (at your option) any later version.
43+
//
44+
// This program is distributed in the hope that it will be useful,
45+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
46+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
47+
// GNU Affero General Public License for more details.
48+
//
49+
// You should have received a copy of the GNU Affero General Public License
50+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
51+
`
6052

61-
var generatedHeader = regexp.MustCompile(`^// Code generated .* DO NOT EDIT\.`)
53+
copyrightPattern = regexp.MustCompile(`^// mongodb_exporter
54+
// Copyright \(C\) 20\d{2} Percona LLC
55+
//
56+
// This program is free software: you can redistribute it and/or modify
57+
// it under the terms of the GNU Affero General Public License as published by
58+
// the Free Software Foundation, either version 3 of the License, or
59+
// \(at your option\) any later version.
60+
//
61+
// This program is distributed in the hope that it will be useful,
62+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
63+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
64+
// GNU Affero General Public License for more details.
65+
//
66+
// You should have received a copy of the GNU Affero General Public License
67+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
68+
`)
69+
)
6270

63-
func checkHeader(path string, header string) bool {
71+
func checkHeader(path string) bool {
6472
f, err := os.Open(path)
6573
if err != nil {
6674
log.Fatal(err)
6775
}
6876
defer f.Close()
6977

70-
actual := make([]byte, len(header))
78+
actual := make([]byte, len(copyrightText))
7179
_, err = io.ReadFull(f, actual)
7280
if err == io.ErrUnexpectedEOF {
7381
err = nil // some files are shorter than license header
@@ -81,7 +89,7 @@ func checkHeader(path string, header string) bool {
8189
return true
8290
}
8391

84-
if header != string(actual) {
92+
if !copyrightPattern.Match(actual) {
8593
log.Print(path)
8694
return false
8795
}
@@ -96,8 +104,6 @@ func main() {
96104
}
97105
flag.Parse()
98106

99-
header := getHeader()
100-
101107
ok := true
102108
filepath.Walk(".", func(path string, info os.FileInfo, err error) error {
103109
if err != nil {
@@ -113,7 +119,7 @@ func main() {
113119
}
114120

115121
if filepath.Ext(info.Name()) == ".go" {
116-
if !checkHeader(path, header) {
122+
if !checkHeader(path) {
117123
ok = false
118124
}
119125
}

.github/workflows/go.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,4 @@ jobs:
8383
# use GITHUB_TOKEN because only it has access to GitHub Checks API
8484
bin/golangci-lint run -c=.golangci-required.yml --out-format=line-number | env REVIEWDOG_GITHUB_API_TOKEN=${{ secrets.GITHUB_TOKEN }} bin/reviewdog -f=golangci-lint -level=error -reporter=github-pr-check
8585
bin/golangci-lint run -c=.golangci.yml --out-format=line-number | env REVIEWDOG_GITHUB_API_TOKEN=${{ secrets.GITHUB_TOKEN }} bin/reviewdog -f=golangci-lint -level=error -reporter=github-pr-review
86+
make check-license

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ bin
66
build
77
dist
88
mongodb_exporter
9+
vendor

exporter/common.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
// mongodb_exporter
2+
// Copyright (C) 2022 Percona LLC
3+
//
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU Affero General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU Affero General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU Affero General Public License
15+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
117
package exporter
218

319
import (
@@ -151,6 +167,12 @@ func listAllCollections(ctx context.Context, client *mongo.Client, filterInNames
151167
filterNS = append(filterNS, dbs...)
152168
}
153169

170+
for _, db := range dbs {
171+
for _, namespace := range filterNS {
172+
parts := strings.Split(namespace, ".")
173+
dbname := strings.TrimSpace(parts[0])
174+
175+
154176
for _, db := range dbs {
155177
for _, namespace := range filterNS {
156178
parts := strings.Split(namespace, ".")

exporter/common_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
// mongodb_exporter
2+
// Copyright (C) 2022 Percona LLC
3+
//
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU Affero General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU Affero General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU Affero General Public License
15+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
117
package exporter
218

319
import (

exporter/debug.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
// mongodb_exporter
2+
// Copyright (C) 2022 Percona LLC
3+
//
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU Affero General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU Affero General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU Affero General Public License
15+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
117
package exporter
218

319
import (

exporter/debug_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
// mongodb_exporter
2+
// Copyright (C) 2022 Percona LLC
3+
//
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU Affero General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU Affero General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU Affero General Public License
15+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
117
package exporter
218

319
import (

exporter/exporter.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ import (
2121
"context"
2222
"fmt"
2323
"net/http"
24+
"os"
2425
"sync"
2526
"time"
2627

27-
"github.com/percona/exporter_shared"
2828
"github.com/prometheus/client_golang/prometheus"
2929
"github.com/prometheus/client_golang/prometheus/promhttp"
30+
"github.com/prometheus/common/promlog"
31+
"github.com/prometheus/exporter-toolkit/web"
3032
"github.com/sirupsen/logrus"
3133
"go.mongodb.org/mongo-driver/mongo"
3234
"go.mongodb.org/mongo-driver/mongo/options"
@@ -325,8 +327,16 @@ func (e *Exporter) Handler() http.Handler {
325327

326328
// Run starts the exporter.
327329
func (e *Exporter) Run() {
328-
handler := e.Handler()
329-
exporter_shared.RunServer("MongoDB", e.webListenAddress, e.path, handler)
330+
server := &http.Server{
331+
Addr: e.webListenAddress,
332+
Handler: e.Handler(),
333+
}
334+
335+
// TODO: tls, basic auth support, etc.
336+
if err := web.ListenAndServe(server, "", promlog.New(&promlog.Config{})); err != nil {
337+
e.logger.Errorf("error starting server: %v", err)
338+
os.Exit(1)
339+
}
330340
}
331341

332342
func connect(ctx context.Context, dsn string, directConnect bool) (*mongo.Client, error) {

exporter/secondary_lag_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
// mongodb_exporter
2+
// Copyright (C) 2022 Percona LLC
3+
//
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU Affero General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU Affero General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU Affero General Public License
15+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
117
package exporter
218

319
import (

exporter/utils_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
// mongodb_exporter
2+
// Copyright (C) 2022 Percona LLC
3+
//
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU Affero General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU Affero General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU Affero General Public License
15+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
117
package exporter
218

319
import (

0 commit comments

Comments
 (0)