diff options
author | Christopher Speller <crspeller@gmail.com> | 2018-02-16 06:47:51 -0800 |
---|---|---|
committer | Joram Wilander <jwawilander@gmail.com> | 2018-02-16 09:47:51 -0500 |
commit | 6d8f122a5160f6d9e4c51579f2429dfaa62c7271 (patch) | |
tree | 6e0242cd6709260abd74060a7ec7dc1381efa36e /vendor/github.com/prometheus/client_golang/prometheus/push/example_add_from_gatherer_test.go | |
parent | b112747de76f9c11c4d8083207049fac6e435019 (diff) | |
download | chat-6d8f122a5160f6d9e4c51579f2429dfaa62c7271.tar.gz chat-6d8f122a5160f6d9e4c51579f2429dfaa62c7271.tar.bz2 chat-6d8f122a5160f6d9e4c51579f2429dfaa62c7271.zip |
Upgrading server dependancies (#8308)
Diffstat (limited to 'vendor/github.com/prometheus/client_golang/prometheus/push/example_add_from_gatherer_test.go')
-rw-r--r-- | vendor/github.com/prometheus/client_golang/prometheus/push/example_add_from_gatherer_test.go | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/vendor/github.com/prometheus/client_golang/prometheus/push/example_add_from_gatherer_test.go b/vendor/github.com/prometheus/client_golang/prometheus/push/example_add_from_gatherer_test.go index 5180c0745..dd22b526a 100644 --- a/vendor/github.com/prometheus/client_golang/prometheus/push/example_add_from_gatherer_test.go +++ b/vendor/github.com/prometheus/client_golang/prometheus/push/example_add_from_gatherer_test.go @@ -11,12 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -// Copyright (c) 2013, The Prometheus Authors -// All rights reserved. -// -// Use of this source code is governed by a BSD-style license that can be found -// in the LICENSE file. - package push_test import ( @@ -53,10 +47,14 @@ func performBackup() (int, error) { return 42, nil } -func ExampleAddFromGatherer() { +func ExamplePusher_Add() { + // We use a registry here to benefit from the consistency checks that + // happen during registration. registry := prometheus.NewRegistry() registry.MustRegister(completionTime, duration, records) - // Note that successTime is not registered at this time. + // Note that successTime is not registered. + + pusher := push.New("http://pushgateway:9091", "db_backup").Gatherer(registry) start := time.Now() n, err := performBackup() @@ -67,18 +65,16 @@ func ExampleAddFromGatherer() { if err != nil { fmt.Println("DB backup failed:", err) } else { - // Only now register successTime. - registry.MustRegister(successTime) + // Add successTime to pusher only in case of success. + // We could as well register it with the registry. + // This example, however, demonstrates that you can + // mix Gatherers and Collectors when handling a Pusher. + pusher.Collector(successTime) successTime.SetToCurrentTime() } - // AddFromGatherer is used here rather than FromGatherer to not delete a - // previously pushed success timestamp in case of a failure of this - // backup. - if err := push.AddFromGatherer( - "db_backup", nil, - "http://pushgateway:9091", - registry, - ); err != nil { + // Add is used here rather than Push to not delete a previously pushed + // success timestamp in case of a failure of this backup. + if err := pusher.Add(); err != nil { fmt.Println("Could not push to Pushgateway:", err) } } |