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

Allow the process manager to configure log files count and sizes #1067

Merged
merged 6 commits into from
Oct 11, 2024

Conversation

tahini
Copy link
Collaborator

@tahini tahini commented Sep 25, 2024

  • Use named objects instead of ordinal parameters for the numerous function parameters. This makes a call more readable, make it easier to fine-tune specific parameters while keeping the default values for others, and will make adding yet more parameters simpler.

  • Let ProcessManager support log file count and size as extra parameter

  • Let TrRoutingProcessManager support log file count and size as extra parameter. startBatch now also supports the debug option.

  • Add tests for the new functionalities

Copy link
Contributor

@samuel-duhaime samuel-duhaime left a comment

Choose a reason for hiding this comment

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

Good.

@tahini
Copy link
Collaborator Author

tahini commented Sep 25, 2024

I added the possibility to configure the log files and whether to run in debug in the config file by default, with always the possibility to override in individual calls, but we don't support it yet.

@greenscientist fwiw we can now allow more log files and of larger sizes in our instances and we could support running in debug in some instances if required, batch and not batch separately.

@greenscientist
Copy link
Collaborator

Kinda wondering if we should just strip all this out and let the standard OS tools handle log management.

@greenscientist
Copy link
Collaborator

@tahini, as-tu regardé si il existait des modules standard pour gérer tout ça ?

@tahini
Copy link
Collaborator Author

tahini commented Oct 1, 2024

@tahini, as-tu regardé si il existait des modules standard pour gérer tout ça ?

C'est ce que winston fait, on peut envoyer les logs où on veut. Ceci a l'avantage que qqn qui fait rouler Transition peut contrôler le logging. Si on laisse l'OS faire, il faudrait documenter la procédure ou configurer un autre outil séparément.

tagName,
serviceName,
nbFiles = 1,
maxFileSizeKb = 1000
Copy link
Collaborator

Choose a reason for hiding this comment

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

The number here should be a constant

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also why use kilo instead if simply bytes.

The Kb is confusing, it should be KB if you want bytes, Kb would usually means bits

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, a bit unreleated, but 1 meg is probably a bit small to be the default value. Thoughts?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's the current default... fwiw, these values are to keep the current behavior, again fwiw...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Defaults to 3 files of 5MB each now, for the processManager and specifically for trRouting as well

cwd?: string;
attemptRestart?: boolean;
logFiles?: {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we realely need a struct in a struct? This make calling the function a bit more complex with useful reason.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Debatable, but I'll say that one can leave it blank if they will, but if they want to set it, they'll want to handle the "log file" concept separately form the other 10 parameters that we set, so it might as well be a struct.

@@ -14,6 +14,13 @@ import config from '../../config/server.config';
// Set 2 threads as default, just in case we have more than one request being handled
const DEFAULT_THREAD_COUNT = 2;

type StartParameters = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add a command to mention what is that type and where it will be used.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If it's of general use it should be in the ProcessManager file. Otherwise it whould be named TrRouting something...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done, this is for the TrRotuingProcessManager only

{
debug = false,
cacheDirectoryPath,
// Flag to enable the trRouting connection cache for all scenario
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it possible to keep the comment after the param to make it clear to which entry it's related.

const port = parameters.port || Preferences.get('trRouting.port');
const cacheAllScenarios =
config.trRoutingCacheAllScenarios === undefined ? false : config.trRoutingCacheAllScenarios;

const params: Parameters<typeof startTrRoutingProcess>[3] = {
debug: parameters.debug,
cacheDirectoryPath: parameters.cacheDirectoryPath,
cacheAllScenarios: cacheAllScenarios
cacheAllScenarios: cacheAllScenarios,
logFiles: parameters.logFiles
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure it's a good idea of expose the logFiles setting externally. We should know what we expect here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Another option for this PR would be to simply put the winston config in the config.js file (maybe not exactly the config, but something tha twill allow us to easily build that config). That would avoid all the parameter passing, each service can get its log configuration and we won't have to add too much when we want to support something else than log files.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I updated so log files are only configurable through the config, there's no use case for individually setting it.

@@ -17,6 +17,19 @@ module.exports = {

// Enable caching of connections for all scenarios in trRouting. Will use more memory
trRoutingCacheAllScenarios: false,
// Extra options for running trRouting
Copy link
Collaborator

Choose a reason for hiding this comment

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

We if add a config block for trRouting, then we need to move the cacheAllFlag inside of it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We should also move the port number there.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done in previous PR

The `startProcess` function receives 8 arguments as parameter, that's a
lot and difficult to read when calling the function. Adding more
arguments will only get more difficult. So we switch to named arguments
instead.
Add an argument `logFiles` in the ProcessManager's `startProcess`
function. This argument takes the maximum size in kilobytes of the
log files and the maximum number of desired files.
…eparately

The `TrRoutingStartParameterss` type contains all the extra parameter of
the various start functions, so this type can be re-used in all
functions (`start`, `restart` and `startBatch`).

All but the first argument of the `startBatch` function is now part of a
unique object with named arguments, adding the `debug` parameters.
@tahini
Copy link
Collaborator Author

tahini commented Oct 10, 2024

@greenscientist I rebase and updated to address all your comments. With this, next time we need to investigate some trRouting related errors, we'll be ready to configure debug and logging in our instances.

Copy link
Collaborator

@greenscientist greenscientist left a comment

Choose a reason for hiding this comment

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

One last question.

@@ -12,6 +12,8 @@ import serviceLocator from 'chaire-lib-common/lib/utils/ServiceLocator';
import ProcessUtils from './ProcessUtils';

const PID_DIRECTORY = 'pids';
const DEFAULT_LOG_FILE_COUNT = 3; // 3 files
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't those be removed in the last commit, now that we have default in the config file???

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The config is only for trRouting, this is the main process manager and applies to all possible processes to start.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we combine those constant somehow? Can the trRouting default config information use those constant ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Moved to the config file

This adds a `debug` and `logs` configuration option to the
TrRoutingConfig type. They can be configured on the `config.js` used in
the project.

`debug` is a boolean option specifying whether to start the trRouting
process in debug mode

`logs` configures the loggins of the trRouting process. Currently, the
options that can be set are `maxFileSizeKB` for the maximum size of a
log file in kilobytes and `nbFiles` to specify the number of log files
to keep.

They can be set separately for the batch or single instance. These
onfigurations are optional.

Move the default log file count and size to the config instead of the
`ProcessManager.ts` file.
@tahini tahini merged commit ed91875 into chairemobilite:main Oct 11, 2024
6 checks passed
@tahini tahini deleted the processManagerLogFiles branch October 11, 2024 17:42
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.

3 participants