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

[DO NOT MERGE]Add environment variables for stats config (#1627) #1628

Closed
wants to merge 7 commits into from

Conversation

rg2011
Copy link
Contributor

@rg2011 rg2011 commented Jul 26, 2024

Adds environment variables for stats configuration (fixes #1627).

NOTE: Adds documentation for config.stats.persistence, that seemed to be undocumented.

NOTE: Changed to DO NOT MERGE because of #1627 (comment)

@rg2011 rg2011 changed the title aFixes issue #1627 Add environment variables for stats config (#1627) Jul 26, 2024
doc/admin.md Outdated
@@ -162,11 +162,12 @@ support nulls or multi-attribute requests if they are encountered.
#### `stats`

It configures the periodic collection of statistics. Use `interval` in milliseconds to set the time between stats
writings.
writings. The `persistence` flag stores stats in the mongo backend.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great to provide more detail on this. For instance:

  • In which collection at mongo backend are the stas persisted?
  • How are the documents in that collection? Which fields they have? An example would be also great

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@AlvaroVega
Copy link
Member

AlvaroVega commented Jul 30, 2024

@rg2011 Is this PR including all feature? if feature is already implemented any link to paths involved or doc related is welcome!

@rg2011
Copy link
Contributor Author

rg2011 commented Jul 30, 2024

@rg2011 Is this PR including all feature? if feature is already implemented any link to paths involved or doc related is welcome!

The stats.persistence flag and kpis mongo collection were actually added in commit fd1354b 9 years ago (!?).

So the feature was already present, this PR only exposes its configuration through environment variables.

I also added some documentation for the stats.persistence parameter that I dind't find mentioned elsewhere, the documentation I wrote was derived from the code in:

  • if (
    (currentConfig.deviceRegistry && currentConfig.deviceRegistry.type === 'mongodb') ||
    (currentConfig.stats && currentConfig.stats.persistence === true)
    ) {
    : Creates a dbConn if stats.persistence is true
  • function mongodbPersistence(currentValues, globalValues, callback) {
    const statStamp = _.clone(globalValues);
    statStamp.timestamp = new Date().toISOString();
    dbService.db.collection('kpis').insertOne(statStamp, callback);
    }
    : Uses collection kpis for stats, dumps global stats as mongo document.

However, it seems that setting stats.persistence is not enough to enable stats persistence. activateStatLogs does not check the flag at all, and will never schedule the mongodbPersistence action:

function activateStatLogs(newConfig, callback) {
if (newConfig.stats && newConfig.stats.interval) {
async.series(
[
apply(statsRegistry.globalLoad, {
deviceCreationRequests: 0,
deviceRemovalRequests: 0,
measureRequests: 0
}),
apply(statsRegistry.addTimerAction, statsRegistry.logStats)
],
callback
);
} else {
callback();
}
}

So if an user wants stats persisted to mongo , in addition to defining stats.persistence, it must also schedule an statsRegistry.addTimerAction(statsRegistry.mongodbPersistence, ...) as done here:

statsService.addTimerAction(statsService.mongodbPersistence, function () {

I will add this to the documentation.

@rg2011 rg2011 changed the title Add environment variables for stats config (#1627) [WIP] [DO NOT MERGE] Add environment variables for stats config (#1627) Jul 30, 2024
@rg2011 rg2011 changed the title [WIP] [DO NOT MERGE] Add environment variables for stats config (#1627) Add environment variables for stats config (#1627) Jul 30, 2024
@rg2011
Copy link
Contributor Author

rg2011 commented Jul 30, 2024

I will add this to the documentation.

0bb40cd

@AlvaroVega
Copy link
Member

The stats.persistence flag and kpis mongo collection were actually added in commit fd1354b 9 years ago (!?).

So the feature was already present, this PR only exposes its configuration through environment variables.

OMG! I'm pretty sure nobody has used this feature before, so I'm not sure if is fully implemented. Let's see.

@rg2011 rg2011 changed the title Add environment variables for stats config (#1627) [DO NOT MERGE]Add environment variables for stats config (#1627) Aug 1, 2024
@rg2011
Copy link
Contributor Author

rg2011 commented Aug 2, 2024

deprecated by #1629

@rg2011 rg2011 closed this Aug 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add environment variable for config.stats.interval
3 participants