Add TTFB metric logic and report it to cloudflare analytics#33
Add TTFB metric logic and report it to cloudflare analytics#33ankur12-1610 wants to merge 1 commit intofilbeam:mainfrom
Conversation
|
Thank you for the pull request, @ankur12-1610 .
That's not correct. Submitting the TTFB data to CF analytics is only the first step, the next step is to visualise them in our dashboards. I updated the description. I am not familiar with CF analytics, don't we need some sort of authentication for writing data? Or does the URL in @juliangruber We were discussing using InfluxDB for these analytics. Do you have an opinion whether we are okay to use CF analytics instead?
Thoughts? |
|
I'm fine with CF analytics, or at least I don't have any concerns for now |
Hey @bajtos, yes—you’re right, this is just the first step of the issue. I wanted to make sure this part was set up correctly before moving on. I’ve set up a worker that’s public and accepts any request, then writes the dataset (for testing purpose, which I'll be changing to some kind of secret key based authorisation, after this comment): // analytics-worker.js
var analytics_worker_default = {
async fetch(request, env) {
if (request.method !== "POST") {
return new Response("Send POST with TTFB data", { status: 405 });
}
try {
const data = await request.json();
env["analytics-engine"].writeDataPoint({
blobs: data.blobs, // [url, location, client, cid]
doubles: data.doubles // [ttfb, status, bytes]
});
return new Response(JSON.stringify({ success: true }), {
headers: { "Content-Type": "application/json" }
});
} catch (error) {
return new Response(JSON.stringify({
success: false,
error: error.message
}), {
status: 500,
headers: { "Content-Type": "application/json" }
});
}
}
};
export {
analytics_worker_default as default
}; |
This is IMO adding too much complexity. InfluxDB is simpler to set up because it provides an HTTP API for writing data points. However, I don't feel too strongly about this. If @juliangruber thinks it's fine to add another worker to record data points to Workers Analytics Engine, then I am okay with following your lead. I suggest starting with a pull request creating the worker recording data points, so that we can discuss the desired API & request body format, before we move to changing the bot to submit data points via that new API. |
|
I'm fine adding a new worker, I don't see worker count as a decisive factor at this point. +1 to opening a PR for the worker, so we can discuss the full scope of the implementation |
|
Should I keep the worker code in the new PR as it is: or should I update it to use secret-based authentication? |
|
Let's discuss in that PR please |
@juliangruber @bajtos created a new PR, please take a look at #34 |
See filbeam/roadmap#76