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

check workflow config for 'dmrpp' key if collection doesn't have it #25

Merged
merged 2 commits into from
Jan 5, 2022

Conversation

michaeljb
Copy link
Contributor

@michaeljb michaeljb commented Dec 21, 2021

This allows putting the dmrpp config in the workflow to facilitate using the same config for many collections, and any collections that will be different can still have their own configuration.

As a quick test, I added a bit more logging in nsidc@8fe1af6 to dump out the different possible dmrpp configs, and show which one that the code chooses. The CloudWatch screenshots show that the correct config is picked* (which is the third one logged in each of these screenshots).

*note: they also show some log messages being duplicated when I ran the next trial quickly; it seems that the underlying Logger instance from the CumulusLogger persists between runs, and when the DMRPPGenerator instance is created, the CumulusLogger creation grabs the same underlying Logger, and adds another handler to it resulting in duplicate messages; I'm surprised the Logger manages to hang around, but I suspect this duplication could be removed by adding a check in CumulusLogger.__init__ to only add a handler iff one isn't already present (edit to add: I have put in a PR to CMA to address this: nasa/cumulus-message-adapter-python#43)

Screenshots

with no dmrpp key anywhere

both empty

collection has dmrpp key

just collection

workflow has dmrpp key

just workflow

both collection and workflow have a dmrpp key, collection config is used

both set

workflow has dmrpp key and value, collection has dmrpp key and value of {}

"dmrpp": {} in the collection overrides whatever dmrpp was in the workflow; note the difference between this case and the case where the collection simply doesn't have a dmrpp key and so the workflow config is used

workflow with empty collection overriding

michaeljb added a commit to nsidc/cumulus-message-adapter-python that referenced this pull request Dec 21, 2021
This fixes the test added in the previous commit

Before this change, multiple calls to `CumulusLogger(name)` would construct a
`CumulusLogger` instance with the same underlying `Logger` instance, but each
construction would also create and attach a new handler, resulting in duplicate
messages, e.g.:

```
> python
>>> from cumulus_logger import CumulusLogger
>>> logger = CumulusLogger('test')
>>> logger.info('hello there')
{"message": "hello there", "timestamp": "2021-12-21T16:18:09.315309", "level": "info"}
>>>
>>> logger2 = CumulusLogger('test')
>>> logger2.info('hello there')
{"message": "hello there", "timestamp": "2021-12-21T16:18:16.845070", "level": "info"}
{"message": "hello there", "timestamp": "2021-12-21T16:18:16.845070", "level": "info"}
>>>
>>> logger.info('hello there')
{"message": "hello there", "timestamp": "2021-12-21T16:18:18.165564", "level": "info"}
{"message": "hello there", "timestamp": "2021-12-21T16:18:18.165564", "level": "info"}
```

See also the screenshots on
ghrcdaac/dmrpp-file-generator-docker#25

With this change, a new handler is only constructed if the underlying `Logger`
does not already have any handlers, preventing messages from being handled more
than once:

```
> python
>>> from cumulus_logger import CumulusLogger
>>> logger  = CumulusLogger('test')
>>> logger.info('hello there')
{"message": "hello there", "timestamp": "2021-12-21T16:33:56.735453", "level": "info"}
>>>
>>> logger2 = CumulusLogger('test')
>>> logger2.info('hello there')
{"message": "hello there", "timestamp": "2021-12-21T16:34:03.887972", "level": "info"}
>>>
>>> logger.info('hello there')
{"message": "hello there", "timestamp": "2021-12-21T16:34:07.808415", "level": "info"}
```
@amarouane-ABDELHAK
Copy link
Contributor

Can you please add an example of adding dmrpp config using the workflow?

michaeljb added a commit to nsidc/dmrpp-generator that referenced this pull request Jan 4, 2022
@michaeljb
Copy link
Contributor Author

@amarouane-ABDELHAK I've added example configs to the two READMEs in dbd7b9c and ghrcdaac/dmrpp-generator#16. Thanks!

@michaeljb
Copy link
Contributor Author

@amarouane-ABDELHAK another question, if you don't think we'll be able to get this PR merged before PI Planning, would you be able to create a Jira ticket for this? NSIDC needs this functionality for NDCUM-683 and our scrum master wants to link our ticket to a GHRC ticket so the dependency is visible for planning. Thanks!

Copy link
Contributor

@amarouane-ABDELHAK amarouane-ABDELHAK left a comment

Choose a reason for hiding this comment

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

A welcome PR

@amarouane-ABDELHAK amarouane-ABDELHAK merged commit 0574f0a into ghrcdaac:master Jan 5, 2022
@michaeljb michaeljb deleted the workflow-dmrpp-config branch January 6, 2022 17:10
@amarouane-ABDELHAK
Copy link
Contributor

amarouane-ABDELHAK commented Jan 7, 2022 via email

michaeljb added a commit to nsidc/cumulus-message-adapter-python that referenced this pull request Feb 15, 2022
This fixes the test added in the previous commit

Before this change, multiple calls to `CumulusLogger(name)` would construct a
`CumulusLogger` instance with the same underlying `Logger` instance, but each
construction would also create and attach a new handler, resulting in duplicate
messages, e.g.:

```
> python
>>> from cumulus_logger import CumulusLogger
>>> logger = CumulusLogger('test')
>>> logger.info('hello there')
{"message": "hello there", "timestamp": "2021-12-21T16:18:09.315309", "level": "info"}
>>>
>>> logger2 = CumulusLogger('test')
>>> logger2.info('hello there')
{"message": "hello there", "timestamp": "2021-12-21T16:18:16.845070", "level": "info"}
{"message": "hello there", "timestamp": "2021-12-21T16:18:16.845070", "level": "info"}
>>>
>>> logger.info('hello there')
{"message": "hello there", "timestamp": "2021-12-21T16:18:18.165564", "level": "info"}
{"message": "hello there", "timestamp": "2021-12-21T16:18:18.165564", "level": "info"}
```

See also the screenshots on
ghrcdaac/dmrpp-file-generator-docker#25

With this change, a new handler is only constructed if the underlying `Logger`
does not already have any handlers, preventing messages from being handled more
than once:

```
> python
>>> from cumulus_logger import CumulusLogger
>>> logger  = CumulusLogger('test')
>>> logger.info('hello there')
{"message": "hello there", "timestamp": "2021-12-21T16:33:56.735453", "level": "info"}
>>>
>>> logger2 = CumulusLogger('test')
>>> logger2.info('hello there')
{"message": "hello there", "timestamp": "2021-12-21T16:34:03.887972", "level": "info"}
>>>
>>> logger.info('hello there')
{"message": "hello there", "timestamp": "2021-12-21T16:34:07.808415", "level": "info"}
```
markdboyd added a commit to nasa/cumulus-message-adapter-python that referenced this pull request Feb 15, 2022
* test_logger setup: allow kwargs to be forwarded to CumulusLogger constructor

* add failing test, each logger should only have one handler

* CumulusLogger: only create new handler if one is not present

This fixes the test added in the previous commit

Before this change, multiple calls to `CumulusLogger(name)` would construct a
`CumulusLogger` instance with the same underlying `Logger` instance, but each
construction would also create and attach a new handler, resulting in duplicate
messages, e.g.:

```
> python
>>> from cumulus_logger import CumulusLogger
>>> logger = CumulusLogger('test')
>>> logger.info('hello there')
{"message": "hello there", "timestamp": "2021-12-21T16:18:09.315309", "level": "info"}
>>>
>>> logger2 = CumulusLogger('test')
>>> logger2.info('hello there')
{"message": "hello there", "timestamp": "2021-12-21T16:18:16.845070", "level": "info"}
{"message": "hello there", "timestamp": "2021-12-21T16:18:16.845070", "level": "info"}
>>>
>>> logger.info('hello there')
{"message": "hello there", "timestamp": "2021-12-21T16:18:18.165564", "level": "info"}
{"message": "hello there", "timestamp": "2021-12-21T16:18:18.165564", "level": "info"}
```

See also the screenshots on
ghrcdaac/dmrpp-file-generator-docker#25

With this change, a new handler is only constructed if the underlying `Logger`
does not already have any handlers, preventing messages from being handled more
than once:

```
> python
>>> from cumulus_logger import CumulusLogger
>>> logger  = CumulusLogger('test')
>>> logger.info('hello there')
{"message": "hello there", "timestamp": "2021-12-21T16:33:56.735453", "level": "info"}
>>>
>>> logger2 = CumulusLogger('test')
>>> logger2.info('hello there')
{"message": "hello there", "timestamp": "2021-12-21T16:34:03.887972", "level": "info"}
>>>
>>> logger.info('hello there')
{"message": "hello there", "timestamp": "2021-12-21T16:34:07.808415", "level": "info"}
```

Co-authored-by: Michael Brandt <michaelbrandt5@gmail.com>
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.

None yet

2 participants