From 523bcd5c1ed637d478ac3892401f97ad73971111 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 000000000..84e76d4df --- /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 000000000..3ebaa9ecb --- /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 5911fd5344054b16721bb3ec4fb531027bf48cdf 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 5f14d1162..899129ecc 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 43c5d2eee..47f978eac 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 fbbbc9e4c..5e86b007c 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 303b56e07b18cafd97dcc1ddfb8ec5f832fd9735 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 8a5c418a3..c5a1c41bc 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 5badbb879..d30bf686d 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) {