-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a dedicated system for generic configuration options
There are certain configuration options that basically apply to all Buildbarn binaries. One example is Jaeger. Right now only bb_storage supports it, even though we want it to be configurable for all binaries. Introduce a separate set of messages for setting up these options. Add a pkg/global package that contains an initialization function for all of these. From now on we'll be calling this from within main() in all binaries. This should make it easier to complete this PR: buildbarn/bb-remote-execution#32
- Loading branch information
1 parent
8d9054f
commit fb0be44
Showing
13 changed files
with
199 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package global | ||
|
||
import ( | ||
"log" | ||
"runtime" | ||
"time" | ||
|
||
pb "github.com/buildbarn/bb-storage/pkg/proto/configuration/global" | ||
"github.com/buildbarn/bb-storage/pkg/util" | ||
"github.com/golang/protobuf/ptypes" | ||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/prometheus/client_golang/prometheus/push" | ||
|
||
"contrib.go.opencensus.io/exporter/jaeger" | ||
prometheus_exporter "contrib.go.opencensus.io/exporter/prometheus" | ||
"go.opencensus.io/plugin/ocgrpc" | ||
"go.opencensus.io/stats/view" | ||
"go.opencensus.io/trace" | ||
"go.opencensus.io/zpages" | ||
) | ||
|
||
// ApplyConfiguration applies configuration options to the running | ||
// process. These configuration options are global, in that they apply | ||
// to all Buildbarn binaries, regardless of their purpose. | ||
func ApplyConfiguration(configuration *pb.Configuration) error { | ||
// Push traces to Jaeger. | ||
if jaegerConfiguration := configuration.GetJaeger(); jaegerConfiguration != nil { | ||
pe, err := prometheus_exporter.NewExporter(prometheus_exporter.Options{ | ||
Registry: prometheus.DefaultRegisterer.(*prometheus.Registry), | ||
Namespace: "bb_storage", | ||
}) | ||
if err != nil { | ||
return util.StatusWrap(err, "Failed to create the Prometheus stats exporter") | ||
} | ||
view.RegisterExporter(pe) | ||
if err := view.Register(ocgrpc.DefaultServerViews...); err != nil { | ||
return util.StatusWrap(err, "Failed to register ocgrpc server views") | ||
} | ||
zpages.Handle(nil, "/debug") | ||
je, err := jaeger.NewExporter(jaeger.Options{ | ||
AgentEndpoint: jaegerConfiguration.AgentEndpoint, | ||
CollectorEndpoint: jaegerConfiguration.CollectorEndpoint, | ||
Process: jaeger.Process{ | ||
ServiceName: jaegerConfiguration.ServiceName, | ||
}, | ||
}) | ||
if err != nil { | ||
return util.StatusWrap(err, "Failed to create the Jaeger exporter") | ||
} | ||
trace.RegisterExporter(je) | ||
if jaegerConfiguration.AlwaysSample { | ||
trace.ApplyConfig(trace.Config{DefaultSampler: trace.AlwaysSample()}) | ||
} | ||
} | ||
|
||
// Enable mutex profiling. | ||
runtime.SetMutexProfileFraction(int(configuration.GetMutexProfileFraction())) | ||
|
||
// Periodically push metrics to a Prometheus Pushgateway, as | ||
// opposed to letting the Prometheus server scrape the metrics. | ||
if pushgateway := configuration.GetPrometheusPushgateway(); pushgateway != nil { | ||
pusher := push.New(pushgateway.Url, pushgateway.Job) | ||
pusher.Gatherer(prometheus.DefaultGatherer) | ||
if basicAuthentication := pushgateway.BasicAuthentication; basicAuthentication != nil { | ||
pusher.BasicAuth(basicAuthentication.Username, basicAuthentication.Password) | ||
} | ||
for key, value := range pushgateway.Grouping { | ||
pusher.Grouping(key, value) | ||
} | ||
pushInterval, err := ptypes.Duration(pushgateway.PushInterval) | ||
if err != nil { | ||
return util.StatusWrap(err, "Failed to parse push interval") | ||
} | ||
|
||
go func() { | ||
for { | ||
if err := pusher.Push(); err != nil { | ||
log.Print("Failed to push metrics to Prometheus Pushgateway: ", err) | ||
} | ||
time.Sleep(pushInterval) | ||
} | ||
}() | ||
} | ||
|
||
return nil | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
load("@rules_proto//proto:defs.bzl", "proto_library") | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library") | ||
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library") | ||
|
||
go_library( | ||
name = "go_default_library", | ||
embed = [":global_go_proto"], | ||
importpath = "github.com/buildbarn/bb-storage/pkg/proto/configuration/global", | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
proto_library( | ||
name = "global_proto", | ||
srcs = ["global.proto"], | ||
visibility = ["//visibility:public"], | ||
deps = ["@com_google_protobuf//:duration_proto"], | ||
) | ||
|
||
go_proto_library( | ||
name = "global_go_proto", | ||
importpath = "github.com/buildbarn/bb-storage/pkg/proto/configuration/global", | ||
proto = ":global_proto", | ||
visibility = ["//visibility:public"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
syntax = "proto3"; | ||
|
||
package buildbarn.configuration.global; | ||
|
||
import "google/protobuf/duration.proto"; | ||
|
||
option go_package = "github.com/buildbarn/bb-storage/pkg/proto/configuration/global"; | ||
|
||
message JaegerConfiguration { | ||
// Jaeger agent endpoint. | ||
string agent_endpoint = 1; | ||
|
||
// Jaeger collector endpoint. | ||
string collector_endpoint = 2; | ||
|
||
// OpenTracing service name. | ||
string service_name = 3; | ||
|
||
// Whether or not all traces should be sampled. | ||
bool always_sample = 4; | ||
} | ||
|
||
message BasicAuthenticationConfiguration { | ||
// Username to store in the "Authorization: Basic" header. | ||
string username = 1; | ||
|
||
// Password to store in the "Authorization: Basic" header. | ||
string password = 2; | ||
} | ||
|
||
message PrometheusPushgatewayConfiguration { | ||
// URL of the Prometheus Pushgateway server. Do not include the | ||
// "/metrics/jobs/..." part in the URL. | ||
string url = 1; | ||
|
||
// Name of the job to announce to the Prometheus Pushgateway. | ||
string job = 2; | ||
|
||
// If set, enable the use of HTTP basic authentication. | ||
BasicAuthenticationConfiguration basic_authentication = 3; | ||
|
||
// Label pairs to use as the grouping key. | ||
map<string, string> grouping = 4; | ||
|
||
// Interval between metrics pushes. | ||
google.protobuf.Duration push_interval = 5; | ||
} | ||
|
||
message Configuration { | ||
// Jaeger configuration for tracing. | ||
JaegerConfiguration jaeger = 1; | ||
|
||
// Sets the runtime.SetMutexProfileFraction(), so that the HTTP debug | ||
// endpoints used by pprof expose mutex profiling information. | ||
int32 mutex_profile_fraction = 2; | ||
|
||
// Periodically push metrics to a Prometheus Pushgateway, as opposed | ||
// to letting the Prometheus server scrape the metrics. | ||
PrometheusPushgatewayConfiguration prometheus_pushgateway = 3; | ||
} |