From 5df757fdd4a6fa09e2d3201e5a801a14b9b7d4d9 Mon Sep 17 00:00:00 2001 From: Simon Pasquier Date: Fri, 28 Sep 2018 11:36:43 +0200 Subject: [PATCH 1/5] zookeeper: fix panic Signed-off-by: Simon Pasquier --- discovery/manager.go | 4 ++-- discovery/zookeeper/zookeeper.go | 10 ++++----- discovery/zookeeper/zookeeper_test.go | 32 +++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 7 deletions(-) create mode 100644 discovery/zookeeper/zookeeper_test.go diff --git a/discovery/manager.go b/discovery/manager.go index bb4409fea..ee70ada2b 100644 --- a/discovery/manager.go +++ b/discovery/manager.go @@ -304,12 +304,12 @@ func (m *Manager) registerProviders(cfg sd_config.ServiceDiscoveryConfig, setNam } for _, c := range cfg.ServersetSDConfigs { add(c, func() (Discoverer, error) { - return zookeeper.NewServersetDiscovery(c, log.With(m.logger, "discovery", "zookeeper")), nil + return zookeeper.NewServersetDiscovery(c, log.With(m.logger, "discovery", "zookeeper")) }) } for _, c := range cfg.NerveSDConfigs { add(c, func() (Discoverer, error) { - return zookeeper.NewNerveDiscovery(c, log.With(m.logger, "discovery", "nerve")), nil + return zookeeper.NewNerveDiscovery(c, log.With(m.logger, "discovery", "nerve")) }) } for _, c := range cfg.EC2SDConfigs { diff --git a/discovery/zookeeper/zookeeper.go b/discovery/zookeeper/zookeeper.go index 487121457..7b5c1afc0 100644 --- a/discovery/zookeeper/zookeeper.go +++ b/discovery/zookeeper/zookeeper.go @@ -115,12 +115,12 @@ type Discovery struct { } // NewNerveDiscovery returns a new Discovery for the given Nerve config. -func NewNerveDiscovery(conf *NerveSDConfig, logger log.Logger) *Discovery { +func NewNerveDiscovery(conf *NerveSDConfig, logger log.Logger) (*Discovery, error) { return NewDiscovery(conf.Servers, time.Duration(conf.Timeout), conf.Paths, logger, parseNerveMember) } // NewServersetDiscovery returns a new Discovery for the given serverset config. -func NewServersetDiscovery(conf *ServersetSDConfig, logger log.Logger) *Discovery { +func NewServersetDiscovery(conf *ServersetSDConfig, logger log.Logger) (*Discovery, error) { return NewDiscovery(conf.Servers, time.Duration(conf.Timeout), conf.Paths, logger, parseServersetMember) } @@ -132,7 +132,7 @@ func NewDiscovery( paths []string, logger log.Logger, pf func(data []byte, path string) (model.LabelSet, error), -) *Discovery { +) (*Discovery, error) { if logger == nil { logger = log.NewNopLogger() } @@ -143,7 +143,7 @@ func NewDiscovery( c.SetLogger(treecache.NewZookeeperLogger(logger)) }) if err != nil { - return nil + return nil, err } updates := make(chan treecache.ZookeeperTreeCacheEvent) sd := &Discovery{ @@ -156,7 +156,7 @@ func NewDiscovery( for _, path := range paths { sd.treeCaches = append(sd.treeCaches, treecache.NewZookeeperTreeCache(conn, path, updates, logger)) } - return sd + return sd, nil } // Run implements the Discoverer interface. diff --git a/discovery/zookeeper/zookeeper_test.go b/discovery/zookeeper/zookeeper_test.go new file mode 100644 index 000000000..8900b2ab6 --- /dev/null +++ b/discovery/zookeeper/zookeeper_test.go @@ -0,0 +1,32 @@ +// Copyright 2018 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// 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. + +package zookeeper + +import ( + "testing" + "time" + + "github.com/prometheus/common/model" +) + +func TestNewDiscoveryError(t *testing.T) { + _, err := NewDiscovery( + []string{"unreachable.test"}, + time.Second, []string{"/"}, + nil, + func(data []byte, path string) (model.LabelSet, error) { return nil, nil }) + if err == nil { + t.Fatalf("expected error, got nil") + } +} From 3c00eeaf16645a7626cd00ce2621155950b896bb Mon Sep 17 00:00:00 2001 From: Simon Pasquier Date: Tue, 2 Oct 2018 12:48:07 +0200 Subject: [PATCH 2/5] web/api/v1: fix optional skip_head for snapshot (#4674) Signed-off-by: Simon Pasquier --- web/api/v1/api.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/web/api/v1/api.go b/web/api/v1/api.go index 71fd4ac54..3caedb5d2 100644 --- a/web/api/v1/api.go +++ b/web/api/v1/api.go @@ -892,9 +892,15 @@ func (api *API) snapshot(r *http.Request) (interface{}, *apiError, func()) { if !api.enableAdmin { return nil, &apiError{errorUnavailable, errors.New("Admin APIs disabled")}, nil } - skipHead, err := strconv.ParseBool(r.FormValue("skip_head")) - if err != nil { - return nil, &apiError{errorUnavailable, fmt.Errorf("unable to parse boolean 'skip_head' argument: %v", err)}, nil + var ( + skipHead bool + err error + ) + if r.FormValue("skip_head") != "" { + skipHead, err = strconv.ParseBool(r.FormValue("skip_head")) + if err != nil { + return nil, &apiError{errorUnavailable, fmt.Errorf("unable to parse boolean 'skip_head' argument: %v", err)}, nil + } } db := api.db() From f78e59577b031dd20a3bc4686e9773413b06432b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jannick=20Fahlbusch=20=E0=B8=8F=E0=B9=8E=E0=B9=8E=E0=B9=8E?= =?UTF-8?q?=E0=B9=8E=E0=B9=8E=E0=B9=8E=E0=B9=8E=E0=B9=8E=E0=B9=8E=E0=B9=8E?= =?UTF-8?q?=E0=B9=8E=E0=B9=8E=E0=B9=8E=E0=B9=8E=E0=B9=8E=E0=B9=8E=E0=B9=8E?= =?UTF-8?q?=E0=B9=8E=E0=B9=8E=E0=B9=8E=E0=B9=8E=E0=B9=8E=E0=B9=8E=E0=B9=8E?= =?UTF-8?q?=E0=B9=8E=E0=B9=8E=E0=B9=8E=E0=B9=8E=E0=B9=8E=E0=B9=8E=E0=B9=8E?= =?UTF-8?q?=E0=B9=8E=E0=B9=8E=E0=B9=8E=E0=B9=8E=E0=B9=8E=E0=B9=8E=E0=B9=8E?= =?UTF-8?q?=E0=B9=8E=E0=B9=8E=E0=B9=8E=E0=B9=8E=E0=B9=8E=E0=B9=8E=E0=B9=8E?= =?UTF-8?q?=E0=B9=8E=E0=B9=8E=E0=B9=8E=E0=B9=8E=E0=B9=8E=E0=B9=8E=E0=B9=8E?= =?UTF-8?q?=E0=B9=8E=E0=B9=8E=E0=B9=8E=E0=B9=8E=E0=B9=8E=E0=B9=8E=E0=B9=8E?= =?UTF-8?q?=E0=B9=8E=E0=B9=8E=E0=B9=8E=E0=B9=8E=E0=B9=8E=E0=B9=8E=E0=B9=8E?= =?UTF-8?q?=E0=B9=8E=E0=B9=8E=E0=B9=8E=E0=B9=8E=E0=B9=8E=E0=B9=8E=E0=B9=8E?= =?UTF-8?q?=E0=B9=8E=E0=B9=8E=E0=B9=8E=E0=B9=8E=E0=B9=8E=E0=B9=8E=E0=B9=8E?= =?UTF-8?q?=E0=B9=8E=E0=B9=8E=E0=B9=8E=E0=B9=8E=E0=B9=8E=E0=B9=8E=E0=B9=8E?= =?UTF-8?q?=E0=B9=8E=E0=B9=8E=E0=B9=8E=E0=B9=8E=E0=B9=8E=E0=B9=8E=E0=B9=8E?= =?UTF-8?q?=E0=B9=8E=E0=B9=8E=E0=B9=8E=E0=B9=8E?= Date: Tue, 2 Oct 2018 12:48:31 +0200 Subject: [PATCH 3/5] [FIX] EC2 DS: Check for existence of OwnerID (#4672) Commit 1c89984 introduced the ability to expose the owner of the instance. However, this breaks Prometheus if there is no OwnerID in the reservation (Eg. if you are using a private EC2-API introduced by #4333) Signed-off-by: Jannick Fahlbusch --- discovery/ec2/ec2.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/discovery/ec2/ec2.go b/discovery/ec2/ec2.go index d984fd3c6..a4f09cf06 100644 --- a/discovery/ec2/ec2.go +++ b/discovery/ec2/ec2.go @@ -241,9 +241,13 @@ func (d *Discovery) refresh() (tg *targetgroup.Group, err error) { continue } labels := model.LabelSet{ - ec2LabelOwnerID: model.LabelValue(*r.OwnerId), ec2LabelInstanceID: model.LabelValue(*inst.InstanceId), } + + if r.OwnerId != nil { + labels[ec2LabelOwnerID] = model.LabelValue(*r.OwnerId) + } + labels[ec2LabelPrivateIP] = model.LabelValue(*inst.PrivateIpAddress) addr := net.JoinHostPort(*inst.PrivateIpAddress, fmt.Sprintf("%d", d.port)) labels[model.AddressLabel] = model.LabelValue(addr) From 167a4b4e73a8eca8df648d2d2043e21bdb9a7449 Mon Sep 17 00:00:00 2001 From: Goutham Veeramachaneni Date: Thu, 4 Oct 2018 14:09:33 +0530 Subject: [PATCH 4/5] *: release 2.4.3 (#4694) Signed-off-by: Goutham Veeramachaneni --- CHANGELOG.md | 6 ++++++ VERSION | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee9a6dd77..2b29a18b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 2.4.3 / 2018-10-04 + +[BUGFIX] Fix panic when using custom EC2 API for SD #4672 +[BUGFIX] Fix panic when Zookeeper SD cannot connect to servers #4669 +[BUGFIX] Make the skip_head an optional parameter for snapshot API #4674 + ## 2.4.2 / 2018-09-21 The last release didn't have bugfix included due to a vendoring error. diff --git a/VERSION b/VERSION index 8e8299dcc..35cee72dc 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.4.2 +2.4.3 From 1625c9c6e44aecc17a3ca2bcbf83d3e932eb84a8 Mon Sep 17 00:00:00 2001 From: Goutham Veeramachaneni Date: Thu, 11 Oct 2018 09:10:37 -0700 Subject: [PATCH 5/5] Format changelog properly (#4721) Signed-off-by: Goutham Veeramachaneni --- CHANGELOG.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b29a18b1..efc9ba06e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,8 @@ ## 2.4.3 / 2018-10-04 -[BUGFIX] Fix panic when using custom EC2 API for SD #4672 -[BUGFIX] Fix panic when Zookeeper SD cannot connect to servers #4669 -[BUGFIX] Make the skip_head an optional parameter for snapshot API #4674 +* [BUGFIX] Fix panic when using custom EC2 API for SD #4672 +* [BUGFIX] Fix panic when Zookeeper SD cannot connect to servers #4669 +* [BUGFIX] Make the skip_head an optional parameter for snapshot API #4674 ## 2.4.2 / 2018-09-21