Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP Grafana #1562

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from 11 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
16 changes: 7 additions & 9 deletions abn/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ import (
)

const (
// metricsDirEnv is the environment variable identifying the directory with metrics storage
metricsDirEnv = "METRICS_DIR"
// MetricsDirEnv is the environment variable identifying the directory with metrics storage
MetricsDirEnv = "METRICS_DIR"

configEnv = "ABN_CONFIG_FILE"
defaultPortNumber = 50051
)

var (
Expand Down Expand Up @@ -85,11 +88,6 @@ func (server *abnServer) WriteMetric(ctx context.Context, metricMsg *pb.MetricVa
)
}

const (
configEnv = "ABN_CONFIG_FILE"
defaultPortNumber = 50051
)

// abnConfig defines the configuration of the controllers
type abnConfig struct {
// Port is port number on which the abn gRPC service should listen
Expand Down Expand Up @@ -119,8 +117,8 @@ func LaunchGRPCServer(opts []grpc.ServerOption, stopCh <-chan struct{}) error {
grpcServer := grpc.NewServer(opts...)
pb.RegisterABNServer(grpcServer, newServer())

// configure metricsClient if needed
MetricsClient, err = badgerdb.GetClient(badger.DefaultOptions(os.Getenv(metricsDirEnv)), badgerdb.AdditionalOptions{})
// configure MetricsClient if needed
MetricsClient, err = badgerdb.GetClient(badger.DefaultOptions(os.Getenv(MetricsDirEnv)), badgerdb.AdditionalOptions{})
if err != nil {
log.Logger.Error("Unable to configure metrics storage client ", err)
return err
Expand Down
6 changes: 6 additions & 0 deletions abn/service_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ func lookupInternal(application string, user string) (controllers.RoutemapInterf
}

// record user; ignore error if any; this is best effort
if MetricsClient == nil {
return nil, invalidVersion, fmt.Errorf("no metrics client")
}
_ = MetricsClient.SetUser(application, versionNumber, *s.GetVersions()[versionNumber].GetSignature(), user)

return s, versionNumber, nil
Expand Down Expand Up @@ -131,6 +134,9 @@ func writeMetricInternal(application, user, metric, valueStr string) error {
v := s.GetVersions()[versionNumber]
transaction := uuid.NewString()

if MetricsClient == nil {
return fmt.Errorf("no metrics client")
}
err = MetricsClient.SetMetric(
s.GetNamespace()+"/"+s.GetName(), versionNumber, *v.GetSignature(),
metric, user, transaction,
Expand Down
10 changes: 9 additions & 1 deletion abn/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,16 +212,24 @@ func getMetricsCount(t *testing.T, namespace string, name string, version int, m
if rm == nil || reflect.ValueOf(rm).IsNil() {
return 0
}

assert.Less(t, version, len(rm.GetVersions()))
v := rm.GetVersions()[version]
signature := v.GetSignature()

if nil == signature {
return 0
}

// TODO: better error handling when there is no metrics client
if MetricsClient == nil {
return 0
}
versionmetrics, err := MetricsClient.GetMetrics(namespace+"/"+name, version, *signature)
if err != nil {
return 0
}

metrics, ok := (*versionmetrics)[metric]
if !ok {
return 0
Expand All @@ -236,7 +244,7 @@ func TestLaunchGRPCServer(t *testing.T) {
defer cancel()

// define METRICS_DIR
err := os.Setenv(metricsDirEnv, t.TempDir())
err := os.Setenv(MetricsDirEnv, t.TempDir())
assert.NoError(t, err)

configFile := filepath.Clean(util.CompletePath("../testdata", "abninputs/config.yaml"))
Expand Down
1 change: 1 addition & 0 deletions action/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ func (rOpts *RunOpts) KubeRun() error {
if err := rOpts.KubeDriver.InitKube(); err != nil {
return err
}

return base.RunExperiment(rOpts.ReuseResult, rOpts.KubeDriver)
}
2 changes: 1 addition & 1 deletion base/collect_grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (t *collectGRPCTask) resultForVersion() (map[string]*runner.Report, error)

// merge endpoint options with baseline options
if err := mergo.Merge(&endpoint, t.With.Config); err != nil {
log.Logger.Error(fmt.Sprintf("could not merge Fortio options for endpoint \"%s\"", endpointID))
log.Logger.Error(fmt.Sprintf("could not merge ghz options for endpoint \"%s\"", endpointID))
return nil, err
}
eOpts := runner.WithConfig(&endpoint) // endpoint options
Expand Down
Loading
Loading