Skip to content

Commit

Permalink
Merge pull request #7554 from tangledbytes/utkarsh/fix/analytics-coll…
Browse files Browse the repository at this point in the history
…ections

Fix NooBaa usagereports and endpointgroupreports collections
  • Loading branch information
tangledbytes authored Oct 16, 2024
2 parents b171929 + 73a0747 commit 8f1d6f8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/server/analytic_services/endpoint_group_report_indexes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
module.exports = [{
fields: {
start_time: 1,
aggregated_time: -1,
aggregated_time_range: 1,
end_time: 1,
group_name: 1,
},
options: {
unique: false,
}
}, ];
}];
7 changes: 4 additions & 3 deletions src/server/analytic_services/endpoint_stats_store.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,17 +167,17 @@ class EndpointStatsStore {

async get_endpoint_group_reports(params) {
dbg.log1('get_endpoint_group_reports', params);
const query = this._format_endpoint_gorup_report_query(params);
const query = this._format_endpoint_group_report_query(params);
return this._endpoint_group_reports.find(query);
}

async clean_endpoint_group_reports(params) {
dbg.log1('clean_endpoint_group_reports', params);
const query = this._format_endpoint_gorup_report_query(params);
const query = this._format_endpoint_group_report_query(params);
return this._endpoint_group_reports.deleteMany(query);
}

_format_endpoint_gorup_report_query(params) {
_format_endpoint_group_report_query(params) {
const { groups, since, till } = params;
const query = {};
if (groups) _.set(query, ['group_name', '$in'], _.castArray(groups));
Expand All @@ -196,6 +196,7 @@ class EndpointStatsStore {
group_name: report.endpoint_group,
};
const update = {
$set: selector,
$push: {
endpoints: _.pick(report, [
'hostname',
Expand Down
22 changes: 13 additions & 9 deletions src/server/analytic_services/usage_report_indexes.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
/* Copyright (C) 2016 NooBaa */
'use strict';

module.exports = [{
fields: {
start_time: 1,
aggregated_time: -1,
aggregated_time_range: 1,
},
options: {
unique: false,
module.exports = [
// There are many other fields in the table but this is a common denominator
// and the hot query uses only these fields.
{
fields: {
start_time: 1,
end_time: 1,
bucket: 1,
},
options: {
unique: false,
}
}
}, ];
];
3 changes: 3 additions & 0 deletions src/server/bg_services/usage_aggregator.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ async function background_worker() {
const till = moment().subtract(8, 'weeks').valueOf();
dbg.log0('Deleting reports older than', new Date(till));
await EndpointStatsStore.instance.clean_bandwidth_reports({ till });

// Clean endpoint group reports here as well?
await EndpointStatsStore.instance.clean_endpoint_group_reports({ till });
}

function _accumulate_bandwidth(acc, update) {
Expand Down

0 comments on commit 8f1d6f8

Please sign in to comment.