Skip to content
This repository was archived by the owner on Aug 13, 2026. It is now read-only.

fix: allow reading logs from non-project paths - #444

Merged
daniel-sanche merged 4 commits into
v3.0.0from
allow_alternative_resources_2
Dec 7, 2021
Merged

fix: allow reading logs from non-project paths#444
daniel-sanche merged 4 commits into
v3.0.0from
allow_alternative_resources_2

Conversation

@daniel-sanche

Copy link
Copy Markdown
Contributor

Previously, the entry-parsing code assumed all logs originated from a project, but the list_logs API allows reading from folders, organizations, and billingIds as well. If a user attempted to read from one of these non-project paths, the library would fail to build the LogEntry object and crash. This PR fixes that issue, and is more forgiving in its entry parsing logic.

Now, if a log is found with a parent path that does not represent the active project, the entry.logger field will be None.

Fixes#399

@daniel-sanche
daniel-sanche requested review from a teamNovember 12, 2021 23:17
@product-auto-labelproduct-auto-labelBot added the api: logging Issues related to the googleapis/python-logging API. label Nov 12, 2021
@google-clagoogle-claBot added the cla: yes This human has signed the Contributor License Agreement. label Nov 12, 2021
@daniel-sanchedaniel-sanche added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Nov 16, 2021
@yoshi-kokoroyoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Nov 16, 2021
@daniel-sanchedaniel-sanche added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Dec 2, 2021
@yoshi-kokoroyoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Dec 2, 2021
@daniel-sanchedaniel-sanche added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Dec 6, 2021
@yoshi-kokoroyoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Dec 6, 2021

@losalexlosalex left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Left some minor comments



def logger_name_from_path(path):
def logger_name_from_path(path, project=None):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: Perhaps I am not well familiar with Python, but is there a way to create another logger_name_from_path function with project parameter? I think that it would be better then having parameters with default values

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I think this is the Pythonic way to do it. Especially since this function is just directly calling another function. If it wasn't a public function already in use, I would prefer to remove this one altogether

What's the argument against default parameters?

logger_name = logger_name_from_path(logger_fullname, client.project)
logger = loggers[logger_fullname] = client.logger(logger_name)
except ValueError:
# log name is not scoped to a project. Leave logger as None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this comment true? Seems that logger is initialized with value returned from loggers.get(logger_fullname) call...

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

loggers.get(logger_fullname) will return None if the loggers dict doesn't contain logger_fullname

If it's None. Lines 171 to 173 will try to contruct a new logger associated with logger_name, which will work if logger_name is a project id. If it's an organization or a folder, it will throw an exception. In that case, we can just leave the logger as empty and move on

@daniel-sanche
daniel-sanche merged commit 898b5fe into v3.0.0Dec 7, 2021
@daniel-sanche
daniel-sanche deleted the allow_alternative_resources_2 branch December 7, 2021 21:40
@release-pleaserelease-pleaseBot mentioned this pull request Jan 27, 2022
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

api: loggingIssues related to the googleapis/python-logging API.cla: yesThis human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@daniel-sanche@losalex@yoshi-kokoro