Remove HostnameGrouping method

This commit is contained in:
beorn7 2018-02-14 17:19:52 +01:00
parent 3c2baee2d1
commit 779cbe15b2
4 changed files with 7 additions and 28 deletions

View File

@ -164,8 +164,11 @@ func pushCollectors(job string, grouping map[string]string, url, method string,
// returned map is created upon each call so that the caller is free to add more
// labels to the map.
//
// Deprecated: It is recommended to use a Pusher created with New, which has a
// method HostnameGrouping.
// Deprecated: Usually, metrics pushed to the Pushgateway should not be
// host-centric. (You would use https://github.com/prometheus/node_exporter in
// that case.) If you have the need to add the hostname to the grouping key, you
// are probably doing something wrong. See
// https://prometheus.io/docs/practices/pushing/ for details.
func HostnameGroupingKey() map[string]string {
hostname, err := os.Hostname()
if err != nil {

View File

@ -28,7 +28,7 @@ func ExamplePusher_Push() {
completionTime.SetToCurrentTime()
if err := push.New("http://pushgateway:9091", "db_backup").
Collector(completionTime).
HostnameGrouping().
Grouping("db", "customers").
Push(); err != nil {
fmt.Println("Could not push completion time to Pushgateway:", err)
}

View File

@ -41,7 +41,6 @@ import (
"io/ioutil"
"net/http"
"net/url"
"os"
"strings"
"github.com/prometheus/common/expfmt"
@ -167,21 +166,6 @@ func (p *Pusher) Grouping(name, value string) *Pusher {
return p
}
// HostnameGrouping adds a label pair with “instance” as the name and the
// current hostname as the value to the grouping key of the Pusher. If the
// hostname cannot be determined, “unknown” is used as the label value. For
// further implications of setting a grouping key, see the Grouping method.
//
// For convenience, this method returns a pointer to the Pusher itself.
func (p *Pusher) HostnameGrouping() *Pusher {
hostname, err := os.Hostname()
if err != nil {
hostname = "unknown"
}
p.grouping["instance"] = hostname
return p
}
// Client sets a custom HTTP client for the Pusher. For convenience, this method
// returns a pointer to the Pusher itself.
func (p *Pusher) Client(c *http.Client) *Pusher {

View File

@ -24,7 +24,6 @@ import (
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
"testing"
"github.com/prometheus/common/expfmt"
@ -40,11 +39,6 @@ func TestPush(t *testing.T) {
lastPath string
)
host, err := os.Hostname()
if err != nil {
t.Error(err)
}
// Fake a Pushgateway that always responds with 202.
pgwOK := httptest.NewServer(
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@ -100,7 +94,6 @@ func TestPush(t *testing.T) {
// Push some Collectors, all good.
if err := New(pgwOK.URL, "testjob").
HostnameGrouping().
Collector(metric1).
Collector(metric2).
Push(); err != nil {
@ -112,7 +105,7 @@ func TestPush(t *testing.T) {
if bytes.Compare(lastBody, wantBody) != 0 {
t.Errorf("got body %v, want %v", lastBody, wantBody)
}
if lastPath != "/metrics/job/testjob/instance/"+host {
if lastPath != "/metrics/job/testjob" {
t.Error("unexpected path:", lastPath)
}
@ -176,7 +169,6 @@ func TestPush(t *testing.T) {
// Push registry, all good.
if err := New(pgwOK.URL, "testjob").
HostnameGrouping().
Gatherer(reg).
Push(); err != nil {
t.Fatal(err)