Skip to content

Commit

Permalink
x
Browse files Browse the repository at this point in the history
  • Loading branch information
bassosimone committed Feb 6, 2024
1 parent 787509f commit 6568812
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
7 changes: 3 additions & 4 deletions internal/database/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"time"

"github.com/apex/log"
"github.com/ooni/probe-cli/v3/internal/engine"
"github.com/ooni/probe-cli/v3/internal/model"
"github.com/pkg/errors"
"github.com/upper/db/v4"
Expand Down Expand Up @@ -354,11 +355,9 @@ func (d *Database) AddTestKeys(msmt *model.DatabaseMeasurement, sk model.Measure
if err != nil {
log.WithError(err).Error("failed to serialize summary")
}
// This is necessary so that we can extract from the the opaque testKeys just
// the IsAnomaly field of bool type.
// Maybe generics are not so bad after-all, heh golang?
msmt.TestKeys = string(skBytes)
msmt.IsAnomaly = sql.NullBool{Bool: sk.Anomaly(), Valid: true}
_, isNotImplemented := sk.(*engine.ExperimentMeasurementSummaryKeysNotImplemented)
msmt.IsAnomaly = sql.NullBool{Bool: sk.Anomaly(), Valid: !isNotImplemented}
err = d.sess.Collection("measurements").Find("measurement_id", msmt.ID).Update(msmt)
if err != nil {
log.WithError(err).Error("failed to update measurement")
Expand Down
10 changes: 5 additions & 5 deletions internal/engine/experiment.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ func (e *experiment) Name() string {
return e.testName
}

// experimentMeasurementSummaryKeysNotImplemented is the [model.MeasurementSummary] we use when
// ExperimentMeasurementSummaryKeysNotImplemented is the [model.MeasurementSummary] we use when
// the experiment TestKeys do not provide an implementation of [model.MeasurementSummary].
type experimentMeasurementSummaryKeysNotImplemented struct{}
type ExperimentMeasurementSummaryKeysNotImplemented struct{}

var _ model.MeasurementSummaryKeys = &experimentMeasurementSummaryKeysNotImplemented{}
var _ model.MeasurementSummaryKeys = &ExperimentMeasurementSummaryKeysNotImplemented{}

// IsAnomaly implements MeasurementSummary.
func (*experimentMeasurementSummaryKeysNotImplemented) Anomaly() bool {
func (*ExperimentMeasurementSummaryKeysNotImplemented) Anomaly() bool {
return false
}

Expand All @@ -79,7 +79,7 @@ func (e *experiment) GetSummaryKeys(m *model.Measurement) model.MeasurementSumma
if tk, ok := m.TestKeys.(model.MeasurementSummaryKeysProvider); ok {
return tk.MeasurementSummaryKeys()
}
return &experimentMeasurementSummaryKeysNotImplemented{}
return &ExperimentMeasurementSummaryKeysNotImplemented{}
}

// ReportID implements Experiment.ReportID.
Expand Down

0 comments on commit 6568812

Please sign in to comment.