BB-721: Properly get location in lifecycle metrics#2736
Conversation
9da1c41 to
5561284
Compare
4da31b3 to
4520f5a
Compare
f9d1347 to
7c00e43
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files
... and 3 files with indirect coverage changes
@@ Coverage Diff @@
## improvement/BB-740-monitor-lifecycle-conductor #2736 +/- ##
==================================================================================
- Coverage 74.83% 74.62% -0.22%
==================================================================================
Files 200 201 +1
Lines 13701 13796 +95
==================================================================================
+ Hits 10253 10295 +42
- Misses 3438 3491 +53
Partials 10 10
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
7c00e43 to
405b79a
Compare
405b79a to
326294c
Compare
| return objectMD[fieldName]; | ||
| } | ||
|
|
||
| function isRealLocation(location) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
|
|
||
| const STANDARD_LOCATION = 'STANDARD'; | ||
|
|
||
| function _getObjectMDValue(objectMD, getterName, fieldName) { |
There was a problem hiding this comment.
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,
then when it's not nil, I think we don't need this helper and can directly call
objectMD.getArchive()
objectMD..getDatastoreName()
etc
There was a problem hiding this comment.
I agree with Sylvain on this one, something is not clear
There was a problem hiding this comment.
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 ?
| return !isRealLocation(location); | ||
| } | ||
|
|
||
| function resolveLifecycleMetricObjectLocation(objectMD, fallbackLocation) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Can discuss with other reviewers : its a bit annoying to do one more pr but, should all these functions belongs to Arsenal ?
| return !!location && location !== STANDARD_LOCATION; | ||
| } | ||
|
|
||
| function shouldResolveLifecycleMetricLocation(location) { |
There was a problem hiding this comment.
after reading the pr some more, I think this is more a
needsResolveLifecycleMetricLocation
than
shouldResolveLifecycleMetricLocation
It makes the function calling it easier to understand what they are doing
There was a problem hiding this comment.
I'm not sure we need a new function to just call an another one ?
| }, false); | ||
| } | ||
|
|
||
| _resolveLifecycleMetricLocation(entry, fallbackLocation, log, cb) { |
There was a problem hiding this comment.
i feel like something is off around here :
We have
_resolveLifecycleMetricLocation calling
- _resolveLifecycleMetricLocationFromBucket
- _resolveLifecycleMetricLocationFromMetadata which calls these 2
- _resolveLifecycleMetricLocationFromArchiveInfo
- _resolveLifecycleMetricLocationFromBucket
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 :
DarkIsDude
left a comment
There was a problem hiding this comment.
Can you also tell me more about In some cases, we have STANDARD as location in lifecycle metrics : as we get object information through regular S3 API. which cases and when it's an issue to use regular s3 api ?
|
|
||
| const STANDARD_LOCATION = 'STANDARD'; | ||
|
|
||
| function _getObjectMDValue(objectMD, getterName, fieldName) { |
There was a problem hiding this comment.
I agree with Sylvain on this one, something is not clear
| return !!location && location !== STANDARD_LOCATION; | ||
| } | ||
|
|
||
| function shouldResolveLifecycleMetricLocation(location) { |
There was a problem hiding this comment.
I'm not sure we need a new function to just call an another one ?
|
|
||
| const STANDARD_LOCATION = 'STANDARD'; | ||
|
|
||
| function _getObjectMDValue(objectMD, getterName, fieldName) { |
There was a problem hiding this comment.
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 ?
francoisferrand
left a comment
There was a problem hiding this comment.
- no clear which scenario exactly creates which problem - and hence if the fix is relevant
- by trying to be very generic, the code creates lots of complexity, with a very complex algorithm being implemented to retrieve the location in different cases - which also makes it very difficult to be sure "what" will actually end up in the metrics
- this is a "small" improvement: instead of STANDARD we get in some case, we want to get the actual field which is already in metadata; so don't want to pay for this (if it needs so much complexity and IOs, may be better to just live with it)
With the advances in Cloudserver api (headObject, list object v2, ...), is there no way to just tweak the existing approach, to get to this information efficiently and keep this simple?
| this.producer.sendToTopic(this.objectTasksTopic, entries, err => { | ||
| LifecycleMetrics.onKafkaPublish(null, 'ObjectTopic', 'bucket', err, 1); | ||
| return cb(err); | ||
| const command = new GetBucketLocationCommand({ Bucket: bucket }); |
There was a problem hiding this comment.
getBucketLocation() returns the default location of a bucket, which could change (it happens in S3C, in some cases):
- so would be a race condition here...
- the cache makes this issue worse, as it may get poisoned by the "old" value of the location
| .then(data => { | ||
| LifecycleMetrics.onS3Request(log, 'getBucketLocation', 'bucket', null); | ||
| const location = data && data.LocationConstraint; | ||
| this._bucketLocationCache.set(bucket, location); |
There was a problem hiding this comment.
there may be many buckets, not sure we should allow unbounded cache
| if (shouldBreak) { | ||
| process.nextTick(() => cb(errorCircuitBreakerTripped)); | ||
| return; | ||
| this._resolveLifecycleMetricLocation(entry, initialLocation, this.log, (err, location) => { |
There was a problem hiding this comment.
instead of the extra metadata call, could we change one (existing) call?
i.e. if we already call HeadObject, we could instead pass the appropriate flag (x-amz-scal-archive-info) to get more details? Or use getObjectAttribute/listObjectV2 with attributes to get the required info more efficiently?
| */ | ||
| _sendObjectAction(entry, cb) { | ||
| const location = entry.getAttribute('details.dataStoreName'); | ||
| const initialLocation = entry.getAttribute('details.dataStoreName'); |
There was a problem hiding this comment.
this is not the "initialLocation" : if the location is already set (e.g. object has been transitioned already or written directly to a non-default location), this value should be correct already : and it must be used.
→ this is really the "real" location, except sometimes it is "STANDARD" (i.e. default bucket location) and needs to be resolved
There was a problem hiding this comment.
also sometimes needs to be resolved because it is a "cold" location, according to the ticket.
Though practically, not sure what the problem really is - of if there one : sendObjectAction would be called on expiration, and seems ok if we report the expiration of a cold object as happening on the "cold" location itself?
| }); | ||
| } | ||
|
|
||
| _resolveLifecycleMetricLocationFromBucket(entry, fallbackLocation, log, cb) { |
There was a problem hiding this comment.
- this so-called "fallbackLocation" is NOT a fallback, this is the actual location
- parameter is redundant : this is part of entry already
| } | ||
|
|
||
| _resolveLifecycleMetricLocationFromMetadata(entry, fallbackLocation, log, cb) { | ||
| if (!this.backbeatMetadataProxy) { |
There was a problem hiding this comment.
why do we need 3 cases?
backbeatMetadataProxyis always available AFAICS (always initialized in Bucket Processor)- resolving from ObjectMD or Bucket should work in all cases : but at the cost of extra IO (read ObjectMD) or race condition (read default bucket location)
| versionId: params.versionId, | ||
| error: err.message, | ||
| }); | ||
| return this._resolveLifecycleMetricLocationFromArchiveInfo(entry, fallbackLocation, log, cb); |
There was a problem hiding this comment.
why make the call to getObjectMD if we already had the data in entry ?
|
|
||
| const STANDARD_LOCATION = 'STANDARD'; | ||
|
|
||
| function _getObjectMDValue(objectMD, getterName, fieldName) { |
There was a problem hiding this comment.
not possible. When you call a function, you MUST know what the parameters are : and then you implement the way which is needed, instead of trying to cope with various cases dynamically...
| }); | ||
| }); | ||
|
|
||
| it('should emit expiration metrics with restored object cold location', done => { |
There was a problem hiding this comment.
expiration metrics should be made with cold location: since this is where the data is "really" stored...
Or are there some cases where this creates inconsistencies?
| "Effect": "Allow", | ||
| "Action": [ | ||
| "s3:GetLifecycleConfiguration", | ||
| "s3:GetBucketLocation", |
There was a problem hiding this comment.
also need extra permission to get "archive info" in HeadObject
Issue: BB-721