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

Plugins: update how investUsageLogger gets port information #1691

Merged
merged 4 commits into from
Nov 21, 2024

Conversation

dcdenu4
Copy link
Member

@dcdenu4 dcdenu4 commented Nov 20, 2024

Description

Since we're now managing multiple invest servers on different ports, we're storing related port information in the settingsStore config. investUsageLogger was still using process.env.PORT. This PR attempts to transition that to the new setup.

I'd love some feedback and input on how to manage this. The solution I have here works, but feels a little tacked on. I couldn't think of a clean way for investUsageLogger to locally know if a plugin or core model was being run to get the port information there. So, I end up passing the port in to the start and exit functions from setupInvestHandlers.

@dcdenu4 dcdenu4 self-assigned this Nov 20, 2024
@@ -112,6 +114,7 @@ export function setupInvestRunHandlers() {
'run',
modelRunName,
`-d "${datastackPath}"`];
port = settingsStore.get('core.port');
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this solution is fine. I was wondering if we could always just use the core invest server for usage logging, even when running a plugin, but I see that natcap.invest.usage._log_model needs to import the model.

@@ -225,7 +225,8 @@ describe('createWindow', () => {
});

describe('investUsageLogger', () => {
const expectedURL = `http://127.0.0.1:${process.env.PORT}/api/log_model_start`;
Copy link
Contributor

Choose a reason for hiding this comment

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

I see that process.env.PORT is still being defined when we run yarn run test (see package.json). Maybe we can and should remove that from the yarn scripts if we're no longer using it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done in eeb6bfb

workbench/tests/main/main.test.js Show resolved Hide resolved
Copy link
Contributor

@davemfish davemfish left a comment

Choose a reason for hiding this comment

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

Thanks, @dcdenu4 , one small change requested here

@@ -8,10 +8,10 @@
"start": "yarn build-main && yarn build:preload && concurrently --kill-others \"yarn serve\" \"electron .\"",
"serve": "cross-env MODE=development node scripts/watch.js",
"lint": "eslint --cache --color --ext .jsx,.js src",
"test": "cross-env PORT=56788 jest --runInBand --testPathIgnorePatterns /tests/binary_tests/ /tests/sampledata_linkcheck/",
"test": "cross-env jest --runInBand --testPathIgnorePatterns /tests/binary_tests/ /tests/sampledata_linkcheck/",
Copy link
Contributor

Choose a reason for hiding this comment

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

cross-env is the program for setting environment variables in a cross-platform way, so we don't need that anymore.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch, I didn't realize they were related. updated in 5cc7ffe

Copy link
Member

@emlys emlys left a comment

Choose a reason for hiding this comment

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

Nothing to add to Dave's comments, I think this is a good solution. It could be a little cleaner to look up the port and pyModuleName in the settings store using the modelRunName - if modelRunName is in settingsStore.get('plugins'), then it's a plugin. There's an example of this on line 93 of setupInvestHandlers.js in the diff.

@dcdenu4
Copy link
Member Author

dcdenu4 commented Nov 21, 2024

Nothing to add to Dave's comments, I think this is a good solution. It could be a little cleaner to look up the port and pyModuleName in the settings store using the modelRunName - if modelRunName is in settingsStore.get('plugins'), then it's a plugin. There's an example of this on line 93 of setupInvestHandlers.js in the diff.

Thanks @emlys , I was looking into this for a solution because I thought it'd be cleaner too. But, for the exit function call we don't have access to pyModuleName, so it'd need to be passed in like it is for start. Or maybe we could have something like:

let port;
function start() {
  port = "logic to get port from pyModuleName";
}
function end(){
  "use port, which should be initialized by the time this call occurs";
}

@dcdenu4
Copy link
Member Author

dcdenu4 commented Nov 21, 2024

Thanks Dave, I see some tests failing related to GDAL 3.10, which we fixed in main. So, I'll go ahead and merge this and we can merge main in the future.

@dcdenu4 dcdenu4 merged commit f98f272 into natcap:feature/plugins Nov 21, 2024
21 of 29 checks passed
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