Skip to content

Commit

Permalink
Merge pull request #83 from guggero/lndclient-update
Browse files Browse the repository at this point in the history
maintenance: Bump lnd and lndclient versions, use dockerized linter and formatter, use Golang 1.18
  • Loading branch information
guggero authored Aug 2, 2022
2 parents 082846f + aa8f3de commit d0d214c
Show file tree
Hide file tree
Showing 19 changed files with 2,206 additions and 130 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ env:
# go needs absolute directories, using the $HOME variable doesn't work here.
GOCACHE: /home/runner/work/go/pkg/build
GOPATH: /home/runner/work/go
GO_VERSION: 1.16.8
GO_VERSION: 1.18.4

jobs:
########################
Expand Down
63 changes: 63 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
run:
# timeout for analysis
deadline: 10m

linters-settings:
govet:
# Don't report about shadowed variables
check-shadowing: false
gofmt:
# simplify code: gofmt with `-s` option, true by default
simplify: true
whitespace:
multi-func: true
multi-if: true

linters:
enable:
- gofmt
- whitespace
- asciicheck
- bidichk
- bodyclose
- deadcode
- decorder
- depguard
- dupl
- durationcheck
- errcheck
- errchkjson
- execinquery
- exportloopref
- goconst
- gocritic
- godot
- goheader
- goimports
- gomodguard
- goprintffuncname
- gosec
- gosimple
- govet
- grouper
- importas
- ineffassign
- makezero
- misspell
- nakedret
- nonamedreturns
- nosprintfhostport
- predeclared
- revive
- rowserrcheck
- sqlclosecheck
- staticcheck
- structcheck
- tagliatelle
- tenv
- typecheck
- unconvert
- unparam
- unused
- varcheck
- wastedassign
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.14-alpine as builder
FROM golang:1.18-alpine as builder

# Install build dependencies such as git and glide.
RUN apk add --no-cache git gcc musl-dev
Expand Down
26 changes: 16 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
PKG := github.com/lightninglabs/lndmon
ESCPKG := github.com\/lightninglabs\/lndmon
TOOLS_DIR := tools

LINT_PKG := github.com/golangci/golangci-lint/cmd/golangci-lint
GOIMPORTS_PKG := github.com/rinchsan/gosimports/cmd/gosimports

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

LINT_COMMIT := v1.18.0

DEPGET := cd /tmp && GO111MODULE=on go get -v
GOBUILD := GO111MODULE=on go build -v
GOBUILD := go build -v

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

RM := rm -f
CP := cp
MAKE := make
DOCKER_TOOLS = docker run -v $$(pwd):/build lndmon-tools

LINT = $(LINT_BIN) run -v

Expand All @@ -28,9 +28,9 @@ all: lint build
# DEPENDENCIES
# ============

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

# ============
# INSTALLATION
Expand All @@ -43,13 +43,19 @@ build:
# =========
# UTILITIES
# =========
fmt:
docker-tools:
@$(call print, "Building tools docker image.")
docker build -q -t lndmon-tools $(TOOLS_DIR)

fmt: goimports
@$(call print, "Fixing imports.")
gosimports -w $(GOFILES_NOVENDOR)
@$(call print, "Formatting source.")
gofmt -l -w -s $(GOFILES_NOVENDOR)

lint: $(LINT_BIN)
lint: docker-tools
@$(call print, "Linting source.")
$(LINT)
$(DOCKER_TOOLS) golangci-lint run -v $(LINT_WORKERS)

list:
@$(call print, "Listing commands.")
Expand Down
1 change: 0 additions & 1 deletion cmd/lndmon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"github.com/lightninglabs/lndmon"

_ "github.com/lightninglabs/lndmon/collectors"
)

Expand Down
2 changes: 1 addition & 1 deletion collectors/channel_collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package collectors
import (
"testing"

"github.com/btcsuite/btcutil"
"github.com/btcsuite/btcd/btcutil"
"github.com/lightninglabs/lndclient"
"github.com/stretchr/testify/require"
)
Expand Down
30 changes: 15 additions & 15 deletions collectors/channels_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import (
"fmt"
"strconv"

"github.com/btcsuite/btcutil"
"github.com/btcsuite/btcd/btcutil"
"github.com/lightninglabs/lndclient"
"github.com/lightningnetwork/lnd/routing/route"
"github.com/prometheus/client_golang/prometheus"
)

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

chanIdStr := strconv.Itoa(int(channel.ChannelID))
chanIDStr := strconv.Itoa(int(channel.ChannelID))

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

ch <- prometheus.MustNewConstMetric(
c.incomingChanSatDesc, prometheus.GaugeValue,
float64(channel.RemoteBalance), chanIdStr, status,
float64(channel.RemoteBalance), chanIDStr, status,
initiator, peer,
)
ch <- prometheus.MustNewConstMetric(
c.outgoingChanSatDesc, prometheus.GaugeValue,
float64(channel.LocalBalance), chanIdStr, status,
float64(channel.LocalBalance), chanIDStr, status,
initiator, peer,
)
ch <- prometheus.MustNewConstMetric(
c.numPendingHTLCsDesc, prometheus.GaugeValue,
float64(channel.NumPendingHtlcs), chanIdStr, status,
float64(channel.NumPendingHtlcs), chanIDStr, status,
initiator, peer,
)
ch <- prometheus.MustNewConstMetric(
c.satsSentDesc, prometheus.GaugeValue,
float64(channel.TotalSent), chanIdStr, status,
float64(channel.TotalSent), chanIDStr, status,
initiator, peer,
)
ch <- prometheus.MustNewConstMetric(
c.satsRecvDesc, prometheus.GaugeValue,
float64(channel.TotalReceived), chanIdStr, status,
float64(channel.TotalReceived), chanIDStr, status,
initiator, peer,
)
ch <- prometheus.MustNewConstMetric(
c.numUpdatesDesc, prometheus.GaugeValue,
float64(channel.NumUpdates), chanIdStr, status,
float64(channel.NumUpdates), chanIDStr, status,
initiator, peer,
)
ch <- prometheus.MustNewConstMetric(
c.csvDelayDesc, prometheus.GaugeValue,
float64(channel.LocalConstraints.CsvDelay), chanIdStr,
float64(channel.LocalConstraints.CsvDelay), chanIDStr,
status, initiator, peer,
)
ch <- prometheus.MustNewConstMetric(
c.unsettledBalanceDesc, prometheus.GaugeValue,
float64(channel.UnsettledBalance), chanIdStr, status,
float64(channel.UnsettledBalance), chanIDStr, status,
initiator, peer,
)
ch <- prometheus.MustNewConstMetric(
c.feePerKwDesc, prometheus.GaugeValue,
float64(channel.FeePerKw), chanIdStr, status, initiator,
float64(channel.FeePerKw), chanIDStr, status, initiator,
peer,
)
ch <- prometheus.MustNewConstMetric(
c.commitWeightDesc, prometheus.GaugeValue,
float64(channel.CommitWeight), chanIdStr, status,
float64(channel.CommitWeight), chanIDStr, status,
initiator, peer,
)
ch <- prometheus.MustNewConstMetric(
c.commitFeeDesc, prometheus.GaugeValue,
float64(channel.CommitFee), chanIdStr, status,
float64(channel.CommitFee), chanIDStr, status,
initiator, peer,
)

Expand All @@ -351,7 +351,7 @@ func (c *ChannelsCollector) Collect(ch chan<- prometheus.Metric) {
ch <- prometheus.MustNewConstMetric(
c.channelUptimeDesc, prometheus.GaugeValue,
float64(channel.Uptime)/float64(channel.LifeTime),
chanIdStr, status, initiator, peer,
chanIDStr, status, initiator, peer,
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion collectors/graph_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ func (g *GraphCollector) Collect(ch chan<- prometheus.Metric) {

ch <- prometheus.MustNewConstMetric(
g.avgOutDegreeDesc, prometheus.GaugeValue,
float64(networkInfo.AvgOutDegree),
networkInfo.AvgOutDegree,
)
ch <- prometheus.MustNewConstMetric(
g.maxOutDegreeDesc, prometheus.GaugeValue,
Expand Down
4 changes: 2 additions & 2 deletions collectors/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ var (
// initLogRotator initializes the logging rotator to write logs to logFile and
// create roll files in the same directory. It must be called before the
// package-global log rotator variables are used.
func initLogRotator(logFile string, MaxLogFileSize int, MaxLogFiles int) error {
func initLogRotator(logFile string, maxLogFileSize int, maxLogFiles int) error {
logDir, _ := filepath.Split(logFile)
err := os.MkdirAll(logDir, 0700)
if err != nil {
return fmt.Errorf("failed to create log directory: %v", err)
}

r, err := rotator.New(
logFile, int64(MaxLogFileSize*1024), false, MaxLogFiles,
logFile, int64(maxLogFileSize*1024), false, maxLogFiles,
)
if err != nil {
return fmt.Errorf("failed to create file rotator: %v", err)
Expand Down
2 changes: 1 addition & 1 deletion collectors/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"os"
"path/filepath"

"github.com/btcsuite/btcutil"
"github.com/btcsuite/btcd/btcutil"
"github.com/lightninglabs/lndclient"
"github.com/lightningnetwork/lnd/routing/route"
"github.com/prometheus/client_golang/prometheus"
Expand Down
1 change: 0 additions & 1 deletion collectors/stats_compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ func newStatsCompiler(numSamples uint32) statsCompiler {

// Observe logs a new value in the set of existing samples.
func (s *statsCompiler) Observe(value float64) {

// First, we'll update our min/max, if needed.
if value > s.max {
s.max = value
Expand Down
4 changes: 2 additions & 2 deletions collectors/wallet_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"math"

"github.com/btcsuite/btcutil"
"github.com/btcsuite/btcd/btcutil"
"github.com/lightninglabs/lndclient"
"github.com/prometheus/client_golang/prometheus"
)
Expand Down Expand Up @@ -164,7 +164,7 @@ func (u *WalletCollector) Collect(ch chan<- prometheus.Metric) {
)

ch <- prometheus.MustNewConstMetric(
u.avgUtxoSizeDesc, prometheus.GaugeValue, float64(avg),
u.avgUtxoSizeDesc, prometheus.GaugeValue, avg,
)

// Next, we'll query the wallet to determine our confirmed and unconf
Expand Down
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package lndmon

import (
"github.com/btcsuite/btcutil"
"github.com/btcsuite/btcd/btcutil"
"github.com/lightninglabs/lndmon/collectors"
)

Expand Down
Loading

0 comments on commit d0d214c

Please sign in to comment.