Skip to content
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

Merged
merged 7 commits into from
May 9, 2024

Conversation

JesseLovelace
Copy link
Member

Adds samples for storage insights, and tests

Fixes #2287

@JesseLovelace JesseLovelace requested a review from a team as a code owner April 29, 2024 16:52
Copy link

snippet-bot bot commented Apr 29, 2024

Here is the summary of changes.

You are about to add 5 region tags.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@product-auto-label product-auto-label bot added the samples Issues that are directly related to samples. label Apr 29, 2024
@jskeet jskeet assigned amanda-tarafa and unassigned jskeet Apr 29, 2024
Copy link
Member

@amanda-tarafa amanda-tarafa left a 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

@JesseLovelace JesseLovelace added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 1, 2024
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 1, 2024
@JesseLovelace JesseLovelace added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 1, 2024
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 1, 2024
@JesseLovelace JesseLovelace added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 1, 2024
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 1, 2024
@JesseLovelace JesseLovelace added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 1, 2024
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 1, 2024
Copy link
Member

@amanda-tarafa amanda-tarafa left a 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
Copy link
Member

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,
Copy link
Member

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 };
Copy link
Member

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.

Comment on lines 44 to 54
bool found = false;

foreach (var config in reportConfigs)
{
if (config.Name.Contains(reportConfig.Name.Split("/")[5]))
{
found = true;
}
}

Assert.True(found);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

User Assert.Contains instead.

Copy link
Member Author

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

Copy link
Member

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]))
Copy link
Member

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 };
Copy link
Member

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
Copy link
Member

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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as before.

Comment on lines 42 to 46
foreach (ReportConfig report in _fixture.StorageInsights.ListReportConfigs(
LocationName.Format(_fixture.ProjectId, _fixture.BucketLocation)))
{
Assert.NotEqual(report.Name, reportConfig.Name);
}
Copy link
Member

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 },
Copy link
Member

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?

Copy link
Member Author

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?

Copy link
Member

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.

Comment on lines 44 to 54
bool found = false;

foreach (var config in reportConfigs)
{
if (config.Name.Contains(reportConfig.Name.Split("/")[5]))
{
found = true;
}
}

Assert.True(found);
Copy link
Member

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 },
Copy link
Member

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);
Copy link
Member

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 reportNames 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.

Copy link
Member

@amanda-tarafa amanda-tarafa left a 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.

});
EditInventoryReportConfigSample sample = new EditInventoryReportConfigSample();
var updatedConfig = sample.EditInventoryReportConfig(_fixture.ProjectId, _fixture.BucketLocation,
reportConfig.Name.Split("/")[5]);
Copy link
Member

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.

JesseLovelace and others added 2 commits May 9, 2024 13:33
Co-authored-by: Amanda Tarafa Mas <14878252+amanda-tarafa@users.noreply.github.com>
Copy link
Member

@amanda-tarafa amanda-tarafa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGMT, thanks!

@amanda-tarafa amanda-tarafa merged commit c392a20 into main May 9, 2024
10 checks passed
@amanda-tarafa amanda-tarafa deleted the insights branch May 9, 2024 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
samples Issues that are directly related to samples.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create samples for storageinsights
4 participants