Skip to content

Commit 99f2870

Browse files
authored
Merge pull request #61 from fly-apps/lint
Adds workflow that runs linter
2 parents efb4a5d + 77aafea commit 99f2870

File tree

24 files changed

+215
-78
lines changed

24 files changed

+215
-78
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,4 @@ jobs:
6666
run: echo ${{ steps.docker_build_14.outputs.digest }}
6767
-
6868
name: Postgres 15 Image digest
69-
run: echo ${{ steps.docker_build_15.outputs.digest }}
69+
run: echo ${{ steps.docker_build_15.outputs.digest }}

.github/workflows/pre-commit.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: pre-commit
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [master]
7+
8+
jobs:
9+
lint:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v3
13+
- uses: actions/setup-go@v3
14+
with:
15+
go-version-file: "go.mod"
16+
- uses: pre-commit/[email protected]
17+
with:
18+
extra_args: --all-files --hook-stage=manual
19+
- uses: golangci/golangci-lint-action@master
20+
with:
21+
version: v1.49.0
22+
- run: go mod download

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
.idea/
1+
.idea/

.golangci.yml

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
issues:
2+
# List of regexps of issue texts to exclude, empty list by default.
3+
# But independently from this option we use default exclude patterns,
4+
# it can be disabled by `exclude-use-default: false`. To list all
5+
# excluded by default patterns execute `golangci-lint run --help`
6+
7+
exclude-rules:
8+
# Exclude gosimple bool check
9+
- linters:
10+
- gosimple
11+
text: "S(1002|1008|1021)"
12+
# Exclude failing staticchecks for now
13+
- linters:
14+
- staticcheck
15+
text: "SA(1006|1019|4006|4010|4017|5007|6005|9004):"
16+
# Exclude lll issues for long lines with go:generate
17+
- linters:
18+
- lll
19+
source: "^//go:generate "
20+
21+
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
22+
max-issues-per-linter: 0
23+
24+
# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
25+
max-same-issues: 0
26+
27+
linters:
28+
disable-all: true
29+
enable:
30+
# - gofumpt
31+
# - goimports
32+
- gosimple
33+
- govet
34+
- ineffassign
35+
- staticcheck
36+
- unconvert
37+
- unused
38+
fast: true
39+
40+
# options for analysis running
41+
run:
42+
go: "1.19"
43+
44+
# default concurrency is a available CPU number
45+
concurrency: 4
46+
47+
# timeout for analysis, e.g. 30s, 5m, default is 1m
48+
timeout: 10m
49+
50+
# exit code when at least one issue was found, default is 1
51+
issues-exit-code: 1
52+
53+
# include test files or not, default is true
54+
tests: true
55+
56+
# list of build tags, all linters use it. Default is empty list.
57+
#build-tags:
58+
# - mytag
59+
60+
# which dirs to skip: issues from them won't be reported;
61+
# can use regexp here: generated.*, regexp is applied on full path;
62+
# default value is empty list, but default dirs are skipped independently
63+
# from this option's value (see skip-dirs-use-default).
64+
#skip-dirs:
65+
# - src/external_libs
66+
# - autogenerated_by_my_lib
67+
68+
# default is true. Enables skipping of directories:
69+
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
70+
skip-dirs-use-default: true
71+
72+
# which files to skip: they will be analyzed, but issues from them
73+
# won't be reported. Default value is empty list, but there is
74+
# no need to include all autogenerated files, we confidently recognize
75+
# autogenerated files. If it's not please let us know.
76+
skip-files:
77+
- ".*\\.hcl2spec\\.go$"
78+
- "docstrings/gen.go"
79+
# - lib/bad.go
80+
81+
# by default isn't set. If set we pass it to "go list -mod={option}". From "go help modules":
82+
# If invoked with -mod=readonly, the go command is disallowed from the implicit
83+
# automatic updating of go.mod described above. Instead, it fails when any changes
84+
# to go.mod are needed. This setting is most useful to check that go.mod does
85+
# not need updates, such as in a continuous integration and testing system.
86+
# If invoked with -mod=vendor, the go command assumes that the vendor
87+
# directory holds the correct copies of dependencies and ignores
88+
# the dependency descriptions in go.mod.
89+
# modules-download-mode: vendor
90+
91+
# output configuration options
92+
output:
93+
# colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number"
94+
format: colored-line-number
95+
96+
# print lines of code with issue, default is true
97+
print-issued-lines: true
98+
99+
# print linter name in the end of issue text, default is true
100+
print-linter-name: true
101+
102+
# make issues output unique by line, default is true
103+
uniq-by-line: true
104+
105+
# all available settings of specific linters
106+
linters-settings:
107+
gofumpt:
108+
module-path: github.com/fly-apps/postgres-flex
109+
errcheck:
110+
# report about not checking of errors in type assetions: `a := b.(MyStruct)`;
111+
# default is false: such cases aren't reported by default.
112+
check-type-assertions: false
113+
114+
# report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`;
115+
# default is false: such cases aren't reported by default.
116+
check-blank: false
117+
118+
# [deprecated] comma-separated list of pairs of the form pkg:regex
119+
# the regex is used to ignore names within pkg. (default "fmt:.*").
120+
# see https://github.com/kisielk/errcheck#the-deprecated-method for details
121+
ignore: fmt:.*,io/ioutil:^Read.*,io:Close
122+
123+
# path to a file containing a list of functions to exclude from checking
124+
# see https://github.com/kisielk/errcheck#excluding-functions for details
125+
#exclude: /path/to/file.txt

.pre-commit-config.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# See https://pre-commit.com for more information
2+
# See https://pre-commit.com/hooks.html for more hooks
3+
repos:
4+
- repo: https://github.com/pre-commit/pre-commit-hooks
5+
rev: v4.3.0
6+
hooks:
7+
- id: trailing-whitespace
8+
- id: end-of-file-fixer
9+
- id: check-yaml
10+
- id: check-added-large-files
11+
- repo: https://github.com/golangci/golangci-lint
12+
rev: v1.50.0
13+
hooks:
14+
- id: golangci-lint
15+
# pre-commit github action runs as "manual" hook
16+
# because golangci-lint's action is more useful than
17+
# the pre-commit hook in that case
18+
stages: [commit]

Dockerfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ FROM wrouesnel/postgres_exporter:latest AS postgres_exporter
1919

2020
FROM postgres:${PG_VERSION}
2121
ENV PGDATA=/data/postgresql
22-
ARG VERSION
22+
ARG VERSION
2323
ARG PG_MAJOR_VERSION
2424

2525
LABEL fly.app_role=postgres_cluster
@@ -42,4 +42,3 @@ EXPOSE 5432
4242

4343

4444
CMD ["start"]
45-

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ To get started, run the following:
1111
fly version update
1212

1313
# Provision a 3 member cluster
14-
fly pg create --name <app-name> --initial-cluster-size 3 --region ord --repmgr
14+
fly pg create --name <app-name> --initial-cluster-size 3 --region ord --repmgr
1515
```
1616

1717
## High Availability
18-
To ensure High Availability, it's recommended that your cluster has at least 3 members.
18+
To ensure High Availability, it's recommended that your cluster has at least 3 members.
1919

20-
Automatic failovers will only consider members residing within your primary region. The primary region is represented as an environment variable defined within the `fly.toml` file. That being said, if you're running a 3 member setup at least 2 of the members should reside within your primary region.
20+
Automatic failovers will only consider members residing within your primary region. The primary region is represented as an environment variable defined within the `fly.toml` file. That being said, if you're running a 3 member setup at least 2 of the members should reside within your primary region.
2121

2222
## Horizontal scaling
2323
Use the clone command to scale up your cluster.
@@ -30,7 +30,7 @@ fly machines clone <machine-id> --region <target-region>
3030
```
3131

3232
## Staying up-to-date!
33-
This project is in active development so it's important to stay current with the latest changes and bug fixes.
33+
This project is in active development so it's important to stay current with the latest changes and bug fixes.
3434

3535
```
3636
# Use the following command to verify you're on the latest version.
@@ -46,4 +46,3 @@ Create an issue or ask a question here: https://community.fly.io/
4646

4747
## Contributing
4848
If you're looking to get involved, fork the project and send pull requests.
49-

cmd/event_handler/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func main() {
7373
success := false
7474

7575
for retry < maxRetries {
76-
if err := reconfigurePGBouncer(*&newMemberID); err != nil {
76+
if err := reconfigurePGBouncer(newMemberID); err != nil {
7777
log.Printf("%s - failed to reconfigure pgbouncer: %s. (attempt: %d)\n", *event, err, retry)
7878
retry++
7979
time.Sleep(1 * time.Second)

cmd/standby_cleaner/main.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,9 @@ func main() {
5252

5353
fmt.Printf("Pruning every %s...\n", deadMemberRemovalThreshold)
5454

55-
for {
56-
select {
57-
case <-ticker.C:
58-
if err := handleTick(ctx, flypgNode, seenAt, deadMemberRemovalThreshold); err != nil {
59-
fmt.Println(err)
60-
}
55+
for range ticker.C {
56+
if err := handleTick(ctx, flypgNode, seenAt, deadMemberRemovalThreshold); err != nil {
57+
fmt.Println(err)
6158
}
6259
}
6360
}
@@ -91,7 +88,7 @@ func handleTick(ctx context.Context, node *flypg.Node, seenAt map[int]time.Time,
9188
sConn, err := node.RepMgr.NewRemoteConnection(ctx, standby.Hostname)
9289
if err != nil {
9390
// TODO - Verify the exception that's getting thrown.
94-
if time.Now().Sub(seenAt[standby.ID]) >= deadMemberRemovalThreshold {
91+
if time.Since(seenAt[standby.ID]) >= deadMemberRemovalThreshold {
9592
if err := node.RepMgr.UnregisterMember(ctx, standby); err != nil {
9693
fmt.Printf("failed to unregister member %s: %v", standby.Hostname, err)
9794
continue

config/queries.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ pg_database:
88
description: "Name of the database"
99
- size_bytes:
1010
usage: "GAUGE"
11-
description: "Disk space used by the database"
11+
description: "Disk space used by the database"

0 commit comments

Comments
 (0)