Skip to content

Commit

Permalink
Merge pull request #26 from m-lab/prom_clean
Browse files Browse the repository at this point in the history
prometheusx and promauto
  • Loading branch information
pboothe authored Feb 27, 2019
2 parents 1747337 + 84cdc44 commit 5f24582
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
13 changes: 4 additions & 9 deletions aeflex/aeflex.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
appengine "google.golang.org/api/appengine/v1"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)

const (
Expand Down Expand Up @@ -43,7 +44,7 @@ var (
// gcp_aeflex_services
// Example usage:
// ServiceCount.Set(count)
ServiceCount = prometheus.NewGauge(
ServiceCount = promauto.NewGauge(
prometheus.GaugeOpts{
Name: "gcp_aeflex_services",
Help: "Number of active AEFlex services.",
Expand All @@ -56,7 +57,7 @@ var (
// gcp_aeflex_versions{service="etl-batch-parser"}
// Example usage:
// VersionCount.WithLabelValues("etl-batch-parser").Set(count)
VersionCount = prometheus.NewGaugeVec(
VersionCount = promauto.NewGaugeVec(
prometheus.GaugeOpts{
Name: "gcp_aeflex_versions",
Help: "Total number of versions.",
Expand All @@ -70,7 +71,7 @@ var (
// gcp_aeflex_instances{service="etl-batch-parser", serving="true"}
// Example usage:
// InstanceCount.WithLabelValues("etl-batch-parser", "true").Set(count)
InstanceCount = prometheus.NewGaugeVec(
InstanceCount = promauto.NewGaugeVec(
prometheus.GaugeOpts{
Name: "gcp_aeflex_instances",
Help: "Total number of running serving instances.",
Expand All @@ -79,12 +80,6 @@ var (
)
)

func init() {
prometheus.MustRegister(ServiceCount)
prometheus.MustRegister(VersionCount)
prometheus.MustRegister(InstanceCount)
}

// Service caches information collected from the App Engine Admin API during target discovery.
type Service struct {
project string
Expand Down
8 changes: 8 additions & 0 deletions aeflex/aeflex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"reflect"
"testing"

"github.com/m-lab/go/prometheusx"

"github.com/m-lab/gcp-service-discovery/aeflex/iface"
"github.com/m-lab/gcp-service-discovery/discovery"
appengine "google.golang.org/api/appengine/v1"
Expand Down Expand Up @@ -341,3 +343,9 @@ func TestNewService(t *testing.T) {
})
}
}

func TestMetrics(t *testing.T) {
InstanceCount.WithLabelValues("x", "x")
VersionCount.WithLabelValues("x")
prometheusx.LintMetrics(t)
}
15 changes: 5 additions & 10 deletions cmd/gcp_service_discovery/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ package main
import (
"context"
"fmt"
"log"
"net/http"
"os"
"time"

"github.com/m-lab/go/prometheusx"

"github.com/m-lab/go/rtx"

flag "github.com/spf13/pflag"
Expand All @@ -24,8 +24,6 @@ import (
"github.com/m-lab/gcp-service-discovery/discovery"
"github.com/m-lab/gcp-service-discovery/gke"
"github.com/m-lab/gcp-service-discovery/web"

"github.com/prometheus/client_golang/prometheus/promhttp"
)

var (
Expand Down Expand Up @@ -85,12 +83,9 @@ func main() {
os.Exit(1)
}

go func() {
http.Handle("/metrics", promhttp.Handler())
// Port allocated from:
// https://github.com/prometheus/prometheus/wiki/Default-port-allocations
log.Fatal(http.ListenAndServe(":9373", nil))
}()
// Port allocated from:
// https://github.com/prometheus/prometheus/wiki/Default-port-allocations
prometheusx.MustStartPrometheus(":9373")

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand Down

0 comments on commit 5f24582

Please sign in to comment.