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

Not able to retreive log entries #1411

Open
deama opened this issue Apr 21, 2023 · 1 comment · May be fixed by #1482
Open

Not able to retreive log entries #1411

deama opened this issue Apr 21, 2023 · 1 comment · May be fixed by #1482
Assignees
Labels
api: logging Issues related to the googleapis/nodejs-logging API. priority: p3 Desirable enhancement or fix. May not be included in next release. type: question Request for information or clarification. Not an issue.

Comments

@deama
Copy link

deama commented Apr 21, 2023

So I have the following function here:

const functions = require('@google-cloud/functions-framework');
const { Storage } = require('@google-cloud/storage');
const readline = require('readline');
const { Logging } = require('@google-cloud/logging');
const storage = new Storage();
const logging = new Logging();

async function searchLogs(date, timeStart, timeEnd, user) {
  const logFilter = `logName="timestamp>="2023-03-01T11:55:00Z" AND timestamp<="2023-03-03T11:55:51Z"`;
  const resourceNames = ['projects/production-logs'];
  const [entries] = await logging.getEntries({ resourceNames, filter: logFilter });

  console.log(`Searching logs with filter: ${logFilter}`);
  console.log(`Found ${entries.length} entries.`);

  for (const entry of entries) {
    const message = entry.data.jsonPayload.message;
    const ipAddress = message.match(/Ip Address:\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/);
    if (ipAddress) {
      return ipAddress[1];
    }
  }

  console.log(`----`);
  return null;
}

//... rest of code

What I'm having an issue is I have my production logs stored in a logging bucket called "prod", however the above code only works on the project scope rather than on a per-bucket scope, so it basically can't find the logs, because it can't see the logging bucket.

Is there a way to direct it so that it sends the request to a specific logging bucket? I can't find much online, and I have found a function in the source code for the loggin API about retreiving a list of logging buckets in the project, which works, but how do I set it to use that bucket now?

Btw, I hardcoded the timestamp for now to keep it simple.

@product-auto-label product-auto-label bot added the api: logging Issues related to the googleapis/nodejs-logging API. label Apr 21, 2023
@deama deama closed this as completed Apr 24, 2023
@deama deama reopened this Apr 24, 2023
@deama
Copy link
Author

deama commented Apr 24, 2023

I've tried setting the resourceNames to view:

const resourceNames = ['projects/production-logs/locations/global/buckets/prod/views/_AllLogs'];

And whilst that is what is said in the documentation:
https://github.com/googleapis/nodejs-logging/blob/main/src/v2/logging_service_v2_client.ts
[line 772]

    • projects/[PROJECT_ID]/locations/[LOCATION_ID]/buckets/[BUCKET_ID]/views/[VIEW_ID]

It compiles fine, and it gives me the entries, however if I now try and make a filter specific to the bucket in question, e.g a filter that only that bucket should contain, it gives me 0 entries, even though manually checking it displays actual entries.
So looks like it still applies the getEntries on the project only rather than the logging bucket.

@losalex losalex added priority: p2 Moderately-important priority. Fix may not be included in next release. type: question Request for information or clarification. Not an issue. labels May 31, 2023
@losalex losalex removed their assignment Jul 3, 2023
@triplequark triplequark added priority: p3 Desirable enhancement or fix. May not be included in next release. and removed priority: p2 Moderately-important priority. Fix may not be included in next release. labels Oct 4, 2023
@Colt45s Colt45s linked a pull request Jan 18, 2024 that will close this issue
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: logging Issues related to the googleapis/nodejs-logging API. priority: p3 Desirable enhancement or fix. May not be included in next release. type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants