C
C#3mo ago
NeRooN

Amazon S3 client total request count

Hello, i need some help in something i assume it's easy but i need to be 100% sure. I have an s3client that i use to make some requests to amazon s3. Now i need to log the total GET/POST/PUT/DELETE requests i do. I assume it's only 1 request per call, but to be 100% sure i prefer to ask here how can i check this. The idea is to have methods like:
Public Function GetObjectMetadata(metadataRequest As GetObjectMetadataRequest) As GetObjectMetadataResponse
GetRequests += 1
Return S3Client.GetObjectMetadata(metadataRequest)
End Function
Public Function GetObjectMetadata(metadataRequest As GetObjectMetadataRequest) As GetObjectMetadataResponse
GetRequests += 1
Return S3Client.GetObjectMetadata(metadataRequest)
End Function
so when i do the "GetObjectMetadata" request, it adds 1 to the counter. So i need to be sure every mehtod i call does only 1 request, in case it does some extra requests i should then add something like "PostRequest += 1" or smth like that
15 Replies
Pobiega
Pobiega3mo ago
That looks like VB, not C#. How do you plan to handle restarts, or crashes? Is the object lifetime for your client always a singleton?
NeRooN
NeRooN3mo ago
its a service i execute once every day and it start from 0 in every execution. It does some things and then ends and restart the next day. Also for the C#/VB part, i assumed i could ask here since the s3Client is fully written in c# and here i only do a call to the api
Pobiega
Pobiega3mo ago
what the S3 client is written in really doesnt matter you are not asking about the s3 client, you are asking about your wrapper regardless, the same questions apply - are you sure about the lifetimes here? like, if you do var wrapper = new Wrapper(s3Client);, your counts will reset so how accurate do you need your counts to be? When are they "reported" out of the system?
NeRooN
NeRooN3mo ago
yeah, this app should open, do something and end. This wrapper will execute once at the start of the lifetiume and will end with the end of the process
Pobiega
Pobiega3mo ago
ok so its a short-lived app?
NeRooN
NeRooN3mo ago
i just start it and at the end of the execution it will log it with somehting like:
Public Overrides Function GetS3Statistics() As String
Dim stats As New List(Of String)()

If s3Wrapper.GetRequests <> 0 Then
stats.Add($"Get Requests: {s3Wrapper.GetRequests}")
End If

If s3Wrapper.PostRequests <> 0 Then
stats.Add($"Post Requests: {s3Wrapper.PostRequests}")
End If

If s3Wrapper.PutRequests <> 0 Then
stats.Add($"Put Requests: {s3Wrapper.PutRequests}")
End If

If s3Wrapper.DeleteRequests <> 0 Then
stats.Add($"Delete Requests: {s3Wrapper.DeleteRequests}")
End If

Return String.Join(" - ", stats)
End Function
Public Overrides Function GetS3Statistics() As String
Dim stats As New List(Of String)()

If s3Wrapper.GetRequests <> 0 Then
stats.Add($"Get Requests: {s3Wrapper.GetRequests}")
End If

If s3Wrapper.PostRequests <> 0 Then
stats.Add($"Post Requests: {s3Wrapper.PostRequests}")
End If

If s3Wrapper.PutRequests <> 0 Then
stats.Add($"Put Requests: {s3Wrapper.PutRequests}")
End If

If s3Wrapper.DeleteRequests <> 0 Then
stats.Add($"Delete Requests: {s3Wrapper.DeleteRequests}")
End If

Return String.Join(" - ", stats)
End Function
Pobiega
Pobiega3mo ago
then this is fine, except that it wont handle failures very well
NeRooN
NeRooN3mo ago
and it will log it dw, the failures are handled in the main code
Pobiega
Pobiega3mo ago
but the counts will be potentially inaccurate, based on failures
NeRooN
NeRooN3mo ago
i used to do s3Client.MyRequest with a try catch and all that, now i just do the same but with a wrapper so i can add the request count without worrying about forgiving to add it well, thats something i will need to live with, it doesnt need to be 100% accurate, i just need it so someone can do some statistics and some numbers
Pobiega
Pobiega3mo ago
okay, yeah then thats fine
NeRooN
NeRooN3mo ago
but i assume when i call the api for a delete, for example, it will just do one delete request, right? i dont know how to check what it does in the backend it takes me to an interface so i cannot see the code and how it handles the requests
Pobiega
Pobiega3mo ago
I dont understand the question if you do s3Client.Delete, that will only do a delete it will not do posts, puts, gets etc
NeRooN
NeRooN3mo ago
the client fear is that it makes a Get and then a Delete, for example i assume it's well written and it will only do a Delete but i need to make sure it is like that for the client
Pobiega
Pobiega3mo ago
so check the source for the s3client? but yeah, I would be very surprised if it did anything else
Want results from more Discord servers?
Add your server