From 0603cda5eeb8e7caaaf2cfb99b02fe4d3c5ba72d Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Wed, 4 Apr 2018 19:13:54 -0700 Subject: [PATCH 1/3] Add a helper for generating Consul's user-agent string --- lib/useragent.go | 29 +++++++++++++++++++++++++++++ lib/useragent_test.go | 18 ++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 lib/useragent.go create mode 100644 lib/useragent_test.go diff --git a/lib/useragent.go b/lib/useragent.go new file mode 100644 index 0000000000..84e76d4dfb --- /dev/null +++ b/lib/useragent.go @@ -0,0 +1,29 @@ +package lib + +import ( + "fmt" + "runtime" + + "github.com/hashicorp/consul/version" +) + +var ( + // projectURL is the project URL. + projectURL = "https://www.consul.io/" + + // rt is the runtime - variable for tests. + rt = runtime.Version() + + // versionFunc is the func that returns the current version. This is a + // function to take into account the different build processes and distinguish + // between enterprise and oss builds. + versionFunc = func() string { + return version.GetHumanVersion() + } +) + +// UserAgent returns the consistent user-agent string for Consul. +func UserAgent() string { + return fmt.Sprintf("Consul/%s (+%s; %s)", + versionFunc(), projectURL, rt) +} diff --git a/lib/useragent_test.go b/lib/useragent_test.go new file mode 100644 index 0000000000..3ebaa9ecb7 --- /dev/null +++ b/lib/useragent_test.go @@ -0,0 +1,18 @@ +package lib + +import ( + "testing" +) + +func TestUserAgent(t *testing.T) { + projectURL = "https://consul-test.com" + rt = "go5.0" + versionFunc = func() string { return "1.2.3" } + + act := UserAgent() + + exp := "Consul/1.2.3 (+https://consul-test.com; go5.0)" + if exp != act { + t.Errorf("expected %q to be %q", act, exp) + } +} From 3dc2cf793cfd3ef606e6c99c5c3d7f3872ccba56 Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Fri, 4 May 2018 12:10:59 -0700 Subject: [PATCH 2/3] Update vendor for go-discover --- vendor/github.com/aws/aws-sdk-go/NOTICE.txt | 2 +- vendor/github.com/digitalocean/godo/LICENSE.txt | 1 - vendor/github.com/gophercloud/gophercloud/LICENSE | 4 +--- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/vendor/github.com/aws/aws-sdk-go/NOTICE.txt b/vendor/github.com/aws/aws-sdk-go/NOTICE.txt index 5f14d1162e..899129ecc4 100644 --- a/vendor/github.com/aws/aws-sdk-go/NOTICE.txt +++ b/vendor/github.com/aws/aws-sdk-go/NOTICE.txt @@ -1,3 +1,3 @@ AWS SDK for Go -Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. +Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. Copyright 2014-2015 Stripe, Inc. diff --git a/vendor/github.com/digitalocean/godo/LICENSE.txt b/vendor/github.com/digitalocean/godo/LICENSE.txt index 43c5d2eee7..47f978eac1 100644 --- a/vendor/github.com/digitalocean/godo/LICENSE.txt +++ b/vendor/github.com/digitalocean/godo/LICENSE.txt @@ -52,4 +52,3 @@ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - diff --git a/vendor/github.com/gophercloud/gophercloud/LICENSE b/vendor/github.com/gophercloud/gophercloud/LICENSE index fbbbc9e4cb..5e86b007c6 100644 --- a/vendor/github.com/gophercloud/gophercloud/LICENSE +++ b/vendor/github.com/gophercloud/gophercloud/LICENSE @@ -9,10 +9,8 @@ License at Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the -specific language governing permissions and limitations under the License. +specific language governing permissions and limitations under the License. ------- - Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ From accb85a6a9388d8145d1640bdd3a74322e495b36 Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Fri, 4 May 2018 12:11:12 -0700 Subject: [PATCH 3/3] Use new discover and useragent libs --- agent/retry_join.go | 7 ++++++- agent/retry_join_test.go | 5 ++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/agent/retry_join.go b/agent/retry_join.go index 8a5c418a3b..c5a1c41bc9 100644 --- a/agent/retry_join.go +++ b/agent/retry_join.go @@ -6,6 +6,7 @@ import ( "strings" "time" + "github.com/hashicorp/consul/lib" discover "github.com/hashicorp/go-discover" ) @@ -67,7 +68,11 @@ func (r *retryJoiner) retryJoin() error { return nil } - disco := discover.Discover{} + disco, err := discover.New(discover.WithUserAgent(lib.UserAgent())) + if err != nil { + return err + } + r.logger.Printf("[INFO] agent: Retry join %s is supported for: %s", r.cluster, strings.Join(disco.Names(), " ")) r.logger.Printf("[INFO] agent: Joining %s cluster...", r.cluster) attempt := 0 diff --git a/agent/retry_join_test.go b/agent/retry_join_test.go index 5badbb8797..d30bf686d8 100644 --- a/agent/retry_join_test.go +++ b/agent/retry_join_test.go @@ -8,7 +8,10 @@ import ( ) func TestGoDiscoverRegistration(t *testing.T) { - d := discover.Discover{} + d, err := discover.New() + if err != nil { + t.Fatal(err) + } got := d.Names() want := []string{"aliyun", "aws", "azure", "digitalocean", "gce", "os", "scaleway", "softlayer", "triton"} if !reflect.DeepEqual(got, want) {