diff --git a/go.mod b/go.mod index 77feac0e..f403a054 100644 --- a/go.mod +++ b/go.mod @@ -18,7 +18,7 @@ require ( github.com/kr/pretty v0.1.0 // indirect github.com/kylelemons/godebug v0.0.0-20160406211939-eadb3ce320cb github.com/matttproud/golang_protobuf_extensions v1.0.1 - github.com/oklog/oklog v0.0.0-20170918173356-f857583a70c3 + github.com/oklog/run v1.0.0 github.com/oklog/ulid v0.0.0-20170117200651-66bb6560562f github.com/pkg/errors v0.8.0 github.com/prometheus/client_golang v0.9.2 diff --git a/go.sum b/go.sum index 16635415..6407b99d 100644 --- a/go.sum +++ b/go.sum @@ -123,8 +123,8 @@ github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQz github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223 h1:F9x/1yl3T2AeKLr2AMdilSD8+f9bvMnNN8VS5iDtovc= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= -github.com/oklog/oklog v0.0.0-20170918173356-f857583a70c3 h1:K/4JIfLQRyyHKJGd6ZfHply0GYxMuiqLCGuA8904lJk= -github.com/oklog/oklog v0.0.0-20170918173356-f857583a70c3/go.mod h1:FCV+B7mhrz4o+ueLpx+KqkyXRGMWOYEvfiXtdGtbWGs= +github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw= +github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA= github.com/oklog/ulid v0.0.0-20170117200651-66bb6560562f h1:UpfE/Q64+1idrbE+phdstApLr3SJBSjkxg8AvRx1mSk= github.com/oklog/ulid v0.0.0-20170117200651-66bb6560562f/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c h1:Lgl0gzECD8GnQ5QCWA8o6BtfL6mDH5rQgM4/fX3avOs= diff --git a/inhibit/inhibit.go b/inhibit/inhibit.go index 60027b52..b4d00fd2 100644 --- a/inhibit/inhibit.go +++ b/inhibit/inhibit.go @@ -20,7 +20,7 @@ import ( "github.com/go-kit/kit/log" "github.com/go-kit/kit/log/level" - "github.com/oklog/oklog/pkg/group" + "github.com/oklog/run" "github.com/prometheus/common/model" "github.com/prometheus/alertmanager/config" @@ -84,7 +84,7 @@ func (ih *Inhibitor) run(ctx context.Context) { // Run the Inhibitor's background processing. func (ih *Inhibitor) Run() { var ( - g group.Group + g run.Group ctx context.Context ) diff --git a/vendor/github.com/oklog/run/.gitignore b/vendor/github.com/oklog/run/.gitignore new file mode 100644 index 00000000..a1338d68 --- /dev/null +++ b/vendor/github.com/oklog/run/.gitignore @@ -0,0 +1,14 @@ +# Binaries for programs and plugins +*.exe +*.dll +*.so +*.dylib + +# Test binary, build with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736 +.glide/ diff --git a/vendor/github.com/oklog/oklog/LICENSE b/vendor/github.com/oklog/run/LICENSE similarity index 99% rename from vendor/github.com/oklog/oklog/LICENSE rename to vendor/github.com/oklog/run/LICENSE index 8dada3ed..261eeb9e 100644 --- a/vendor/github.com/oklog/oklog/LICENSE +++ b/vendor/github.com/oklog/run/LICENSE @@ -178,7 +178,7 @@ APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "{}" + boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright {yyyy} {name of copyright owner} + Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/vendor/github.com/oklog/run/README.md b/vendor/github.com/oklog/run/README.md new file mode 100644 index 00000000..a7228cd9 --- /dev/null +++ b/vendor/github.com/oklog/run/README.md @@ -0,0 +1,73 @@ +# run + +[![GoDoc](https://godoc.org/github.com/oklog/run?status.svg)](https://godoc.org/github.com/oklog/run) +[![Build Status](https://travis-ci.org/oklog/run.svg?branch=master)](https://travis-ci.org/oklog/run) +[![Go Report Card](https://goreportcard.com/badge/github.com/oklog/run)](https://goreportcard.com/report/github.com/oklog/run) +[![Apache 2 licensed](https://img.shields.io/badge/license-Apache2-blue.svg)](https://raw.githubusercontent.com/oklog/run/master/LICENSE) + +run.Group is a universal mechanism to manage goroutine lifecycles. + +Create a zero-value run.Group, and then add actors to it. Actors are defined as +a pair of functions: an **execute** function, which should run synchronously; +and an **interrupt** function, which, when invoked, should cause the execute +function to return. Finally, invoke Run, which blocks until the first actor +returns. This general-purpose API allows callers to model pretty much any +runnable task, and achieve well-defined lifecycle semantics for the group. + +run.Group was written to manage component lifecycles in func main for +[OK Log](https://github.com/oklog/oklog). +But it's useful in any circumstance where you need to orchestrate multiple +goroutines as a unit whole. +[Click here](https://www.youtube.com/watch?v=LHe1Cb_Ud_M&t=15m45s) to see a +video of a talk where run.Group is described. + +## Examples + +### context.Context + +```go +ctx, cancel := context.WithCancel(context.Background()) +g.Add(func() error { + return myProcess(ctx, ...) +}, func(error) { + cancel() +}) +``` + +### net.Listener + +```go +ln, _ := net.Listen("tcp", ":8080") +g.Add(func() error { + return http.Serve(ln, nil) +}, func(error) { + ln.Close() +}) +``` + +### io.ReadCloser + +```go +var conn io.ReadCloser = ... +g.Add(func() error { + s := bufio.NewScanner(conn) + for s.Scan() { + println(s.Text()) + } + return s.Err() +}, func(error) { + conn.Close() +}) +``` + +## Comparisons + +Package run is somewhat similar to package +[errgroup](https://godoc.org/golang.org/x/sync/errgroup), +except it doesn't require actor goroutines to understand context semantics. + +It's somewhat similar to package +[tomb.v1](https://godoc.org/gopkg.in/tomb.v1) or +[tomb.v2](https://godoc.org/gopkg.in/tomb.v2), +except it has a much smaller API surface, delegating e.g. staged shutdown of +goroutines to the caller. diff --git a/vendor/github.com/oklog/oklog/pkg/group/group.go b/vendor/github.com/oklog/run/group.go similarity index 86% rename from vendor/github.com/oklog/oklog/pkg/group/group.go rename to vendor/github.com/oklog/run/group.go index 72b69f4b..832d47dd 100644 --- a/vendor/github.com/oklog/oklog/pkg/group/group.go +++ b/vendor/github.com/oklog/run/group.go @@ -1,9 +1,9 @@ -// Package group implements an actor-runner with deterministic teardown. It is +// Package run implements an actor-runner with deterministic teardown. It is // somewhat similar to package errgroup, except it does not require actor -// goroutines to understand context semantics. This makes it suitable for use -// in more circumstances; for example, goroutines which are handling -// connections from net.Listeners, or scanning input from a closable io.Reader. -package group +// goroutines to understand context semantics. This makes it suitable for use in +// more circumstances; for example, goroutines which are handling connections +// from net.Listeners, or scanning input from a closable io.Reader. +package run // Group collects actors (functions) and runs them concurrently. // When one actor (function) returns, all actors are interrupted. diff --git a/vendor/modules.txt b/vendor/modules.txt index baf290b2..3b470424 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -126,8 +126,8 @@ github.com/miekg/dns github.com/mitchellh/mapstructure # github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223 github.com/mwitkow/go-conntrack -# github.com/oklog/oklog v0.0.0-20170918173356-f857583a70c3 -github.com/oklog/oklog/pkg/group +# github.com/oklog/run v1.0.0 +github.com/oklog/run # github.com/oklog/ulid v0.0.0-20170117200651-66bb6560562f github.com/oklog/ulid # github.com/pkg/errors v0.8.0