-
Notifications
You must be signed in to change notification settings - Fork 23
BB-721: Properly get location in lifecycle metrics #2736
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
base: improvement/BB-740-monitor-lifecycle-conductor
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can discuss with other reviewers : its a bit annoying to do one more pr but, should all these functions belongs to Arsenal ? |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| 'use strict'; | ||
|
|
||
| const STANDARD_LOCATION = 'STANDARD'; | ||
|
|
||
| function _getObjectMDValue(objectMD, getterName, fieldName) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Haven't digged too much into this, but I'm surprised we have to create a helper function for this, since there must already be some existing code trying to access object metadatas, I wonder how it's being done ? Don't we have getters functions in Arsenal for this already ? Looking a bit more into it : The function is only called locally from resolveLifecycleMetricObjectLocation, we can check that objectMD is non nil directly at the beginning of resolveLifecycleMetricObjectLocation, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with Sylvain on this one, something is not clear There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the idea is to be able to manage when the value are wrapped in a class (Arsenal) or when it's a raw data. But we should try to always manipulate class ? |
||
| if (!objectMD) { | ||
| return undefined; | ||
| } | ||
| if (typeof objectMD[getterName] === 'function') { | ||
| return objectMD[getterName](); | ||
| } | ||
| return objectMD[fieldName]; | ||
| } | ||
|
|
||
| function isRealLocation(location) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still reading the pr, but I dont fully understand the link between the function name and what its doing. Basically checking that a given location is non null and not equal to 'STANDARD'. So why not name it "isStandardLocation" or "isNotStandardLocation" ? Reading a bit further, I think the standard location is some kind of default value, and we try to resolve some locations, so maybe the intent is "isResolvedLocations" ? I think some of this can be documented by code comments too
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. update : looking at the jira ticket, it gives more context : "In some cases, we have STANDARD as location in lifecycle metrics : as we get object information through regular S3 API." I think this is the kind of context that could be added as code comment |
||
| return !!location && location !== STANDARD_LOCATION; | ||
| } | ||
|
|
||
| function shouldResolveLifecycleMetricLocation(location) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. after reading the pr some more, I think this is more a It makes the function calling it easier to understand what they are doing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure we need a new function to just call an another one ? |
||
| return !isRealLocation(location); | ||
| } | ||
|
|
||
| function resolveLifecycleMetricObjectLocation(objectMD, fallbackLocation) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I find it a bit weird that in this function, we are calling isRealLocation on different object metadata attributes. Maybe its fine but it probably deserve some code comments to explain a bit more what its doing
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can also explain why we only look at the first locations[0], of course future developers can always ask an llm to know (claude said its because mpu object have an array of locations, but all locations are the same so its ok to look at the first only) but I think its nicer to have a human written comment for things that can be confusing. Maybe here it does deserves a helper function like "getMpuObjectLocation" or more generic "getObjectLocation" that handle both mpu and non mpu objects |
||
| const archive = _getObjectMDValue(objectMD, 'getArchive', 'archive'); | ||
| const amzStorageClass = _getObjectMDValue(objectMD, 'getAmzStorageClass', 'x-amz-storage-class'); | ||
| if (archive && isRealLocation(amzStorageClass)) { | ||
| return amzStorageClass; | ||
| } | ||
|
|
||
| const dataStoreName = _getObjectMDValue(objectMD, 'getDataStoreName', 'dataStoreName'); | ||
| if (isRealLocation(dataStoreName)) { | ||
| return dataStoreName; | ||
| } | ||
|
|
||
| const locations = _getObjectMDValue(objectMD, 'getLocation', 'location'); | ||
| const locationDataStoreName = Array.isArray(locations) && locations[0] | ||
| && locations[0].dataStoreName; | ||
| if (isRealLocation(locationDataStoreName)) { | ||
| return locationDataStoreName; | ||
| } | ||
|
|
||
| return fallbackLocation; | ||
| } | ||
|
|
||
| module.exports = { | ||
| STANDARD_LOCATION, | ||
| isRealLocation, | ||
| shouldResolveLifecycleMetricLocation, | ||
| resolveLifecycleMetricObjectLocation, | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| const assert = require('assert'); | ||
|
|
||
| const bucketProcessorPolicy = require('../../../extensions/lifecycle/bucketProcessor/policy.json'); | ||
|
|
||
| describe('LifecycleBucketProcessor policy', () => { | ||
| it('should allow S3 actions required for lifecycle metric location resolution', () => { | ||
| const actions = bucketProcessorPolicy.Statement | ||
| .find(statement => statement.Sid === 'LifecycleExpirationBucketProcessor') | ||
| .Action; | ||
|
|
||
| assert(actions.includes('s3:GetBucketLocation')); | ||
| }); | ||
| }); |
Uh oh!
There was an error while loading. Please reload this page.
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.
i feel like something is off around here :
We have
_resolveLifecycleMetricLocation calling
So Frombucket can be called twice, and we have something else smelly : the if entry action type == deleteMpu is checked in this function, but also in _resolveLifecycleMetricLocationFromMetadata
I have a feeling it would be better to have a single function, even if larger, that can be read more naturally with less indirection.
Discussed this with Claude and providing his answer here :