Skip to content

Commit

Permalink
feat: use correctly how cursor work in AWS SDK (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tchoupinax authored May 18, 2024
1 parent 217a0d9 commit 1a2a902
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "s3-prometheus-exporter",
"version": "0.4.1",
"version": "0.5.0",
"description": "S3 data exporter for prometheus",
"author": "Tchoupinax <[email protected]> (https://corentinfiloche.xyz)",
"license": "MIT",
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ async function main (): Promise<void> {

const app = Fastify();
app.get("/metrics", async (_, reply: FastifyReply) => {
logger.info("Request received");
reply.header("Content-Type", register.contentType);
await queryS3(prefixedPlugins, globalPlugins);
return reply.send(await register.metrics());
Expand Down
10 changes: 8 additions & 2 deletions src/queryS3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { _Object, ListObjectsCommand, ListObjectsCommandInput, S3Client } from "
import config from "config";

import { Metric } from "./metrics/metric";
import logger from "./utils/logger";

const s3Client = new S3Client({
credentials: {
Expand Down Expand Up @@ -40,7 +41,12 @@ async function listAllContents (
let cursor : string | undefined;

while (shouldContinue) {
const params: ListObjectsCommandInput = { Bucket, Prefix };
logger.debug("Processing %s objects", list.length);

const params: ListObjectsCommandInput = {
Bucket,
Prefix,
};
if (cursor) {
params.Marker = cursor;
}
Expand All @@ -55,7 +61,7 @@ async function listAllContents (
shouldContinue = false;
cursor = undefined;
} else {
cursor = res.Marker;
cursor = list.at(-1)?.Key;
}
}

Expand Down

0 comments on commit 1a2a902

Please sign in to comment.