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(SLO): download support for SLO API #1701

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

Kirdock
Copy link
Contributor

@Kirdock Kirdock commented Feb 12, 2025

What this PR does / Why we need it:

Introduces the download command for SLOs

@Kirdock Kirdock requested a review from a team as a code owner February 12, 2025 11:54
Copy link

github-actions bot commented Feb 12, 2025

Unit Test Results

1 808 tests  +17   1 807 ✅ +17   54s ⏱️ -1s
  132 suites + 2       1 💤 ± 0 
    1 files   ± 0       0 ❌ ± 0 

Results for commit 1638fea. ± Comparison against base commit 43450f2.

♻️ This comment has been updated with latest results.

pkg/download/config_creation/config_creation.go Outdated Show resolved Hide resolved
go.sum Outdated Show resolved Hide resolved
)

// CreateConfig creates a config based on a given JSON payload and removes properties like the id (idPropertyKey), version and externalId
func CreateConfig(projectName string, data []byte, configType config.Type, idPropertyKey string) (config.Config, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would reduce the scope of this function to just removing unwanted entries. Than we could reuse it in every client. For example, the bucket client needs to delete:

	r.Delete(bucketName)
	r.Delete(status)
	r.Delete(version)
	r.Delete(updatable)

The signature should look something like:

func Remove(data []byte, keys ... string) (json.JsonRaw, error)

What's your opinion @arthurpitman ?

Copy link
Contributor Author

@Kirdock Kirdock Feb 12, 2025

Choose a reason for hiding this comment

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

I adapted it to only return the id and the modified json payload. The config creation is then again up to the segments/slos

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I adapted it again. Now it's also possible to use it for download buckets. I haven't touched it yet, because this would change the error logs

regarding the delete suggestion: I would not vote for that as it would only transform it basically from vertical to horizontal with no real value

pkg/download/slo/download.go Show resolved Hide resolved
cmd/monaco/download/downloadopts.go Outdated Show resolved Hide resolved
@@ -101,6 +101,10 @@ func GetDownloadCommand(fs afero.Fs, command Command) (cmd *cobra.Command) {
cmd.Flags().BoolVar(&f.onlySegments, "only-segments", false, "Only download segment configurations, skip all other configuration types")
}

if featureflags.ServiceLevelObjective.Enabled() {
cmd.Flags().BoolVar(&f.onlySLOs, "only-slos", false, "Only download SLOs, skip all other configuration types")
Copy link
Contributor

Choose a reason for hiding this comment

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

For a user, it should be always slo-v2. Same as the type name.
As we also have slo in the classic endpoint, it could be confusing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done ✅
changed to only-slo-v2

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On second thought: plural or singular? only-slo-v2 vs only-slos-v2

@Kirdock Kirdock force-pushed the feat/slo/download branch 2 times, most recently from 5294eb4 to fab40e6 Compare February 12, 2025 16:42
@tomazpu tomazpu added the release-notes This feature/fix should be mentioned in release notes label Feb 13, 2025
Copy link

E2E Test Results

0 files   -     4  0 suites   - 391   0s ⏱️ - 1h 15m 12s
0 tests  - 1 902  0 ✅  - 1 900  0 💤  - 2  0 ❌ ±0 
0 runs   - 2 228  0 ✅  - 2 226  0 💤  - 2  0 ❌ ±0 

Results for commit 2f5705e. ± Comparison against base commit 43450f2.

cmd/monaco/download/download_configs.go Outdated Show resolved Hide resolved
pkg/client/clientset.go Outdated Show resolved Hide resolved
pkg/download/config_creation/config_creation.go Outdated Show resolved Hide resolved
}

// PrepareConfig returns the given id (idPropertyKey) and the JSON string without the given properties
func PrepareConfig(data []byte, structPointer any, deletedProperties []string, replaceParam string) (PreparedConfig, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would probably split this up into two methods, in a way, you're breaking the single responsibility principle. As you're getting the PreparedConfig and deleting("sanitizing") the downloaded data set.

Would it make sense to provide two methods, one returns ID. And another one to Sanitize the data set?
General feeling the method is complex and hard to read. Even breaking it up into private methods of steps that you do would make me happy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.
Tell me if you want to split it differently or if we should completely change the implementation

pkg/download/config_creation/config_creation_test.go Outdated Show resolved Hide resolved
Id string `json:"id"`
}

func TestCreateConfig(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would also add some additional error test cases. Specially the field that I have in mind is structPointer as declared as any. The specific test for replaceParam.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wouldn't testing different variants of structPointer basically be like directly testing json.Unmarshal(data, structPointer) with any value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Anyway, I added some ✅

pkg/download/segment/download.go Outdated Show resolved Hide resolved
pkg/download/slo/download.go Outdated Show resolved Hide resolved
pkg/download/slo/download.go Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-notes This feature/fix should be mentioned in release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants