Skip to content

Commit d0d214c

Browse files
authored
Merge pull request #83 from guggero/lndclient-update
maintenance: Bump lnd and lndclient versions, use dockerized linter and formatter, use Golang 1.18
2 parents 082846f + aa8f3de commit d0d214c

File tree

19 files changed

+2206
-130
lines changed

19 files changed

+2206
-130
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ env:
1616
# go needs absolute directories, using the $HOME variable doesn't work here.
1717
GOCACHE: /home/runner/work/go/pkg/build
1818
GOPATH: /home/runner/work/go
19-
GO_VERSION: 1.16.8
19+
GO_VERSION: 1.18.4
2020

2121
jobs:
2222
########################

.golangci.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
run:
2+
# timeout for analysis
3+
deadline: 10m
4+
5+
linters-settings:
6+
govet:
7+
# Don't report about shadowed variables
8+
check-shadowing: false
9+
gofmt:
10+
# simplify code: gofmt with `-s` option, true by default
11+
simplify: true
12+
whitespace:
13+
multi-func: true
14+
multi-if: true
15+
16+
linters:
17+
enable:
18+
- gofmt
19+
- whitespace
20+
- asciicheck
21+
- bidichk
22+
- bodyclose
23+
- deadcode
24+
- decorder
25+
- depguard
26+
- dupl
27+
- durationcheck
28+
- errcheck
29+
- errchkjson
30+
- execinquery
31+
- exportloopref
32+
- goconst
33+
- gocritic
34+
- godot
35+
- goheader
36+
- goimports
37+
- gomodguard
38+
- goprintffuncname
39+
- gosec
40+
- gosimple
41+
- govet
42+
- grouper
43+
- importas
44+
- ineffassign
45+
- makezero
46+
- misspell
47+
- nakedret
48+
- nonamedreturns
49+
- nosprintfhostport
50+
- predeclared
51+
- revive
52+
- rowserrcheck
53+
- sqlclosecheck
54+
- staticcheck
55+
- structcheck
56+
- tagliatelle
57+
- tenv
58+
- typecheck
59+
- unconvert
60+
- unparam
61+
- unused
62+
- varcheck
63+
- wastedassign

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.14-alpine as builder
1+
FROM golang:1.18-alpine as builder
22

33
# Install build dependencies such as git and glide.
44
RUN apk add --no-cache git gcc musl-dev

Makefile

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
PKG := github.com/lightninglabs/lndmon
22
ESCPKG := github.com\/lightninglabs\/lndmon
3+
TOOLS_DIR := tools
34

45
LINT_PKG := github.com/golangci/golangci-lint/cmd/golangci-lint
6+
GOIMPORTS_PKG := github.com/rinchsan/gosimports/cmd/gosimports
57

68
GO_BIN := ${GOPATH}/bin
79
LINT_BIN := $(GO_BIN)/golangci-lint
810

9-
LINT_COMMIT := v1.18.0
10-
11-
DEPGET := cd /tmp && GO111MODULE=on go get -v
12-
GOBUILD := GO111MODULE=on go build -v
11+
GOBUILD := go build -v
1312

1413
GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*")
1514
GOLIST := go list -deps $(PKG)/... | grep '$(PKG)'| grep -v '/vendor/'
1615

1716
RM := rm -f
1817
CP := cp
1918
MAKE := make
19+
DOCKER_TOOLS = docker run -v $$(pwd):/build lndmon-tools
2020

2121
LINT = $(LINT_BIN) run -v
2222

@@ -28,9 +28,9 @@ all: lint build
2828
# DEPENDENCIES
2929
# ============
3030

31-
$(LINT_BIN):
32-
@$(call print, "Fetching linter")
33-
$(DEPGET) $(LINT_PKG)@$(LINT_COMMIT)
31+
goimports:
32+
@$(call print, "Installing goimports.")
33+
cd $(TOOLS_DIR); go install -trimpath -tags=tools $(GOIMPORTS_PKG)
3434

3535
# ============
3636
# INSTALLATION
@@ -43,13 +43,19 @@ build:
4343
# =========
4444
# UTILITIES
4545
# =========
46-
fmt:
46+
docker-tools:
47+
@$(call print, "Building tools docker image.")
48+
docker build -q -t lndmon-tools $(TOOLS_DIR)
49+
50+
fmt: goimports
51+
@$(call print, "Fixing imports.")
52+
gosimports -w $(GOFILES_NOVENDOR)
4753
@$(call print, "Formatting source.")
4854
gofmt -l -w -s $(GOFILES_NOVENDOR)
4955

50-
lint: $(LINT_BIN)
56+
lint: docker-tools
5157
@$(call print, "Linting source.")
52-
$(LINT)
58+
$(DOCKER_TOOLS) golangci-lint run -v $(LINT_WORKERS)
5359

5460
list:
5561
@$(call print, "Listing commands.")

cmd/lndmon/main.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package main
22

33
import (
44
"github.com/lightninglabs/lndmon"
5-
65
_ "github.com/lightninglabs/lndmon/collectors"
76
)
87

collectors/channel_collector_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package collectors
33
import (
44
"testing"
55

6-
"github.com/btcsuite/btcutil"
6+
"github.com/btcsuite/btcd/btcutil"
77
"github.com/lightninglabs/lndclient"
88
"github.com/stretchr/testify/require"
99
)

collectors/channels_collector.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import (
55
"fmt"
66
"strconv"
77

8-
"github.com/btcsuite/btcutil"
8+
"github.com/btcsuite/btcd/btcutil"
99
"github.com/lightninglabs/lndclient"
1010
"github.com/lightningnetwork/lnd/routing/route"
1111
"github.com/prometheus/client_golang/prometheus"
1212
)
1313

14-
// ChannelsCollector is a collector that keeps track of channel infromation.
14+
// ChannelsCollector is a collector that keeps track of channel information.
1515
type ChannelsCollector struct {
1616
channelBalanceDesc *prometheus.Desc
1717
pendingChannelBalanceDesc *prometheus.Desc
@@ -279,7 +279,7 @@ func (c *ChannelsCollector) Collect(ch chan<- prometheus.Metric) {
279279
initiator := initiatorLabel(channel)
280280
peer := channel.PubKeyBytes.String()
281281

282-
chanIdStr := strconv.Itoa(int(channel.ChannelID))
282+
chanIDStr := strconv.Itoa(int(channel.ChannelID))
283283

284284
primaryChannel := c.primaryNode != nil &&
285285
channel.PubKeyBytes == *c.primaryNode
@@ -292,57 +292,57 @@ func (c *ChannelsCollector) Collect(ch chan<- prometheus.Metric) {
292292

293293
ch <- prometheus.MustNewConstMetric(
294294
c.incomingChanSatDesc, prometheus.GaugeValue,
295-
float64(channel.RemoteBalance), chanIdStr, status,
295+
float64(channel.RemoteBalance), chanIDStr, status,
296296
initiator, peer,
297297
)
298298
ch <- prometheus.MustNewConstMetric(
299299
c.outgoingChanSatDesc, prometheus.GaugeValue,
300-
float64(channel.LocalBalance), chanIdStr, status,
300+
float64(channel.LocalBalance), chanIDStr, status,
301301
initiator, peer,
302302
)
303303
ch <- prometheus.MustNewConstMetric(
304304
c.numPendingHTLCsDesc, prometheus.GaugeValue,
305-
float64(channel.NumPendingHtlcs), chanIdStr, status,
305+
float64(channel.NumPendingHtlcs), chanIDStr, status,
306306
initiator, peer,
307307
)
308308
ch <- prometheus.MustNewConstMetric(
309309
c.satsSentDesc, prometheus.GaugeValue,
310-
float64(channel.TotalSent), chanIdStr, status,
310+
float64(channel.TotalSent), chanIDStr, status,
311311
initiator, peer,
312312
)
313313
ch <- prometheus.MustNewConstMetric(
314314
c.satsRecvDesc, prometheus.GaugeValue,
315-
float64(channel.TotalReceived), chanIdStr, status,
315+
float64(channel.TotalReceived), chanIDStr, status,
316316
initiator, peer,
317317
)
318318
ch <- prometheus.MustNewConstMetric(
319319
c.numUpdatesDesc, prometheus.GaugeValue,
320-
float64(channel.NumUpdates), chanIdStr, status,
320+
float64(channel.NumUpdates), chanIDStr, status,
321321
initiator, peer,
322322
)
323323
ch <- prometheus.MustNewConstMetric(
324324
c.csvDelayDesc, prometheus.GaugeValue,
325-
float64(channel.LocalConstraints.CsvDelay), chanIdStr,
325+
float64(channel.LocalConstraints.CsvDelay), chanIDStr,
326326
status, initiator, peer,
327327
)
328328
ch <- prometheus.MustNewConstMetric(
329329
c.unsettledBalanceDesc, prometheus.GaugeValue,
330-
float64(channel.UnsettledBalance), chanIdStr, status,
330+
float64(channel.UnsettledBalance), chanIDStr, status,
331331
initiator, peer,
332332
)
333333
ch <- prometheus.MustNewConstMetric(
334334
c.feePerKwDesc, prometheus.GaugeValue,
335-
float64(channel.FeePerKw), chanIdStr, status, initiator,
335+
float64(channel.FeePerKw), chanIDStr, status, initiator,
336336
peer,
337337
)
338338
ch <- prometheus.MustNewConstMetric(
339339
c.commitWeightDesc, prometheus.GaugeValue,
340-
float64(channel.CommitWeight), chanIdStr, status,
340+
float64(channel.CommitWeight), chanIDStr, status,
341341
initiator, peer,
342342
)
343343
ch <- prometheus.MustNewConstMetric(
344344
c.commitFeeDesc, prometheus.GaugeValue,
345-
float64(channel.CommitFee), chanIdStr, status,
345+
float64(channel.CommitFee), chanIDStr, status,
346346
initiator, peer,
347347
)
348348

@@ -351,7 +351,7 @@ func (c *ChannelsCollector) Collect(ch chan<- prometheus.Metric) {
351351
ch <- prometheus.MustNewConstMetric(
352352
c.channelUptimeDesc, prometheus.GaugeValue,
353353
float64(channel.Uptime)/float64(channel.LifeTime),
354-
chanIdStr, status, initiator, peer,
354+
chanIDStr, status, initiator, peer,
355355
)
356356
}
357357
}

collectors/graph_collector.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ func (g *GraphCollector) Collect(ch chan<- prometheus.Metric) {
316316

317317
ch <- prometheus.MustNewConstMetric(
318318
g.avgOutDegreeDesc, prometheus.GaugeValue,
319-
float64(networkInfo.AvgOutDegree),
319+
networkInfo.AvgOutDegree,
320320
)
321321
ch <- prometheus.MustNewConstMetric(
322322
g.maxOutDegreeDesc, prometheus.GaugeValue,

collectors/log.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ var (
2525
// initLogRotator initializes the logging rotator to write logs to logFile and
2626
// create roll files in the same directory. It must be called before the
2727
// package-global log rotator variables are used.
28-
func initLogRotator(logFile string, MaxLogFileSize int, MaxLogFiles int) error {
28+
func initLogRotator(logFile string, maxLogFileSize int, maxLogFiles int) error {
2929
logDir, _ := filepath.Split(logFile)
3030
err := os.MkdirAll(logDir, 0700)
3131
if err != nil {
3232
return fmt.Errorf("failed to create log directory: %v", err)
3333
}
3434

3535
r, err := rotator.New(
36-
logFile, int64(MaxLogFileSize*1024), false, MaxLogFiles,
36+
logFile, int64(maxLogFileSize*1024), false, maxLogFiles,
3737
)
3838
if err != nil {
3939
return fmt.Errorf("failed to create file rotator: %v", err)

collectors/prometheus.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"os"
88
"path/filepath"
99

10-
"github.com/btcsuite/btcutil"
10+
"github.com/btcsuite/btcd/btcutil"
1111
"github.com/lightninglabs/lndclient"
1212
"github.com/lightningnetwork/lnd/routing/route"
1313
"github.com/prometheus/client_golang/prometheus"

0 commit comments

Comments
 (0)