Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add metrics server #14

Merged
merged 31 commits into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
a2db4a6
upgrade to latest go version and dependencies, and migrate from circl…
Hsn723 Jul 8, 2022
4f5a1d3
use golangci-lint as a replacement to golint
Hsn723 Jul 11, 2022
a201f0f
add metrics server
Hsn723 Jul 8, 2022
4257d99
instrument usocksd with some metrics
Hsn723 Jul 8, 2022
b3213f3
fix typo in Status5DeniedByRuleset string
Hsn723 Jul 11, 2022
a3458f7
refactor: fix lint issues without modifying original behavior
Hsn723 Jul 11, 2022
c4c00ca
add metrics for proxy
Hsn723 Jul 11, 2022
ccc7fbb
remove circleci
Hsn723 Jul 11, 2022
7cca6ba
instrument time spent copying to/from buffers
Hsn723 Jul 11, 2022
706f713
instrument auth negotiation and address reading, refactor metrics
Hsn723 Jul 19, 2022
ce792e3
remove duplicated jobs
pddg Mar 3, 2023
155e605
fix inconsistent metric name
pddg Mar 3, 2023
9da58ba
do not listen when creating listner is failed
pddg Mar 3, 2023
5d75409
upgrade go to 1.20.1
pddg Mar 3, 2023
05787bc
use io instead of ioutil
pddg Mar 3, 2023
65ab492
gofmt
pddg Mar 3, 2023
a13e8d9
build with -trimpath
pddg Mar 8, 2023
3904468
exit by ErrorExit when serving metrics server failed
pddg Mar 8, 2023
e095487
metrics server now listens on ipv4/ipv6 addr
pddg Mar 8, 2023
0c796be
fix metric names
pddg Mar 13, 2023
03fb5bd
fix error handring on serving metrics server
pddg Mar 14, 2023
866a5c2
fix metric names
pddg Mar 14, 2023
4a7bdc7
fix test
pddg Mar 14, 2023
cb5f044
collect all connections count
pddg Mar 15, 2023
fbc06d1
remove reason labels
pddg Mar 15, 2023
e0a3f10
add type label for address read counter
pddg Mar 15, 2023
89c1f9f
add LabelValue for each type
pddg Mar 15, 2023
dc642c2
make unknown as const
pddg Mar 15, 2023
593e0de
add toml tag
pddg Mar 22, 2023
f097520
fix fot lint
pddg Mar 22, 2023
7d3b323
fix test
pddg Mar 23, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions .circleci/config.yml

This file was deleted.

36 changes: 36 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: main
on:
pull_request:
push:
branches:
- 'master'
env:
go-version: 1.20.1
jobs:
lint:
name: Lint
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: ${{ env.go-version }}
- uses: golangci/golangci-lint-action@v3
build:
name: Build
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: ${{ env.go-version }}
- run: go build -trimpath ./...
test:
name: Test
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: ${{ env.go-version }}
- run: NO_PROXY= go test -race -v -coverprofile cover.out ./...
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,4 @@ _testmain.go
*.exe
*.test
*.prof

# Ignore go.sum
/go.sum
*.out
5 changes: 4 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ linters:
- dupl
- goconst
- gofmt
- golint
- revive
- typecheck
- unparam
linters-settings:
staticcheck:
checks: ["all", "-SA6002"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Features
Install
-------

Use Go 1.7 or better.
Use a recent version of Go.

```
go get -u github.com/cybozu-go/usocksd/...
Expand Down
2 changes: 1 addition & 1 deletion address_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (a *AddressGroup) detectInvalid() {
}
a.lock.Lock()
if len(invalids) > 0 && len(a.invalids) != len(invalids) {
log.Warn("detect black-listed IP", map[string]interface{}{
_ = log.Warn("detect black-listed IP", map[string]interface{}{
"_bad_ips": toStringList(invalids),
})
}
Expand Down
16 changes: 14 additions & 2 deletions cmd/usocksd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"flag"
"fmt"
"net"
"os"

Expand All @@ -18,13 +19,24 @@ var (
optFile = flag.String("f", "", "configuration file name")
)

func serveMetrics(c *usocksd.Config) error {
metricsServer := usocksd.NewMetricsServer(c)
mln, err := usocksd.MetricsListener(c)
if err != nil {
return fmt.Errorf("could not initialize metrics server: %w", err)
}
return metricsServer.Serve(mln)
}

func serve(lns []net.Listener, c *usocksd.Config) {
socksServer := usocksd.NewServer(c)
for _, ln := range lns {
socksServer.Serve(ln)
}
err := well.Wait()
if err != nil && !well.IsSignaled(err) {
if err := serveMetrics(c); err != nil {
log.ErrorExit(err)
}
if err := well.Wait(); err != nil && !well.IsSignaled(err) {
log.ErrorExit(err)
}
}
Expand Down
5 changes: 4 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import (
)

const (
defaultPort = 1080
defaultPort = 1080
defaultMetricsPort = 1081
)

// IncomingConfig is a set of configurations to accept clients.
type IncomingConfig struct {
Port int
MetricsPort int
Addresses []net.IP
AllowFrom []string `toml:"allow_from"`
allowSubnets []*net.IPNet
Expand All @@ -42,6 +44,7 @@ type Config struct {
func NewConfig() *Config {
c := new(Config)
c.Incoming.Port = defaultPort
c.Incoming.MetricsPort = defaultMetricsPort
return c
}

Expand Down
43 changes: 38 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,43 @@
module github.com/cybozu-go/usocksd

require (
github.com/BurntSushi/toml v0.3.1
github.com/cybozu-go/log v1.6.0
github.com/cybozu-go/netutil v1.2.0
github.com/cybozu-go/well v1.10.0
github.com/BurntSushi/toml v1.1.0
github.com/cybozu-go/log v1.6.1
github.com/cybozu-go/netutil v1.4.2
github.com/cybozu-go/well v1.11.0
github.com/prometheus/client_golang v1.12.2
)

go 1.13
require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/onsi/gomega v1.19.0 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.2 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/spf13/afero v1.8.2 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.12.0 // indirect
github.com/subosito/gotenv v1.4.0 // indirect
github.com/vishvananda/netlink v1.1.0 // indirect
github.com/vishvananda/netns v0.0.0-20211101163701-50045581ed74 // indirect
golang.org/x/net v0.0.0-20220706163947-c90051bbdb60 // indirect
golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/ini.v1 v1.66.6 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

go 1.19
Loading