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
Kafka circulars #2248
base: main
Are you sure you want to change the base?
Kafka circulars #2248
Conversation
The build job is failing with C++ compilation errors when building cpp-zst-node16-fork. Based on the compilation errors, I suspect that fixing it might be as simple as adding As for the binding path issues, the fundamental problem is that this Zstandard compressor/decompressor library contains a native Node addon which is our bundler (esbuild) does not know how to handle. I think it should be sufficient to copy the native addons to the appropriate build output directory in https://github.com/nasa-gcn/gcn.nasa.gov/blob/main/esbuild.js. However, given the installation challenges, it may be worthwhile checking if there is a pure JavaScript or a WASM implementation of Zstandard that we could use instead, which would be trivial to install and bundle/tree-shake correctly. |
I think I got it working. The esbuild solution was a much easier find than the previous issues I was encountering. I adapted this https://esbuild.github.io/content-types/#file based on a comment I came across somewhere. Edit: I am unsure about how this will function when deployed, there is a generated file that may need to be in a different directory than where it is currently getting placed |
Marked as ready too soon, need to fix something else first |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than add a new Lambda, I would rather that we use the existing Lambda in app/table-streams/circulars. Look at app/scheduled/circulars for ideas about how to structure it. I imagine something roughly like:
// app/table-streams/circulars/actions/search.ts
export async function searchAction(...) {
...
}
// app/table-streams/circulars/actions/kafka
export async function kafkaAction(...) {
}
// app/table-streams/circulars/index.ts
import { kafkaAction } from './actions/kafka'
import { searchAction } from './actions/search'
import { createTriggerHandler } from '~/lib/lambdaTrigger.server'
export const handler = createTriggerHandler(
async (record: DynamoDBRecord) => {
Promise.all([kafkaAction, searchAction].map((action) => action(record)))
}
)
249c85c
to
fcc7e83
Compare
app/lib/kafka.server.ts
Outdated
await producer.connect() | ||
await producer.send({ | ||
topic, | ||
messages: [ | ||
{ | ||
key: 'message', | ||
value: JSON.stringify(circular), | ||
}, | ||
], | ||
}) | ||
await producer.disconnect() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please close the Kafka connection only when the Lambda runtime is terminating. That way we can amortize the cost of opening the connection across multiple Lambda invocations, only paying it once per cold start.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this best done by not calling the disconnect?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably should call disconnect when the Lambda runtime is terminating gracefully. For Python Lambdas, AWS sends a SIGTERM signal to the function. The documentation doesn't say that it does that for Node.js Lamdbas, but it probably does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be a useful example, I will see if I can implement something similar
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I have something in the latest commit that should work. The listener gets added in, but locally there is no SIGTERM in sandbox. I'm not 100% confident in this implementation, but it should work
Does this work now? |
Co-authored-by: Leo Singer <leo.p.singer@nasa.gov> Consolidate handlers Update esbuild to not put the generated .node file in build directory package lock Adds circulars option to UI undo some moved code, document vars, update domain to use hostname Domain functions, trying to hook into SIGTERM Update test domain updates and reorder kafka function args memoizee Clean up Kafka sending - Type safety for getHostname - Memoize Kafka producer connection, disconnect before exit - Rename sendKafka to send --- it's implicit in the filename that this function sends Kafka records
…-directories Copy node API modules to output dirs using an esbuild plugin
@dakota002, does this work now? Note that you will need #2296 so that our build pipeline installs libraries for the correct OS and CPU. |
I need to commit some of my local changes and run some testing on this, but I will let you know shortly! It was working as expected before these updates too |
@lpsinger This still doesn't disconnect locally. It may work when deployed though since there will be different emitted events and not just an invoked function |
Does it disconnect locally if you hook into the SIGTERM signal? |
Description
Adds a table-streams event for Circulars over Kafka
This is currently a draft as there is either an issue in a dependency (possibly in cpp-zst-node16-fork or bindings) or in how we are building out these table-streams functions that is causing errors.
Currently investigating how cpp-zst-node16-fork uses the bindings package and why it works in some projects and not others
Related Issue(s)
Resolves #686
Testing
To get this to work in local dev setting there are a few things that need to be modified under node_modules:
@remix-run/dev/dist/devServer_unstable/index.js
-> line 139 setsstdio: pipe
, change this toin order to use the plugin-lambda-invoker. Relates to remix-run/remix#9293
Add the following lines to thetry
array defined on thedefaults
object inbindings/bindings.js
(currently trying to resolve this):Once those are in place, test by:
i
to trigger the invokerEdit: I may have resolved the zstd issue