Skip to content

Commit de25e5b

Browse files
authored
Add active series to all_user_stats page (#4972) (#4972)
Signed-off-by: songjiayang <[email protected]> Signed-off-by: songjiayang <[email protected]>
1 parent ddc56a0 commit de25e5b

File tree

8 files changed

+149
-88
lines changed

8 files changed

+149
-88
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* [ENHANCEMENT] Update Go version to 1.19.3. #4988
55
* [FEATURE] Querier/Query Frontend: support Prometheus /api/v1/status/buildinfo API. #4978
66

7+
* [FEATURE] Ingester: Add active series to all_user_stats page. #4972
8+
79
## 1.14.0 in progress
810

911
**This release removes support for chunks storage. See below for more.**

pkg/distributor/distributor.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,10 +1189,13 @@ func (d *Distributor) UserStats(ctx context.Context) (*UserStats, error) {
11891189
totalStats.APIIngestionRate += r.ApiIngestionRate
11901190
totalStats.RuleIngestionRate += r.RuleIngestionRate
11911191
totalStats.NumSeries += r.NumSeries
1192+
totalStats.ActiveSeries += r.ActiveSeries
11921193
}
11931194

1194-
totalStats.IngestionRate /= float64(d.ingestersRing.ReplicationFactor())
1195-
totalStats.NumSeries /= uint64(d.ingestersRing.ReplicationFactor())
1195+
factor := d.ingestersRing.ReplicationFactor()
1196+
totalStats.IngestionRate /= float64(factor)
1197+
totalStats.NumSeries /= uint64(factor)
1198+
totalStats.ActiveSeries /= uint64(factor)
11961199

11971200
return totalStats, nil
11981201
}
@@ -1231,6 +1234,7 @@ func (d *Distributor) AllUserStats(ctx context.Context) ([]UserIDStats, error) {
12311234
s.APIIngestionRate += u.Data.ApiIngestionRate
12321235
s.RuleIngestionRate += u.Data.RuleIngestionRate
12331236
s.NumSeries += u.Data.NumSeries
1237+
s.ActiveSeries += u.Data.ActiveSeries
12341238
perUserTotals[u.UserId] = s
12351239
}
12361240
}
@@ -1245,6 +1249,7 @@ func (d *Distributor) AllUserStats(ctx context.Context) ([]UserIDStats, error) {
12451249
APIIngestionRate: stats.APIIngestionRate,
12461250
RuleIngestionRate: stats.RuleIngestionRate,
12471251
NumSeries: stats.NumSeries,
1252+
ActiveSeries: stats.ActiveSeries,
12481253
},
12491254
})
12501255
}

pkg/distributor/http_admin.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const tpl = `
3030
<tr>
3131
<th>User</th>
3232
<th># Series</th>
33+
<th># Active Series</th>
3334
<th>Total Ingest Rate</th>
3435
<th>API Ingest Rate</th>
3536
<th>Rule Ingest Rate</th>
@@ -40,6 +41,7 @@ const tpl = `
4041
<tr>
4142
<td>{{ .UserID }}</td>
4243
<td align='right'>{{ .UserStats.NumSeries }}</td>
44+
<td align='right'>{{ .UserStats.ActiveSeries }}</td>
4345
<td align='right'>{{ printf "%.2f" .UserStats.IngestionRate }}</td>
4446
<td align='right'>{{ printf "%.2f" .UserStats.APIIngestionRate }}</td>
4547
<td align='right'>{{ printf "%.2f" .UserStats.RuleIngestionRate }}</td>

pkg/distributor/http_server.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type UserStats struct {
1212
NumSeries uint64 `json:"numSeries"`
1313
APIIngestionRate float64 `json:"APIIngestionRate"`
1414
RuleIngestionRate float64 `json:"RuleIngestionRate"`
15+
ActiveSeries uint64 `json:"activeSeries"`
1516
}
1617

1718
// UserStatsHandler handles user stats to the Distributor.

pkg/ingester/client/ingester.pb.go

Lines changed: 124 additions & 83 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/ingester/client/ingester.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ message UserStatsResponse {
9797
uint64 num_series = 2;
9898
double api_ingestion_rate = 3;
9999
double rule_ingestion_rate = 4;
100+
uint64 active_series = 5;
100101
}
101102

102103
message UserIDStatsResponse {

pkg/ingester/ingester.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,7 +1553,7 @@ func (i *Ingester) UserStats(ctx context.Context, req *client.UserStatsRequest)
15531553
return &client.UserStatsResponse{}, nil
15541554
}
15551555

1556-
return createUserStats(db), nil
1556+
return createUserStats(db, i.cfg.ActiveSeriesMetricsEnabled), nil
15571557
}
15581558

15591559
// AllUserStats returns ingestion statistics for all users known to this ingester.
@@ -1573,20 +1573,27 @@ func (i *Ingester) AllUserStats(_ context.Context, _ *client.UserStatsRequest) (
15731573
for userID, db := range users {
15741574
response.Stats = append(response.Stats, &client.UserIDStatsResponse{
15751575
UserId: userID,
1576-
Data: createUserStats(db),
1576+
Data: createUserStats(db, i.cfg.ActiveSeriesMetricsEnabled),
15771577
})
15781578
}
15791579
return response, nil
15801580
}
15811581

1582-
func createUserStats(db *userTSDB) *client.UserStatsResponse {
1582+
func createUserStats(db *userTSDB, activeSeriesMetricsEnabled bool) *client.UserStatsResponse {
15831583
apiRate := db.ingestedAPISamples.Rate()
15841584
ruleRate := db.ingestedRuleSamples.Rate()
1585+
1586+
var activeSeries uint64
1587+
if activeSeriesMetricsEnabled {
1588+
activeSeries = uint64(db.activeSeries.Active())
1589+
}
1590+
15851591
return &client.UserStatsResponse{
15861592
IngestionRate: apiRate + ruleRate,
15871593
ApiIngestionRate: apiRate,
15881594
RuleIngestionRate: ruleRate,
15891595
NumSeries: db.Head().NumSeries(),
1596+
ActiveSeries: activeSeries,
15901597
}
15911598
}
15921599

pkg/ingester/ingester_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3193,6 +3193,7 @@ func Test_Ingester_AllUserStats(t *testing.T) {
31933193
NumSeries: 3,
31943194
ApiIngestionRate: 0.2,
31953195
RuleIngestionRate: 0,
3196+
ActiveSeries: 3,
31963197
},
31973198
},
31983199
{
@@ -3202,6 +3203,7 @@ func Test_Ingester_AllUserStats(t *testing.T) {
32023203
NumSeries: 2,
32033204
ApiIngestionRate: 0.13333333333333333,
32043205
RuleIngestionRate: 0,
3206+
ActiveSeries: 2,
32053207
},
32063208
},
32073209
}

0 commit comments

Comments
 (0)