PubSub Dead Letter in a GCF - google-cloud-pubsub

I have a google cloud function triggered by PubSub, and I'm trying to forward an execution with error to a dead letter topic.
I am forcing an error:
throw Error('test')
And the function is finished with status error.
Ending a function with an error, should the message be forwarded to the Dead Letter topic?

When you bind your Cloud Function with PubSub directly, I mean, you use the --trigger-topic option when you deploy, some PubSub feature aren't available. It's the case for the Dead Letter topic, for the filtering and for the ordering key for example .
If you want to use these features, you need to deploy your function as HTTP function and to call it with a PubSub push subscription that you can customize as you which.
Be careful, the format of PubSub message in a HTTP push function isn't exactly the same as background function. The function signature also change a bit. You need to rework a few on your code before achieving the change.

Related

Handling errors in SYNC handler

I am interested in the best practice for handling errors in the Google Action SYNC handler.
I see in the docs that I can return an errorCode in the SYNC response, however, none of the documented error codes seem to be compatible with the SYNC handler, only QUERY, EXECUTE, etc.
I see that the SYNC response must contain a userAgentId or the Action service deems it an invalid response, however, what happens when I am unable to authenticate the user and I am unable to determine and ID for them?
In that case, should I simply provide an empty string for that property?
Should I just response with an empty object {} in the response when I encounter an error?
Any info is helpful, thanks.
Of all the listed error codes, not all of them may make sense but some like relinkRequired could be useful.
More specifically for you, in the case that the authentication process fails that error should come from the OAuth link. Your account linking, when presented with an incorrect user, should fail at that point and not proceed with sending a SYNC response.

Why webhook never finishes after calling Slack in Azure LogicApps?

I have LogicApps and trying to do Webhook to Slack.
I understood that webhook is done by giving a single URL to the webbook.
I can successfully post messages to the Slack channel. No errors.
However, the pipeline never completes. It is running forever unless I cancel it. I wonder why?
We discovered that this is due to one of the following causes after testing it in our environment.
The subscribe-URL for Webhooks :
We've seen the identical issue you're getting when there isn't a correct link supplied.
The body of the subscription :
The similar problem occurs when the structure of the JSON inside the body of the subscription is not properly organized.

App engine - raw request body - stripe webhooks

I'm trying to run my node.js app app engine and I am having trouble with stripe webhooks - with the constructEvent, that I need to give a request raw body. Worked on virtual machine but not on app engine.
event = stripe.webhooks.constructEvent(req.rawBody, sig, stripeKeys.webhookPaymentIntent);
Says:
No signatures found matching the expected signature for payload. Are you passing the raw request body you received from Stripe? https://github.com/stripe/stripe-node#webhook-signing
Just looking at the code that you posted here, I wonder if the last parameter is indeed the value that you wanted to pass to the constructEvent function. it reads webHookPaymentIntent. I wonder if this should really be the webhook signature secret? It may be that it really is the webhook secret value, but just named a bit misleadingly.
Maybe this is something though you can verify? A simple test would really to be to pass the string literal here to see if that would work first. Of course make sure not to commit that to any source control.
The stripe-node method params are listed here for reference: https://github.com/stripe/stripe-node/blob/1d6207e34f978d8709d42d8a05d7d7e8be6599c7/lib/Webhooks.js#L11

Google Cloud Pub/Sub - Stopped triggering push to endpoint

It was working fine till last day and suddenly stopped pushing to endpoint. Checked all settings including endpoint URL and found everything remains unchanged. Can you guys suggest possible causes.
Not receiving a message on a push endpoint could happen for many reasons. The first thing to do would be to go to Stackdriver and create a graph for the subscription/push_request_count metric. You can break this down by response_code to see how many requests Cloud Pub/Sub is sending to your push endpoint and what response codes it is returning. If there are requests being delivered that are returning errors, this graph will show that.
It might also be worth checking the publish side to ensure messages are still being published as expected. You can look at the topic/send_message_operation_count metric, which can also be broken down by response_code, to make sure the publish requests are all returning success.
You should also check to ensure the subscription still exists using the Pub/Sub Subscriptions page in the Cloud console. After 30 days of inactivity (including inability to successfully deliver a message to a push endpoint), subscriptions are potentially deleted.
If the issue still unsolved after those steps, it is best to contact Google Cloud support with your project ID and subscription name so that things can be investigated for your specific case.

Init and destroy function

I am still beginner with golang in Google Cloud Appengine (standard).
I want to use a function that is automatically call for the instance shutting down.
There is a function init called during startup.
Now I am looking for the opposite part like a destroy function.
Seems there is something like that for python, but could not find
anything for golang.
How could you realise such a destroy fuction in google appengine instances ?
This is documented at Go - How Instances are Managed.
Unfortunately the Go doc is incomplete, here's the link to the Pyton version: Python - How Instances are Managed. The way it is implemented / supported is language-agnostic.
When an instance is spin up, an HTTP GET request is sent to the /_ah/start path.
Before an instance is taken down, an HTTP GET request is sent to the /_ah/stop path.
You should use package init() functions for initialization purposes as that always runs, and only once. If a request is required for your init functions, then register a handler to the _/ah/start path.
And you may register a handler to /_ah/stop and implement "shutdown" functionality like this:
func init() {
http.HandleFunc("/_ah/stop", shutdownHandler)
}
func shutdownHandler(w http.ResponseWriter, r *http.Request) {
doSomeWork()
saveState()
}
But you can't rely on this 100%:
Note: It's important to recognize that the shutdown hook is not always able to run before an instance terminates. In rare cases, an outage can occur that prevents App Engine from providing 30 seconds of shutdown time. Thus, we recommend periodically checkpointing the state of your instance and using it primarily as an in-memory cache rather than a reliable data store.

Resources