Skip to content

Commit 2bfbb14

Browse files
committed
Initial commit
0 parents  commit 2bfbb14

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+13543
-0
lines changed

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

.github/CODEOWNERS

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @percona/pmm-review-exporters

.github/ISSUE_TEMPLATE/bug_report.md

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve the exporter
4+
title: ''
5+
labels: ["community", "bug", "triage"]
6+
assignees: ''
7+
8+
---
9+
10+
**Describe the bug**
11+
A clear and concise description of what the bug is.
12+
If the issue relates to PMM, please open [JIRA PMM](https://jira.percona.com/projects/PMM/issues) issue instead of GH issue.
13+
14+
**To Reproduce**
15+
Steps to reproduce the behavior:
16+
1. what parameters are being passed to `mongodb_exporter`
17+
2. describe steps to reproduce the issue
18+
19+
**Expected behavior**
20+
A clear and concise description of what you expected to happen.
21+
22+
**Logs**
23+
Please provide logs relevant to the issue
24+
25+
**Environment**
26+
- OS,
27+
- environment (docker, k8s, etc)
28+
- MongoDB version
29+
30+
**Additional context**
31+
Add any other context about the problem here.
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
title: ''
5+
labels: ["community", "enhancement", "triage"]
6+
assignees: ''
7+
8+
---
9+
10+
**Is your feature request related to a problem? Please describe.**
11+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12+
If the improvement is related to PMM, please open [PMM project](https://jira.percona.com/projects/PMM/issues) feature instead of GH feature request.
13+
14+
**Describe the solution you'd like**
15+
A clear and concise description of what you expect to happen.
16+
17+
**Describe alternatives you've considered**
18+
A clear and concise description of any alternative solutions or features you've considered.
19+
20+
**Additional context**
21+
Add any other context or screenshots related to the feature request here.

.github/check-license.go

+134
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
// mongodb_exporter
2+
// Copyright (C) 2017 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+
17+
//go:build ignore
18+
// +build ignore
19+
20+
// check-license checks that AGPL license header in all files matches header in this file.
21+
package main
22+
23+
import (
24+
"flag"
25+
"fmt"
26+
"io"
27+
"log"
28+
"os"
29+
"path/filepath"
30+
"regexp"
31+
)
32+
33+
var (
34+
generatedHeader = regexp.MustCompile(`^// Code generated .* DO NOT EDIT\.`)
35+
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+
`
52+
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+
)
70+
71+
func checkHeader(path string) bool {
72+
f, err := os.Open(path)
73+
if err != nil {
74+
log.Fatal(err)
75+
}
76+
defer f.Close()
77+
78+
actual := make([]byte, len(copyrightText))
79+
_, err = io.ReadFull(f, actual)
80+
if err == io.ErrUnexpectedEOF {
81+
err = nil // some files are shorter than license header
82+
}
83+
if err != nil {
84+
log.Printf("%s - %s", path, err)
85+
return false
86+
}
87+
88+
if generatedHeader.Match(actual) {
89+
return true
90+
}
91+
92+
if !copyrightPattern.Match(actual) {
93+
log.Print(path)
94+
return false
95+
}
96+
return true
97+
}
98+
99+
func main() {
100+
log.SetFlags(0)
101+
flag.Usage = func() {
102+
fmt.Fprintln(flag.CommandLine.Output(), "Usage: go run .github/check-license.go")
103+
flag.CommandLine.PrintDefaults()
104+
}
105+
flag.Parse()
106+
107+
ok := true
108+
filepath.Walk(".", func(path string, info os.FileInfo, err error) error {
109+
if err != nil {
110+
return err
111+
}
112+
if info.IsDir() {
113+
switch info.Name() {
114+
case ".git", "vendor":
115+
return filepath.SkipDir
116+
default:
117+
return nil
118+
}
119+
}
120+
121+
if filepath.Ext(info.Name()) == ".go" {
122+
if !checkHeader(path) {
123+
ok = false
124+
}
125+
}
126+
return nil
127+
})
128+
129+
if ok {
130+
os.Exit(0)
131+
}
132+
log.Print("Please update license header in those files.")
133+
os.Exit(1)
134+
}

.github/dependabot.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
version: 2
3+
updates:
4+
- package-ecosystem: "gomod"
5+
directory: "/"
6+
schedule:
7+
interval: "weekly"
8+
- package-ecosystem: "gomod"
9+
directory: "/tools"
10+
schedule:
11+
interval: "weekly"
12+
- package-ecosystem: "docker"
13+
directory: "/"
14+
schedule:
15+
interval: "weekly"
16+
- package-ecosystem: "github-actions"
17+
directory: "/"
18+
schedule:
19+
interval: "weekly"

.github/pull_request_template.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[PMM-XXXX](https://jira.percona.com/browse/PMM-XXXX) (optional, if ticket reported)
2+
3+
- [ ] Links to other linked pull requests (optional).
4+
5+
---
6+
7+
- [ ] Tests passed.
8+
- [ ] Fix conflicts with target branch.
9+
- [ ] Update jira ticket description if needed.
10+
- [ ] Attach screenshots/console output to confirm new behavior to jira ticket, if applicable.
11+
12+
Once all checks pass and the code is ready for review, please add `pmm-review-exporters` team as the reviewer. That would assign people from the review team automatically. Report any issues on our [Forum](https://forums.percona.com).

.github/workflows/go.yml

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: Go
2+
3+
on:
4+
schedule:
5+
# run every Sunday
6+
- cron: '0 13 * * 0'
7+
push:
8+
branches:
9+
- main
10+
- release-0.1x
11+
tags:
12+
- v[0-9]+.[0-9]+.[0-9]+*
13+
pull_request:
14+
15+
jobs:
16+
build:
17+
name: Build
18+
19+
strategy:
20+
fail-fast: false
21+
matrix:
22+
go-version:
23+
- 1.19.x
24+
image:
25+
- mongo:4.2
26+
- mongo:4.4
27+
- mongo:5.0
28+
- percona/percona-server-mongodb:4.2
29+
- percona/percona-server-mongodb:4.4
30+
- percona/percona-server-mongodb:5.0
31+
os: [ubuntu-latest]
32+
may-fail: [false]
33+
34+
include:
35+
# test only one image on tip to detect major Go changes earlier
36+
# without wasting too much time on CI
37+
- go-version: tip
38+
image: mongo:4.4
39+
os: ubuntu-latest
40+
may-fail: true
41+
42+
continue-on-error: ${{ matrix.may-fail }}
43+
runs-on: ${{ matrix.os }}
44+
45+
steps:
46+
- name: Set up Go release
47+
if: matrix.go-version != 'tip'
48+
uses: actions/setup-go@v4
49+
with:
50+
go-version: ${{ matrix.go-version }}
51+
52+
- name: Set up Go tip
53+
if: matrix.go-version == 'tip'
54+
run: |
55+
git clone --depth=1 https://go.googlesource.com/go $HOME/gotip
56+
cd $HOME/gotip/src
57+
./make.bash
58+
echo "GOROOT=$HOME/gotip" >> $GITHUB_ENV
59+
echo "$HOME/gotip/bin" >> $GITHUB_PATH
60+
61+
- name: Check out code into the Go module directory
62+
uses: actions/checkout@v3
63+
64+
- name: Initialize dependencies and linters
65+
run: |
66+
make init
67+
68+
- name: Diff
69+
if: startsWith( ${{ matrix.go-version }}, '1.17')
70+
run: |
71+
make format
72+
git diff --exit-code
73+
74+
- name: Test
75+
run: |
76+
TEST_MONGODB_IMAGE=${{ matrix.image }} make test-cluster
77+
make test-race
78+
make test-cluster-clean
79+
80+
- name: Run checks/linters
81+
run: |
82+
# use GITHUB_TOKEN because only it has access to GitHub Checks API
83+
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
84+
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
85+
make check-license

.github/workflows/release.yml

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: goreleaser
2+
3+
on:
4+
push:
5+
# run when new tag is pushed
6+
tags:
7+
- v*
8+
# manually trigger the release
9+
workflow_dispatch:
10+
11+
jobs:
12+
goreleaser:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v3
17+
with:
18+
fetch-depth: 0
19+
20+
- name: Set up Go
21+
uses: actions/setup-go@v4
22+
with:
23+
go-version: 1.19
24+
25+
- name: Login to Docker Hub
26+
uses: docker/login-action@v2
27+
with:
28+
username: ${{ secrets.DOCKERHUB_USERNAME }}
29+
password: ${{ secrets.DOCKERHUB_TOKEN }}
30+
31+
- name: Login to GitHub Container Registry
32+
uses: docker/login-action@v2
33+
with:
34+
registry: ghcr.io
35+
username: ${{ github.actor }}
36+
password: ${{ secrets.GITHUB_TOKEN }}
37+
38+
- name: Set up QEMU
39+
uses: docker/setup-qemu-action@v2
40+
41+
- name: Set up Docker Buildx
42+
id: buildx
43+
uses: docker/setup-buildx-action@v2
44+
45+
- name: Run GoReleaser
46+
uses: goreleaser/goreleaser-action@v3
47+
with:
48+
version: latest
49+
args: release --rm-dist
50+
env:
51+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.dist
2+
.env
3+
.vscode/
4+
.idea
5+
bin
6+
build
7+
dist
8+
mongodb_exporter
9+
.DS_Store

.golangci-required.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
# The most valuable linters; they are required to pass for PR to be merged.
3+
linters:
4+
disable-all: true
5+
enable:
6+
- depguard
7+
- goimports
8+
- ineffassign
9+
- govet
10+
- staticcheck
11+
12+
issues:
13+
exclude-use-default: false

0 commit comments

Comments
 (0)