-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
feat(storageinsights): Adds samples for storage insights #2612
Conversation
Here is the summary of changes. You are about to add 5 region tags.
This comment is generated by snippet-bot.
|
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.
For tests to run on CI you need to add a file such as this one:
https://github.com/GoogleCloudPlatform/dotnet-docs-samples/blob/main/storage/api/runTests.ps1
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.
A few change requests but nothing major. Mostly idiomatic things.
Some of the comments will apply to everything although I've only brought them up in a couple of places.
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace StorageInsights.Samples |
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.
We don't use namespace in samples because of the extra indentation and verbosity. We do use them in tests though.
Or now, with C# 8, you can just leave the namespace declaration but remove the associated brackets and indent.
Here and everywhere.
RetryRobot robot = new RetryRobot() { ShouldRetry = (e) => true }; | ||
robot.Eventually(() => | ||
{ | ||
var reportConfig = new CreateInventoryReportConfigSample().CreateInventoryReportConfig(_fixture.ProjectId, |
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 believe this is what would fail because of permissions, so just have this within the retry. And also a note explaining why.
[Fact] | ||
public void TestListInventoryReportConfigs() | ||
{ | ||
RetryRobot robot = new RetryRobot() { ShouldRetry = (e) => true }; |
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.
Just retry for the permissions related exceptions? Else we risk things timing out when there's a different error, and then we don't know what exactly happened.
bool found = false; | ||
|
||
foreach (var config in reportConfigs) | ||
{ | ||
if (config.Name.Contains(reportConfig.Name.Split("/")[5])) | ||
{ | ||
found = true; | ||
} | ||
} | ||
|
||
Assert.True(found); |
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.
User Assert.Contains instead.
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 can't do that here unfortunately, the responses from CreateInventoryReportConfig And ListInventoryReportConfigs are slightly different. The Create response has the project ID in the resource name (so like "projects/projectID/locations/...", but the List responses have the project number there instead (so like "projects/1234/locations/..."
So reportConfigs.contains(reportConfig)
actually returns false here. That's why I just search every element to see if it contains the report config name component instead
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.
You can still use with a condition, something like (I'm doing this by heart so it may have syntax errors):
Assert.Contains(reportConfigs, config => config.Name.Contains(reportConfig.NameAsResourceName.Name));
|
||
foreach (var config in reportConfigs) | ||
{ | ||
if (config.Name.Contains(reportConfig.Name.Split("/")[5])) |
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.
You can probably use reportConfig.NameAsResourceName to access the segment you need to access without having to manipulate strings.
[Fact] | ||
public void TestGetInventoryReportNames() | ||
{ | ||
RetryRobot robot = new RetryRobot() { ShouldRetry = (e) => true }; |
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.
Only retry the permission related exceptions. Here and elsewhere.
GetInventoryReportNamesSample sample = new GetInventoryReportNamesSample(); | ||
sample.GetInventoryReportNames(_fixture.ProjectId, _fixture.BucketLocation, | ||
reportConfig.Name.Split("/")[5]); | ||
/* We can't actually test for a report config name showing up here, because we create |
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.
This is fine, but if you are not using the list with the report names, do not return anything from the sample.
public ReportConfig EditInventoryReportConfig( | ||
string projectId = "your-project-id", | ||
string bucketLocation = "us-west-1", | ||
string inventoryReportConfigUuid = "2b90d21c-f2f4-40b5-9519-e29a78f2b09f") |
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.
Same as before.
foreach (ReportConfig report in _fixture.StorageInsights.ListReportConfigs( | ||
LocationName.Format(_fixture.ProjectId, _fixture.BucketLocation))) | ||
{ | ||
Assert.NotEqual(report.Name, reportConfig.Name); | ||
} |
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.
Assert.DoesNotContain
Or better, check that getting the report throws with a NOT_FOUND.
FrequencyOptions = new FrequencyOptions | ||
{ | ||
Frequency = FrequencyOptions.Types.Frequency.Weekly, | ||
StartDate = new Date{ Year = 3022, Month = 11, Day = 15 }, |
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.
Is this year intentional? Can we use a year that's in the 2020's?
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.
The time has to be some minimum time in the future (not sure the exact constraint), and I also wanted to make sure that in the case of a report config accidentally not getting deleted, we don't waste resources by actually making reports. So i just picked a date that would always be in the future and wouldn't have to be updated whenever that year eventually passes.
I guess we could just do something like make it today's date plus one or something, would you prefer that?
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.
Yes, I think so, and if you can find that minimum and use that to move now into the future, with a note explaining, even better. So users know that they at least need to use that minimum as well.
bool found = false; | ||
|
||
foreach (var config in reportConfigs) | ||
{ | ||
if (config.Name.Contains(reportConfig.Name.Split("/")[5])) | ||
{ | ||
found = true; | ||
} | ||
} | ||
|
||
Assert.True(found); |
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.
You can still use with a condition, something like (I'm doing this by heart so it may have syntax errors):
Assert.Contains(reportConfigs, config => config.Name.Contains(reportConfig.NameAsResourceName.Name));
FrequencyOptions = new FrequencyOptions | ||
{ | ||
Frequency = FrequencyOptions.Types.Frequency.Weekly, | ||
StartDate = new Date{ Year = 3022, Month = 11, Day = 15 }, |
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.
Yes, I think so, and if you can find that minimum and use that to move now into the future, with a note explaining, even better. So users know that they at least need to use that minimum as well.
for (long index = reportDetail.ShardsCount - 1; index >= 0; index--) | ||
{ | ||
String reportName = reportDetail.ReportPathPrefix + index + "." + extension; | ||
reportNames.Add(reportName); |
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.
Oh I meant adding the calculate reportName
s to a list to return that list. Yes of course you have to show how to calculate the report names, and then you print them in the console for demonstration purposes. What's odd is to also add them to a list. Some users would want them on a list, some users will write them to a file, some users will inmediately start processes to download the reports etc... So, I just meant stop building and returning the list with all the reports in it. Adn you are not using this for testing so that's fine.
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.
A few, mostly style changes. But looking good.
storageinsights/api/StorageInsights.Samples/GetInventoryReportNames.cs
Outdated
Show resolved
Hide resolved
storageinsights/api/StorageInsights.Samples/EditInventoryReportConfig.cs
Outdated
Show resolved
Hide resolved
}); | ||
EditInventoryReportConfigSample sample = new EditInventoryReportConfigSample(); | ||
var updatedConfig = sample.EditInventoryReportConfig(_fixture.ProjectId, _fixture.BucketLocation, | ||
reportConfig.Name.Split("/")[5]); |
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.
There should be a reportConfig.NameAsResourceName or similar that you can use so that you don't need to manipulate the string.
storageinsights/api/StorageInsights.Samples/CreateInventoryReportConfig.cs
Outdated
Show resolved
Hide resolved
storageinsights/api/StorageInsights.Samples/CreateInventoryReportConfig.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Amanda Tarafa Mas <14878252+amanda-tarafa@users.noreply.github.com>
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.
LGMT, thanks!
Adds samples for storage insights, and tests
Fixes #2287