Skip to content
This repository has been archived by the owner on Jan 31, 2023. It is now read-only.

Add support for go modules. #1

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
32 changes: 32 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Golang CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-go/ for more details
version: 2
jobs:
build:
docker:
# specify the version
- image: circleci/golang:1.13.1

# Specify service dependencies here if necessary
# CircleCI maintains a library of pre-built images
# documented at https://circleci.com/docs/2.0/circleci-images/
# - image: circleci/postgres:9.4

#### TEMPLATE_NOTE: go expects specific checkout path representing url
#### expecting it in the form of
#### /go/src/github.com/circleci/go-tool
#### /go/src/bitbucket.org/circleci/go-tool
working_directory: /go/src/github.com/{{ORG_NAME}}/{{REPO_NAME}}
steps:
- checkout

# specify any bash command here prefixed with `run: `
- run: go get github.com/coreos/etcd
- run: go get github.com/mwitkow/go-etcd-harness
- run: go get github.com/prometheus/client_golang/prometheus
- run: go get github.com/stretchr/testify
- run: go get github.com/spf13/pflag
- run: go get github.com/fsnotify/fsnotify
- run: go get golang.org/x/net/context
- run: ./test_all.sh
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Go FlagZ

[![Travis Build](https://travis-ci.org/mwitkow/go-flagz.svg)](https://travis-ci.org/mwitkow/go-flagz)
[![Go Report Card](https://goreportcard.com/badge/github.com/mwitkow/go-flagz)](http://goreportcard.com/report/mwitkow/go-flagz)
[![GoDoc](http://img.shields.io/badge/GoDoc-Reference-blue.svg)](https://godoc.org/github.com/mwitkow/go-flagz)
[![SourceGraph](https://sourcegraph.com/github.com/mwitkow/go-flagz/-/badge.svg)](https://sourcegraph.com/github.com/mwitkow/go-flagz/?badge)
[![codecov](https://codecov.io/gh/mwitkow/go-flagz/branch/master/graph/badge.svg)](https://codecov.io/gh/mwitkow/go-flagz)
[![Travis Build](https://travis-ci.org/improbable-eng/go-flagz.svg)](https://travis-ci.org/improbable-eng/go-flagz)
[![Go Report Card](https://goreportcard.com/badge/github.com/improbable-eng/go-flagz)](http://goreportcard.com/report/improbable-eng/go-flagz)
[![GoDoc](http://img.shields.io/badge/GoDoc-Reference-blue.svg)](https://godoc.org/github.com/improbable-eng/go-flagz)
[![SourceGraph](https://sourcegraph.com/github.com/improbable-eng/go-flagz/-/badge.svg)](https://sourcegraph.com/github.com/improbable-eng/go-flagz/?badge)
[![codecov](https://codecov.io/gh/improbable-eng/go-flagz/branch/master/graph/badge.svg)](https://codecov.io/gh/improbable-eng/go-flagz)
[![Apache 2.0 License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE)

Dynamic, thread-safe `flag` variables that can be modified at runtime through [etcd](https://github.com/coreos/etcd)
Expand Down Expand Up @@ -44,7 +44,7 @@ All of this can be done simultaneously across a whole shard of your services.

Here's a teaser of the debug endpoint:

![Status Endpoint](https://raw.githubusercontent.com/mwitkow/go-flagz/screenshots/screenshot_endpoint.png)
![Status Endpoint](https://raw.githubusercontent.com/improbable-eng/go-flagz/screenshots/screenshot_endpoint.png)

## Examples

Expand Down Expand Up @@ -114,8 +114,8 @@ This code is *production* quality. It's been running happily in production at Im

Features planned:

* [x] - [#11](https://github.com/mwitkow/go-flagz/issues/11) monitoring of `FlagSet` checksus using a Prometheus handler
* [ ] - [#12](https://github.com/mwitkow/go-flagz/issues/12) support for standard `flag` (requires changes in `spf13/pflag` interfaces)
* [x] - [#11](https://github.com/improbable-eng/go-flagz/issues/11) monitoring of `FlagSet` checksus using a Prometheus handler
* [ ] - [#12](https://github.com/improbable-eng/go-flagz/issues/12) support for standard `flag` (requires changes in `spf13/pflag` interfaces)

### License

Expand Down
9 changes: 9 additions & 0 deletions checksum.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,22 @@ package flagz

import (
"hash/fnv"
"sync"

"github.com/spf13/pflag"
)

// @todo Temporary fix for race condition happening in the test:
// spf13/pflag.FlagSet.VisitAll seems to be prone to a race condition
// This fixes that but I'm not sure how much slower does it make the codebase
var visitAllMutex = &sync.Mutex{}

// ChecksumFlagSet will generate a FNV of the *set* values in a FlagSet.
func ChecksumFlagSet(flagSet *pflag.FlagSet, flagFilter func(flag *pflag.Flag) bool) []byte {
h := fnv.New32a()

visitAllMutex.Lock()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Admitteldy this feels heavy handed and not elegant considering the package mostly uses atomic instead of locking, but the reads and writes happening in VisitAll triggered the race detector.

defer visitAllMutex.Unlock()
flagSet.VisitAll(func(flag *pflag.Flag) {
if flagFilter != nil && !flagFilter(flag) {
return
Expand Down
2 changes: 1 addition & 1 deletion checksum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"testing"
"time"

"github.com/mwitkow/go-flagz"
"github.com/improbable-eng/go-flagz"
flag "github.com/spf13/pflag"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down
2 changes: 1 addition & 1 deletion configmap/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Kubernetes (K8s) ConfigMap support

This package allows you to use [ConfigMap](http://kubernetes.io/docs/user-guide/configmap/) objects in Kubernetes to
drive the update of [dynamic](https://github.com/mwitkow/go-flagz/#dynamic-json-flag-with-a-validator-and-notifier) `go-flagz` at runtime of your service.
drive the update of [dynamic](https://github.com/improbable-eng/go-flagz/#dynamic-json-flag-with-a-validator-and-notifier) `go-flagz` at runtime of your service.

## Semantics

Expand Down
1 change: 0 additions & 1 deletion configmap/testdata/..data

This file was deleted.

2 changes: 1 addition & 1 deletion configmap/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

"github.com/fsnotify/fsnotify"
flag "github.com/spf13/pflag"
"github.com/mwitkow/go-flagz"
"github.com/improbable-eng/go-flagz"
)

const (
Expand Down
13 changes: 11 additions & 2 deletions configmap/updater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package configmap_test

import (
"path/filepath"
"strings"
"testing"
"time"

Expand All @@ -16,8 +18,8 @@ import (

"os"

"github.com/mwitkow/go-flagz"
"github.com/mwitkow/go-flagz/configmap"
"github.com/improbable-eng/go-flagz"
"github.com/improbable-eng/go-flagz/configmap"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
Expand Down Expand Up @@ -67,6 +69,13 @@ func (s *updaterTestSuite) TearDownTest() {
func (s *updaterTestSuite) copyTestDataToDir() {
copyCmd := exec.Command("cp", "--archive", "testdata", s.tempDir)
require.NoError(s.T(), copyCmd.Run(), "copying testdata directory to tempdir must not fail")
// We are storing file testdata/9989_09_09_07_32_32.099817316 and renaming it to testdata/..9989_09_09_07_32_32.099817316,
// because go modules don't allow repos with files with .. in their filename. See https://github.com/golang/go/issues/27299.
for _, p := range []string{firstGoodDir, secondGoodDir, badStaticDir} {
pOld := filepath.Join(s.tempDir, "testdata", strings.TrimPrefix(p, ".."))
pNew := filepath.Join(s.tempDir, "testdata", p)
require.NoError(s.T(), os.Rename(pOld, pNew), "renaming %q to %q failed", pOld, pNew)
}
}

func (s *updaterTestSuite) linkDataDirTo(newDataDir string) {
Expand Down
4 changes: 2 additions & 2 deletions examples/server/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"os"

etcd "github.com/coreos/etcd/client"
"github.com/mwitkow/go-flagz"
"github.com/mwitkow/go-flagz/watcher"
"github.com/improbable-eng/go-flagz"
"github.com/improbable-eng/go-flagz/watcher"
flag "github.com/spf13/pflag"
)

Expand Down
4 changes: 2 additions & 2 deletions examples/server_kube/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"net/http"
"os"

"github.com/mwitkow/go-flagz"
"github.com/mwitkow/go-flagz/configmap"
"github.com/improbable-eng/go-flagz"
"github.com/improbable-eng/go-flagz/configmap"
flag "github.com/spf13/pflag"
)

Expand Down
4 changes: 2 additions & 2 deletions examples/simple/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"time"

etcd "github.com/coreos/etcd/client"
"github.com/mwitkow/go-flagz"
"github.com/mwitkow/go-flagz/watcher"
"github.com/improbable-eng/go-flagz"
"github.com/improbable-eng/go-flagz/watcher"
flag "github.com/spf13/pflag"
)

Expand Down
17 changes: 17 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module github.com/improbable-eng/go-flagz

require (
github.com/coreos/etcd v3.3.12+incompatible
github.com/coreos/go-semver v0.3.0 // indirect
github.com/fsnotify/fsnotify v1.4.7
github.com/golang/protobuf v1.3.2
github.com/mwitkow/go-etcd-harness v0.0.0-20160325212926-4dc1cb3e1ff9
github.com/prometheus/client_golang v1.2.0
github.com/prometheus/tsdb v0.7.1 // indirect
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.3.0
github.com/ugorji/go v1.1.1 // indirect
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980
)

go 1.13
Loading