Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/app/api/service/pipedservice/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ message PingResponse {

message ReportStatRequest {
// Metrics byte sequence in OpenMetrics format.
bytes piped_stats = 1 [(validate.rules).bytes.min_len = 1];
bytes piped_stats = 1;
}

message ReportStatResponse {
Expand Down
18 changes: 12 additions & 6 deletions pkg/app/piped/cmd/piped/piped.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (p *piped) run(ctx context.Context, t cli.Telemetry) (runErr error) {
}

// Register all metrics.
registerMetrics(cfg.PipedID)
registry := registerMetrics(cfg.PipedID)

// Initialize notifier and add piped events.
notifier, err := notifier.NewNotifier(cfg, t.Logger)
Expand Down Expand Up @@ -202,7 +202,7 @@ func (p *piped) run(ctx context.Context, t cli.Telemetry) (runErr error) {
admin.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("ok"))
})
admin.Handle("/metrics", t.PrometheusMetricsHandler())
admin.Handle("/metrics", t.PrometheusMetricsHandlerFor(registry))

group.Go(func() error {
return admin.Run(ctx)
Expand Down Expand Up @@ -616,14 +616,20 @@ func (p *piped) insertLoginUserToPasswd(ctx context.Context) error {
return nil
}

func registerMetrics(pipedID string) {
r := prometheus.DefaultRegisterer
// TODO: Add piped version as label.
func registerMetrics(pipedID string) *prometheus.Registry {
r := prometheus.NewRegistry()
wrapped := prometheus.WrapRegistererWith(
prometheus.Labels{"piped": pipedID},
prometheus.Labels{
"piped": pipedID,
"piped_version": version.Get().Version,
},
r,
)
wrapped.Register(prometheus.NewGoCollector())
wrapped.Register(prometheus.NewProcessCollector(prometheus.ProcessCollectorOpts{}))

k8scloudprovidermetrics.Register(wrapped)
k8slivestatestoremetrics.Register(wrapped)

return r
}
1 change: 1 addition & 0 deletions pkg/cli/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ go_library(
deps = [
"//pkg/log:go_default_library",
"//pkg/version:go_default_library",
"@com_github_prometheus_client_golang//prometheus:go_default_library",
"@com_github_prometheus_client_golang//prometheus/promhttp:go_default_library",
"@com_github_spf13_cobra//:go_default_library",
"@com_github_spf13_pflag//:go_default_library",
Expand Down
11 changes: 11 additions & 0 deletions pkg/cli/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"syscall"

"cloud.google.com/go/profiler"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/spf13/cobra"
"go.uber.org/zap"
Expand Down Expand Up @@ -126,6 +127,16 @@ func (t Telemetry) PrometheusMetricsHandler() http.Handler {
return empty
}

func (t Telemetry) PrometheusMetricsHandlerFor(r *prometheus.Registry) http.Handler {
if t.Flags.Metrics {
return promhttp.HandlerFor(r, promhttp.HandlerOpts{})
}
var empty http.HandlerFunc = func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(""))
}
return empty
}

func extractServiceName(cmd *cobra.Command) string {
return strings.Replace(cmd.CommandPath(), " ", ".", -1)
}