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

PubSub: PubSubOptions.eventFilters not creating a filter #1475

Closed
d7p opened this issue Oct 24, 2023 · 4 comments
Closed

PubSub: PubSubOptions.eventFilters not creating a filter #1475

d7p opened this issue Oct 24, 2023 · 4 comments

Comments

@d7p
Copy link

d7p commented Oct 24, 2023

Related issues

colerogers.change-eventfilters
dl-cf3v2-eventfitlers
colerogers.change-eventfilters
dl-cf3v2-cc-efs

[REQUIRED] Version info

node: v18.12.1

firebase-functions: 4.4.1

firebase-tools: 12.7.0

firebase-admin: 11.11.0

[REQUIRED] Test case

import { onMessagePublished, PubSubOptions, } from "firebase-functions/v2/pubsub"; exports.specialMessageListener = onMessagePublished( { topic: "myTopic", region: region, eventFilters: [ { attributes: "type", value: "specialMessage", }, ], } , myFunctionToHandleSpecialMessages ); function myFunctionToHandleSpecialMessages( event: CloudEvent<MessagePublishedData<any>> ): void { console.log(event.data.message.attributes); }

[REQUIRED] Steps to reproduce

create a function as below:
exports.specialMessageListener = onMessagePublished(
{
topic: "myTopic",
region: region,
eventFilters: [
{
attributes: "type",
value: "specialMessage",
},
],
} ,
myFunctionToHandleSpecialMessages
); `

Deploy the function. check the pubsub topic subscription details.

[REQUIRED] Expected behavior

when firebase is deployed the subscription filter is set and the firebase function only recives messages that match the subscription filter
Screenshot 2023-10-24 at 14 41 14

[REQUIRED] Actual behavior

The filter is not set and the function is triggered on all pubsub messages sent to the topic
Screenshot 2023-10-24 at 13 58 18

Were you able to successfully deploy your functions? yes

I don't think this is a bug so much as missing docs on how to add a filter to a pubsub subscription from firebase.
I have tried several ways to set the eventFilter and either I get a typescript error or the functions deploy but missing the filtters (see screen shoot under actual behavior).
In the docs the description is just says TODO (see below)
Screenshot 2023-10-24 at 13 59 03

@taeold has several merges in firebase tools and functions repos that suggest the format should be like:
eventTrigger: { eventType: "pubsub_event", eventFilter: [ { attribute: "resource", value: "my-storage-bucket", }. { attribute: "appId", value: "12345", }. ] }

this is then supported by the extensions documentation that has the same structure in the yaml example however PubSubOptions nor EventHandlerOptions don't have eventTrigger as a option. I have tried using eventFilter in the the PubSubOption like:

onMessagePublished( { topic: "myTopic", region: region, eventFilters: [ { attributes: "type", value: "specalMessage", }, ], } , myFunctionToHandleSpecalMessages );

This deploys fine but it doesn't set the filter. I have tried several other ways to set the filter with no luck. Can you help with an example of what I have missed please.

Thank you for the help.

@google-oss-bot
Copy link
Collaborator

I found a few problems with this issue:

  • I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
  • This issue does not seem to follow the issue template. Make sure you provide all the required information.

@Berlioz
Copy link
Contributor

Berlioz commented Oct 26, 2023

The EventFilter is an implementation detail of the EventArc trigger which is backing a pubsub function. Setting the topic of a pubsub function causes the SDK to generate an EventTrigger containing that topic as its EventFilter; the PubSubOptions struct doesn't contain a field for eventFilter because it wouldn't do anything.

The code you saw that @taeoid wrote likely covers the EventArc integration or is test cases for it.

@Berlioz Berlioz closed this as completed Oct 26, 2023
@d7p
Copy link
Author

d7p commented Oct 30, 2023

PubSubOptions extends options.EventHandlerOptions that has:

eventFilters?: Record<string, string | Expression<string>>;
eventFilterPathPatterns?: Record<string, string | Expression<string>>;

the SDK doesn't add a filter at all (as far as i can see) it creates the subscription to the topic but ignores the filter ( see the screen shots)

@d7p
Copy link
Author

d7p commented Nov 6, 2023

HI @Berlioz
you reply doesn't make sense given that the PubSubOption class extends the EventHandlerOptions and no filter is set at all when the functions are deployed. see my original question and follow up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants