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

Issue calling CloudProviderSnapshotBackupPolicies Service #349

Closed
makubit opened this issue Jan 26, 2023 · 6 comments
Closed

Issue calling CloudProviderSnapshotBackupPolicies Service #349

makubit opened this issue Jan 26, 2023 · 6 comments

Comments

@makubit
Copy link

makubit commented Jan 26, 2023

Hi Team!

I'm trying to call Atlas API to GET the backup policy (CloudProviderSnapshotBackupPoliciesService) and I'm getting an error from the client:

{"responseError": "json: unsupported type: func() (io.ReadCloser, error)"}

My cluster is running in Atlas, I have enabled continuous backups. I'm passing valid parameters and it seems that issue is not on my service side.
Could someone look at this?

Cheers,
Magda

@gssbzn
Copy link
Collaborator

gssbzn commented Jan 26, 2023

Hi @makubit can you please provide a sample application that reproduces the error?

@makubit
Copy link
Author

makubit commented Jan 27, 2023

Sure, the code is pretty easy, just call the mentioned service:

	t := digest.NewTransport(string(publicKey), string(privateKey))
	tc, err := t.Client()
	if err != nil {
		return nil, fmt.Errorf("error creating http client: %w", err)
	}
	mcli := mongodbatlas.NewClient(tc)

	ps, resp, err := mcli.CloudProviderSnapshotBackupPolicies.Get(ctx, groupID, clusterName)
	//here returned an error

Btw It would be easier to understand this service if there were named parameters in the code:

type CloudProviderSnapshotBackupPoliciesService interface {
	Get(context.Context, string, string) (*CloudProviderSnapshotBackupPolicy, *Response, error)
	Update(context.Context, string, string, *CloudProviderSnapshotBackupPolicy) (*CloudProviderSnapshotBackupPolicy, *Response, error)
	Delete(context.Context, string, string) (*CloudProviderSnapshotBackupPolicy, *Response, error)
}

Get(context.Context, string, string) doesn't show what that strings mean, it's just guessing the convention.

@gssbzn
Copy link
Collaborator

gssbzn commented Jan 27, 2023

Hi @makubit I took your example to make it complete and I'm not able to reproduce

package main

import (
	"context"
	"fmt"

	"github.com/mongodb-forks/digest"
	"go.mongodb.org/atlas/mongodbatlas"
)

func main() {
	t := digest.NewTransport("public-key", "private-key")
	tc, err := t.Client()
	if err != nil {
		panic(err)
	}
	mcli, _ := mongodbatlas.NewClient(tc)
	ps, _, err := mcli.CloudProviderSnapshotBackupPolicies.Get(context.TODO(), "project-id", "cluster-name")
	if err != nil {
		panic(err)
	}
	fmt.Println(ps) // works
}

Btw It would be easier to understand this service if there were named parameters

Feel free to open a PR to improve this

@gssbzn
Copy link
Collaborator

gssbzn commented Jan 27, 2023

I also tested this via the CLI and

atlas backups schedule describe <clusterName> -o json

also works as expected

This feels like it may be a configuration issue the client on your side and why the closer your example is to how you are using it it would be better for us to diagnose

@makubit
Copy link
Author

makubit commented Jan 27, 2023

@gssbzn Thanks for checking! I noticed that one of my conditions was wrong - I didn't wait for the finishing of cluster provisioning and that was the issue (I didn't notice as the message doesn't directly say what was the issue).

In my free time, I can prepare PR with named parameters for a better understanding of the service.

Sorry for the false alarm.

@gssbzn
Copy link
Collaborator

gssbzn commented Jan 27, 2023

I tried the following on the CLI (mainly because it's easier to create a cluster)

atlas cluster create M10 --provider AWS --region US_EAST_1 --tier M10 --backup
atlas backups schedule describe M10 -o json

And the error I get is

404 (request "BACKUP_CONFIG_NOT_FOUND") No backup configuration exists for cluster 63d3d71bbc21f7794cc0270d in group 5e429f2e06822c6eac4d5d9.

And for a cluster that doesn't exists I get

404 (request "CLUSTER_NAME_NOT_FOUND") No cluster with name "fake" exists in group 5e429f2e06822c6eac4d59d9.

I'm a bit curious because this error in particular

unsupported type: func() (io.ReadCloser, error)

Seems like a deserialization error somewhere and we have some options in the client to customize where deserialization happens instead of a return value.

If it works for you now that you wait for the cluster that's great but if it happens again let us know with a way to reproduce which is as close as how you are using the lib so we can discard any internal issue with some of the more advanced settings

@gssbzn gssbzn closed this as completed Jan 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants