Skip to content

Commit e980b58

Browse files
authored
Merge pull request #440 from arnested/gops
Add an option for starting a gops agent
2 parents d1e980b + 4fce1ce commit e980b58

File tree

5 files changed

+23
-0
lines changed

5 files changed

+23
-0
lines changed

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ linters:
66
- depguard
77
- exhaustruct
88
- tagliatelle
9+
- wsl
910
settings:
1011
errcheck:
1112
check-type-assertions: true

entry_groups.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ func (e *entryGroups) get(containerID string) (*avahi.EntryGroup, func(), error)
4040
}
4141

4242
e.mutex.Lock()
43+
4344
if _, ok := e.groups[containerID]; !ok {
4445
entryGroup, err := e.avahiServer.EntryGroupNew()
4546
if err != nil {

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ require (
1717
require (
1818
github.com/carlmjohnson/versioninfo v0.22.5
1919
github.com/coreos/go-systemd/v22 v22.6.0
20+
github.com/google/gops v0.3.28
2021
)
2122

2223
require (

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
3939
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
4040
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
4141
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
42+
github.com/google/gops v0.3.28 h1:2Xr57tqKAmQYRAfG12E+yLcoa2Y42UJo2lOrUFL9ark=
43+
github.com/google/gops v0.3.28/go.mod h1:6f6+Nl8LcHrzJwi8+p0ii+vmBFSlB4f8cOOkTJ7sk4c=
4244
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 h1:YBftPWNWd4WwGqtY2yeZL2ef8rHAxPBD8KFhJpmcqms=
4345
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0/go.mod h1:YN5jB8ie0yfIUg6VvR9Kz84aCaG7AsGZnLjhHbUqwPg=
4446
github.com/holoplot/go-avahi v1.0.1 h1:XcqR2keL4qWRnlxHD5CAOdWpLFZJ+EOUK0vEuylfvvk=

main.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/coreos/go-systemd/v22/daemon"
1414
"github.com/docker/docker/client"
1515
"github.com/godbus/dbus/v5"
16+
"github.com/google/gops/agent"
1617
"github.com/holoplot/go-avahi"
1718
"github.com/kelseyhightower/envconfig"
1819
"ldddns.arnested.dk/internal/log"
@@ -29,6 +30,7 @@ var (
2930
//
3031
//nolint:lll
3132
type Config struct {
33+
Gops bool `default:"false" json:"Gops" split_words:"true"`
3234
HostnameLookup []string `default:"env:VIRTUAL_HOST,containerName" json:"HostnameLookup" split_words:"true"`
3335
IgnoreDockerComposeOneoff bool `default:"true" json:"IgnoreDockerComposeOneoff" split_words:"true"`
3436
}
@@ -53,6 +55,8 @@ func main() {
5355
panic(fmt.Errorf("could not read environment config: %w", err))
5456
}
5557

58+
gops(config.Gops)
59+
5660
docker, err := client.NewClientWithOpts(
5761
client.FromEnv,
5862
client.WithAPIVersionNegotiation(),
@@ -132,3 +136,17 @@ func getVersion() string {
132136

133137
return version
134138
}
139+
140+
// gops starts the gops agent if the config option is set.
141+
func gops(start bool) {
142+
if !start {
143+
return
144+
}
145+
146+
err := agent.Listen(agent.Options{
147+
ShutdownCleanup: true, // automatically closes on os.Interrupt
148+
})
149+
if err != nil {
150+
panic(fmt.Errorf("could not start gops agent: %w", err))
151+
}
152+
}

0 commit comments

Comments
 (0)