diff --git a/splitio/admin/controllers/dashboard.go b/splitio/admin/controllers/dashboard.go index 7222b06a..a51ee444 100644 --- a/splitio/admin/controllers/dashboard.go +++ b/splitio/admin/controllers/dashboard.go @@ -150,6 +150,7 @@ func (c *DashboardController) gatherStats() *dashboard.GlobalStats { FeatureFlags: bundleSplitInfo(c.storages.SplitStorage), Segments: bundleSegmentInfo(c.storages.SplitStorage, c.storages.SegmentStorage), LargeSegments: bundleLargeSegmentInfo(c.storages.SplitStorage, c.storages.LargeSegmentStorage), + RuleBasedSegments: bundleRuleBasedInfo(c.storages.SplitStorage, c.storages.RuleBasedSegmentsStorage), Latencies: bundleProxyLatencies(c.storages.LocalTelemetryStorage), BackendLatencies: bundleLocalSyncLatencies(c.storages.LocalTelemetryStorage), ImpressionsQueueSize: getImpressionSize(c.storages.ImpressionStorage), @@ -166,6 +167,5 @@ func (c *DashboardController) gatherStats() *dashboard.GlobalStats { LoggedMessages: errorMessages, Uptime: int64(c.runtime.Uptime().Seconds()), FlagSets: getFlagSetsInfo(c.storages.SplitStorage), - RuleBasedSegments: bundleRBInfo(c.storages.RuleBasedSegmentsStorage), } } diff --git a/splitio/admin/controllers/helpers.go b/splitio/admin/controllers/helpers.go index abc2aa36..7565aed7 100644 --- a/splitio/admin/controllers/helpers.go +++ b/splitio/admin/controllers/helpers.go @@ -108,6 +108,45 @@ func bundleSegmentInfo(splitStorage storage.SplitStorage, segmentStorage storage return summaries } +func bundleRuleBasedInfo(splitStorage storage.SplitStorage, ruleBasedSegmentStorage storage.RuleBasedSegmentStorageConsumer) []dashboard.RuleBasedSegmentSummary { + names := splitStorage.RuleBasedSegmentNames() + summaries := make([]dashboard.RuleBasedSegmentSummary, 0, names.Size()) + + for _, name := range names.List() { + strName, ok := name.(string) + if !ok { + continue + } + + ruleBased, err := ruleBasedSegmentStorage.GetRuleBasedSegmentByName(strName) + if err != nil { + continue + } + + excluededSegments := make([]dashboard.ExcludedSegments, 0, len(ruleBased.Excluded.Segments)) + for _, excludedSegment := range ruleBased.Excluded.Segments { + excluededSegments = append(excluededSegments, dashboard.ExcludedSegments{ + Name: excludedSegment.Name, + Type: excludedSegment.Type, + }) + } + + if ruleBased.Excluded.Keys == nil { + ruleBased.Excluded.Keys = make([]string, 0) + } + + summaries = append(summaries, dashboard.RuleBasedSegmentSummary{ + Name: ruleBased.Name, + Active: ruleBased.Status == "ACTIVE", + ExcludedKeys: ruleBased.Excluded.Keys, + ExcludedSegments: excluededSegments, + LastModified: time.Unix(0, ruleBased.ChangeNumber*int64(time.Millisecond)).UTC().Format(time.UnixDate), + ChangeNumber: ruleBased.ChangeNumber, + }) + } + return summaries +} + func bundleSegmentKeysInfo(name string, segmentStorage storage.SegmentStorageConsumer) []dashboard.SegmentKeySummary { keys := segmentStorage.Keys(name) @@ -316,22 +355,3 @@ func getProxyRequestCount(metrics storage.TelemetryRuntimeConsumer) (ok int64, e return okCount, errorCount } - -func bundleRBInfo(rbStorage storage.RuleBasedSegmentsStorage) []dashboard.RBSummary { - all := rbStorage.All() - summaries := make([]dashboard.RBSummary, 0, len(all)) - for _, segment := range all { - excludedSegments := make([]string, 0, len(segment.Excluded.Segments)) - for _, seg := range segment.Excluded.Segments { - excludedSegments = append(excludedSegments, seg.Name) - } - summaries = append(summaries, dashboard.RBSummary{ - Name: segment.Name, - ChangeNumber: segment.ChangeNumber, - Active: segment.Status == "ACTIVE", - ExcludedKeys: segment.Excluded.Keys, - ExcludedSegments: excludedSegments, - }) - } - return summaries -} diff --git a/splitio/admin/controllers/helpers_test.go b/splitio/admin/controllers/helpers_test.go index a7d90280..7889dfcb 100644 --- a/splitio/admin/controllers/helpers_test.go +++ b/splitio/admin/controllers/helpers_test.go @@ -3,22 +3,27 @@ package controllers import ( "testing" + "github.com/splitio/split-synchronizer/v5/splitio/admin/views/dashboard" + "github.com/splitio/go-split-commons/v8/dtos" "github.com/splitio/go-split-commons/v8/storage/mocks" - "github.com/splitio/split-synchronizer/v5/splitio/admin/views/dashboard" + "github.com/splitio/go-toolkit/v5/datastructures/set" + "github.com/stretchr/testify/assert" ) func TestBundleRBInfo(t *testing.T) { + split := &mocks.SplitStorageMock{} + split.On("RuleBasedSegmentNames").Return(set.NewSet("rb1", "rb2"), nil).Once() rb := &mocks.MockRuleBasedSegmentStorage{} - rb.On("All").Return([]dtos.RuleBasedSegmentDTO{ - {Name: "rb1", ChangeNumber: 1, Status: "ACTIVE", Excluded: dtos.ExcludedDTO{Keys: []string{"one"}}}, - {Name: "rb2", ChangeNumber: 2, Status: "ARCHIVED"}, - }, nil) - result := bundleRBInfo(rb) + rb.On("GetRuleBasedSegmentByName", "rb1").Return(&dtos.RuleBasedSegmentDTO{Name: "rb1", ChangeNumber: 1, Status: "ACTIVE", Excluded: dtos.ExcludedDTO{Keys: []string{"one"}}}, nil).Once() + rb.On("GetRuleBasedSegmentByName", "rb2").Return(&dtos.RuleBasedSegmentDTO{Name: "rb2", ChangeNumber: 2, Status: "ARCHIVED"}, nil).Once() + result := bundleRuleBasedInfo(split, rb) assert.Len(t, result, 2) - assert.ElementsMatch(t, result, []dashboard.RBSummary{ - {Name: "rb1", ChangeNumber: 1, Active: true, ExcludedKeys: []string{"one"}, ExcludedSegments: []string{}}, - {Name: "rb2", ChangeNumber: 2, Active: false, ExcludedKeys: nil, ExcludedSegments: []string{}}, + assert.ElementsMatch(t, result, []dashboard.RuleBasedSegmentSummary{ + {Name: "rb1", ChangeNumber: 1, Active: true, ExcludedKeys: []string{"one"}, ExcludedSegments: []dashboard.ExcludedSegments{}, LastModified: "Thu Jan 1 00:00:00 UTC 1970"}, + {Name: "rb2", ChangeNumber: 2, Active: false, ExcludedKeys: []string{}, ExcludedSegments: []dashboard.ExcludedSegments{}, LastModified: "Thu Jan 1 00:00:00 UTC 1970"}, }) + split.AssertExpectations(t) + rb.AssertExpectations(t) } diff --git a/splitio/admin/views/dashboard/datainspector.go b/splitio/admin/views/dashboard/datainspector.go index f4f63577..3af58c63 100644 --- a/splitio/admin/views/dashboard/datainspector.go +++ b/splitio/admin/views/dashboard/datainspector.go @@ -38,6 +38,19 @@ const dataInspector = ` {{end}} +
  • + + +  Rule-based Segments + +