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

Fixes before 0.2.0 release #150

Closed
wants to merge 4 commits into from
Closed

Conversation

malcolmholmes
Copy link
Collaborator

@malcolmholmes malcolmholmes commented Aug 6, 2021

see comments inline to explain these changes.

@@ -96,6 +96,9 @@ func postDashboard(resource grizzly.Resource) error {
return err
}

if !resource.HasMetadata("folder") {
return fmt.Errorf("Resource %s requires a folder within its metadata", resource.GetMetadata("name"))
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

complain if there is no folder metadata within a dashboard.

@@ -52,7 +52,7 @@ func getRemoteRuleGroup(uid string) (*grizzly.Resource, error) {
"rules": group.Rules,
}
handler := RuleHandler{}
resource := grizzly.NewResource(handler.APIVersion(), handler.Kind(), uid, spec)
resource := grizzly.NewResource(handler.APIVersion(), handler.Kind(), group.Name, spec)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

uid is $namespace.$name, so this misreports the name portion.

if parsedResource.MatchesTarget(opts.Targets) {
resources = append(resources, parsedResource)
}
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

somehow we lost our -t target handling functionality when parsing with Jsonnet.

@@ -9,6 +11,9 @@ const generalFolderId = 0
func extractFolderUID(d DashboardWrapper) string {
folderUid := d.Meta.FolderUID
if folderUid == "" {
if d.Meta.FolderURL == "" {
return "general"
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Grafana can come back with a blank folder URL for the general folder.

@malcolmholmes malcolmholmes marked this pull request as draft August 6, 2021 21:59
@@ -27,10 +28,12 @@ func TestExtractFolderUID(t *testing.T) {
}
getFolderById = func(folderId int64) (Folder, error) {
return Folder{
"uid": "12345",
"uid": "12345",
"folderURL": "http://localhost:3000/blah",
}, nil
}
uid := extractFolderUID(dashboardWrapper)
require.Equal(t, "12345", uid)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Need to also check for folderUrl here?

@@ -21,7 +21,7 @@ func TestRules(t *testing.T) {
}
res, err := getRemoteRuleGroup("first_rules.grizzly_alerts")
require.NoError(t, err)
require.Equal(t, "first_rules.grizzly_alerts", res.Name())
require.Equal(t, "grizzly_alerts", res.Name())
Copy link

Choose a reason for hiding this comment

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

It's not jumping out to me in the code what's changed that makes this test pass on both sides of the overall changeset, could you explain?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Closing this PR (work done elsewhere), but to answer your question:

A resource is uniquely identified by its Kind and UID. Resources also have a name, but that is not going to be consistent across all resource types, 'cos for example a rule group can appear in multiple namespaces.

Therefore, I've been constructing a UID from various bits of metadata, e.g. $NAMESPACE.$NAME.

What does occur to me though is that people will expect metadata.name to be unique, so constructing a UID in the background really doesn't help here.

What would be much better would be to require the name to be constructed correctly, and validate it is correct, erroring out with a nice message if it isn't. So:

apiVersion: grizzly.grafana.com/v1alpha1
kind: PrometheusRuleGroup
metadata:
  name: some_namespace.some_rules
spec:
  name: some_rules
  namespace: some_namespace
  rules:
    ....all the rules...

Here, metadata.name becomes a unique identifier, and validation in the handler confirms that it it matches ${spec.namespace}.${spec.name}.

@malcolmholmes
Copy link
Collaborator Author

This work has all been done in other PRs.

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

Successfully merging this pull request may close these issues.

None yet

3 participants