nodejs-datastore icon indicating copy to clipboard operation
nodejs-datastore copied to clipboard

Do not clutter the logs with warnings in prod environment

Open vicb opened this issue 2 years ago • 7 comments

The following code

 const companyQuery = query
   .filter('name', 'Google')
   .filter('size', '<', 400);

will print a warning:

process.emitWarning(
  'Providing Filter objects like Composite Filter or Property Filter is recommended when using .filter'
);

First I don't think there should be any warning in a prod environment. One way js libraries check for prod environemnt is to check if the NODE_ENV environment variable is set to production - see the express docs for ref.

Also my understanding is that the warning is there because of nested composite filters. I don't think there should be any warnings in a simple case, that is:

const companyQuery = query.filter('name', 'Google');

should probably not generate a warning even in dev env.

/cc @danieljbruce

vicb avatar May 04 '23 18:05 vicb

Datastore in Python emits this warning too so whatever we end up doing there should probably be consistency across the board.

danieljbruce avatar May 04 '23 19:05 danieljbruce

I am not familiar with Python warnings but it looks like you can at least filter the warnings

vicb avatar May 04 '23 19:05 vicb

This is what I mean:

image

It would be great to filter out all the noise in my prod env.

Thanks!

vicb avatar Jun 25 '23 06:06 vicb

What should be done not to get this warning when building a query with filters?

According to docs there are two ways of filtering a query, with operator and without (defaults to equals). So, how could we build and supply a Filter object?

MiguiTE avatar Jun 29 '23 08:06 MiguiTE

It looks like the doc is not up to date. The filter method can now take objects. You can look at the tests for an example.

That being said I think using the legacy way (with and without operator) should still be supported and should not log a warning at least in production mode.

vicb avatar Jun 29 '23 13:06 vicb

Using PropertyFilter eliminates the warning.

import { Datastore, PropertyFilter } from '@google-cloud/datastore'
const ds = new Datastore()
const query = ds.createQuery('Kind')
.filter(new PropertyFilter('foo', '=', 'bar'))
.filter(new PropertyFilter('baz', '=', 'quux'))

efossvold avatar Jul 05 '23 12:07 efossvold

@efossvold read my initial message. I said I don't think we should be forced to do that for simple case because there is no point. Thanks for trying to help though.

vicb avatar Jul 05 '23 12:07 vicb