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

add dashboards as app #554

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

klinch0
Copy link
Contributor

@klinch0 klinch0 commented Jan 2, 2025

Summary by CodeRabbit

  • New Features

    • Added Grafana dashboards Helm chart with support for URL and JSON dashboard configurations
    • Enhanced tenant RBAC roles with more flexible resource permissions
  • Version Updates

    • Updated tenant application version to 1.6.6
    • Updated monitoring application version to 1.5.4
    • Updated core installer image reference
  • Improvements

    • Added dynamic namespace labeling for Grafana dashboards
    • Introduced conditional ingress annotations for Grafana configuration

@klinch0 klinch0 requested a review from kvaps as a code owner January 2, 2025 09:14
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jan 2, 2025
@klinch0 klinch0 marked this pull request as draft January 2, 2025 09:14
Copy link
Contributor

coderabbitai bot commented Jan 2, 2025

Walkthrough

This pull request introduces a new Grafana dashboards Helm chart with comprehensive configuration options. The changes include creating a new Helm package for Grafana dashboards, adding configuration files like Chart.yaml, values.yaml, and values.schema.json, and implementing a flexible template for dashboard management. Additionally, the PR updates versions for the tenant and monitoring applications, and modifies some deployment configurations across different packages.

Changes

File Change Summary
packages/apps/grafana-dashboards/.helmignore New file added to ignore specific directories and files during Helm packaging
packages/apps/grafana-dashboards/Chart.yaml New Helm chart metadata file with initial version 0.1.0
packages/apps/grafana-dashboards/Makefile Added generate target using readme-generator
packages/apps/grafana-dashboards/README.md Added new section with dashboard parameters
packages/apps/grafana-dashboards/templates/grafana-dashboards.yaml New template for creating Grafana dashboard resources
packages/apps/grafana-dashboards/values.schema.json New JSON schema for dashboard configuration
packages/apps/grafana-dashboards/values.yaml Added configuration parameters for dashboards
packages/apps/tenant/Chart.yaml Version updated from 1.6.5 to 1.6.6
packages/core/installer/values.yaml Updated Cozystack image reference
packages/extra/monitoring/Chart.yaml Version updated from 1.5.3 to 1.5.4

Sequence Diagram

sequenceDiagram
    participant User
    participant HelmChart
    participant GrafanaDashboard
    participant Grafana

    User->>HelmChart: Configure dashboards
    HelmChart->>GrafanaDashboard: Create dashboard resources
    GrafanaDashboard->>Grafana: Apply URL or JSON dashboards
    Grafana-->>GrafanaDashboard: Confirm dashboard import
Loading

Possibly related PRs

Suggested labels

enhancement, size:M, lgtm

Suggested reviewers

  • kvaps

Poem

🐰 Dashboards dancing, Helm charts sing,
A rabbit's tale of configuring things!
URLs and JSON, metrics galore,
Grafana smiles from shore to shore.
Code deployed with magical flair! 🎉


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@dosubot dosubot bot added the enhancement New feature or request label Jan 2, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🧹 Nitpick comments (5)
packages/apps/grafana-dashboards/values.schema.json (1)

17-21: Add validation for instanceSelector

The instanceSelector should validate the Kubernetes label selector format.

 "instanceSelector": {
     "type": "object",
     "description": "Selector to match Grafana instances.",
-    "default": {}
+    "default": {},
+    "properties": {
+        "matchLabels": {
+            "type": "object",
+            "description": "Label selector to match Grafana instances",
+            "patternProperties": {
+                "^[a-zA-Z0-9]([a-zA-Z0-9-_.])*$": {
+                    "type": "string",
+                    "pattern": "^[a-zA-Z0-9]([a-zA-Z0-9-_.])*$"
+                }
+            }
+        }
+    }
 }
packages/apps/grafana-dashboards/templates/grafana-dashboards.yaml (1)

8-11: Add namespace to metadata

Add namespace to metadata to ensure proper resource placement.

 kind: GrafanaDashboard
 metadata:
   name: {{ .name }}
+  namespace: {{ .Release.Namespace }}
packages/apps/grafana-dashboards/values.yaml (2)

20-29: Enhance dashboard example with required fields

The current JSON dashboard example is oversimplified and missing required fields for a valid Grafana dashboard.

 ## Example:
 ## jsonDashboards:
 ##   - name: "grafanadashboard-sample"
 ##     json: |
 ##       {
+##         "id": null,
+##         "title": "Sample Dashboard",
+##         "tags": ["generated", "sample"],
+##         "timezone": "browser",
+##         "schemaVersion": 16,
 ##         "panels": [
-##           { "type": "graph", "title": "Sample Panel" }
+##           {
+##             "id": 1,
+##             "type": "graph",
+##             "title": "Sample Panel",
+##             "datasource": "${DS_PROMETHEUS}"
+##           }
 ##         ]
 ##       }

31-34: Document instanceSelector behavior

Add more context about the instanceSelector's role in dashboard distribution.

 ## @param instanceSelector Selector to match Grafana instances.
-## Leave empty to skip instance selection.
+## Specify labels to match Grafana instances where these dashboards should be deployed.
+## If empty, dashboards will be matched to Grafana instances in the same namespace.
+## For multi-tenant setups, use this to target specific Grafana instances.
 instanceSelector: {}  # @param instanceSelector Selector for matching Grafana instances
packages/extra/monitoring/templates/grafana/grafana.yaml (1)

Line range hint 91-94: Improve template indentation for better readability

The conditional annotation block could be better indented for improved readability.

Consider this format:

  metadata:
    annotations:
-        {{- if ne $issuerType "cloudflare" }}
-        acme.cert-manager.io/http01-ingress-class: "{{ $ingress }}"
-        {{- end }}
+      {{- if ne $issuerType "cloudflare" }}
+      acme.cert-manager.io/http01-ingress-class: "{{ $ingress }}"
+      {{- end }}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fde4bcf and 1a22049.

⛔ Files ignored due to path filters (1)
  • packages/apps/grafana-dashboards/logos/grafana-dashboards.svg is excluded by !**/*.svg
📒 Files selected for processing (14)
  • packages/apps/grafana-dashboards/.helmignore (1 hunks)
  • packages/apps/grafana-dashboards/Chart.yaml (1 hunks)
  • packages/apps/grafana-dashboards/Makefile (1 hunks)
  • packages/apps/grafana-dashboards/README.md (1 hunks)
  • packages/apps/grafana-dashboards/templates/grafana-dashboards.yaml (1 hunks)
  • packages/apps/grafana-dashboards/values.schema.json (1 hunks)
  • packages/apps/grafana-dashboards/values.yaml (1 hunks)
  • packages/apps/tenant/Chart.yaml (1 hunks)
  • packages/apps/tenant/templates/tenant.yaml (1 hunks)
  • packages/apps/versions_map (2 hunks)
  • packages/core/installer/values.yaml (1 hunks)
  • packages/extra/monitoring/Chart.yaml (1 hunks)
  • packages/extra/monitoring/templates/grafana/grafana.yaml (1 hunks)
  • packages/extra/versions_map (1 hunks)
✅ Files skipped from review due to trivial changes (7)
  • packages/extra/monitoring/Chart.yaml
  • packages/apps/tenant/Chart.yaml
  • packages/apps/grafana-dashboards/.helmignore
  • packages/apps/grafana-dashboards/Makefile
  • packages/apps/grafana-dashboards/Chart.yaml
  • packages/apps/grafana-dashboards/README.md
  • packages/core/installer/values.yaml
🧰 Additional context used
🪛 yamllint (1.35.1)
packages/apps/grafana-dashboards/templates/grafana-dashboards.yaml

[warning] 1-1: too many blank lines

(1 > 0) (empty-lines)


[error] 2-2: syntax error: expected the node content, but found '-'

(syntax)

🔇 Additional comments (7)
packages/apps/versions_map (2)

16-16: Introduce and verify the new grafana-dashboards entry.

The addition of grafana-dashboards 0.1.0 HEAD aligns with the introduction of the new Helm chart for Grafana dashboards. Consider confirming the newly added version is referenced properly in your chart configuration and codebase.


99-100: Ensure consistency with tenant chart updates.

Updating the tenant from 1.6.5 f1e11451 to 1.6.6 HEAD appears consistent with the rest of the pull request. Verify that all references or dependencies are updated accordingly (e.g., Chart.yaml, any CI/CD pipelines, or documentation).

packages/apps/tenant/templates/tenant.yaml (1)

244-244: Be cautious with wildcard resources.

Allowing * resources under apiGroups: ["apps.cozystack.io"] in the admin role significantly broadens access. This is normal for an admin role, but ensure you are comfortable with granting complete permissions in production environments.

packages/extra/versions_map (1)

20-21: Confirm proper referencing of commit hash for “monitoring 1.5.3” and the stability of “monitoring 1.5.4 HEAD”.

Switching from HEAD to a specific commit c1ca19dc can help track changes precisely, but ensure that c1ca19dc references the valid updated build you intend to distribute. Additionally, using HEAD in production for version 1.5.4 could introduce unexpected changes unless carefully managed.

packages/extra/monitoring/templates/grafana/grafana.yaml (3)

13-13: LGTM: Namespace-aware dashboard label enables multi-tenancy

The dynamic dashboard label using namespace value aligns well with multi-tenant dashboard management.

Let's verify the dashboard label usage:

✅ Verification successful

Verified: Dashboard label change is consistently implemented and properly integrated

The verification shows that:

  • The namespace-based dashboard label is consistently used in both the main grafana configuration (packages/extra/monitoring/templates/grafana/grafana.yaml) and the new grafana-dashboards app (packages/apps/grafana-dashboards/templates/grafana-dashboards.yaml)
  • The instanceSelector configuration is properly set up in the grafana-dashboards app, allowing for proper dashboard-to-grafana instance mapping
  • The change aligns with the grafana-operator CRD specifications that support instance selection for dashboards
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if the dashboard label is used consistently across the codebase
# and particularly in the new grafana-dashboards app

# Search for dashboard label references
rg --type yaml 'dashboards:.*\$.*NS' 

# Look for dashboard selector configurations
rg --type yaml 'instanceSelector|dashboardSelector'

Length of output: 3999


Line range hint 91-116: Verify ingress security configuration

The conditional ingress annotation is correct, but let's ensure the overall ingress security configuration is robust.

Let's verify the ingress configuration:

✅ Verification successful

Ingress security configuration follows consistent patterns across the cluster

Based on the verification results, the ingress configuration in the Grafana template aligns with the cluster-wide security patterns:

  1. Consistent use of cert-manager.io/cluster-issuer: letsencrypt-prod across multiple services
  2. Proper TLS configuration with dedicated secret names
  3. Standardized ingressClassName usage matching the cluster's ingress controller
  4. Appropriate conditional handling for Cloudflare vs. non-Cloudflare setups

The implementation follows the same secure patterns used in other critical services like Keycloak, Seaweedfs, and the dashboard, indicating a robust and standardized approach to ingress security.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for consistent ingress security patterns across the cluster

# Look for other ingress configurations using cert-manager
rg --type yaml 'cert-manager\.io/(cluster-)?issuer'

# Check for other instances using conditional cloudflare configuration
rg --type yaml 'cloudflare.*ingress|ingress.*cloudflare'

# Verify TLS configuration patterns
rg --type yaml 'ingressClassName|tls:.*secretName'

Length of output: 13254


Line range hint 1-6: Add error handling for resource lookups

The template uses lookup function to fetch critical configuration but doesn't handle cases where the ConfigMap or Namespace resources might not exist or lack required annotations.

Consider adding validation using required function:

-{{- $cozyConfig := lookup "v1" "ConfigMap" "cozy-system" "cozystack" }}
+{{- $cozyConfig := required "ConfigMap 'cozystack' in namespace 'cozy-system' not found" (lookup "v1" "ConfigMap" "cozy-system" "cozystack") }}
-{{- $myNS := lookup "v1" "Namespace" "" .Release.Namespace }}
+{{- $myNS := required "Current namespace details not found" (lookup "v1" "Namespace" "" .Release.Namespace) }}

Comment on lines +11 to +16
"jsonDashboards": {
"type": "array",
"description": "List of dashboards with inline JSON.",
"default": [],
"items": {}
},
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance schema validation for jsonDashboards

Similar to urlDashboards, the items object needs proper validation for required fields and their types.

 "jsonDashboards": {
     "type": "array",
     "description": "List of dashboards with inline JSON.",
     "default": [],
-    "items": {}
+    "items": {
+        "type": "object",
+        "required": ["name", "json"],
+        "properties": {
+            "name": {
+                "type": "string",
+                "description": "The name of the dashboard"
+            },
+            "json": {
+                "type": "object",
+                "description": "The JSON content of the dashboard"
+            }
+        },
+        "additionalProperties": false
+    }
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"jsonDashboards": {
"type": "array",
"description": "List of dashboards with inline JSON.",
"default": [],
"items": {}
},
"jsonDashboards": {
"type": "array",
"description": "List of dashboards with inline JSON.",
"default": [],
"items": {
"type": "object",
"required": ["name", "json"],
"properties": {
"name": {
"type": "string",
"description": "The name of the dashboard"
},
"json": {
"type": "object",
"description": "The JSON content of the dashboard"
}
},
"additionalProperties": false
}
},

Comment on lines +5 to +10
"urlDashboards": {
"type": "array",
"description": "List of dashboards with URLs.",
"default": [],
"items": {}
},
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance schema validation for urlDashboards

The items object is empty, which means any object structure will be accepted. Add proper validation for required fields and their types.

 "urlDashboards": {
     "type": "array",
     "description": "List of dashboards with URLs.",
     "default": [],
-    "items": {}
+    "items": {
+        "type": "object",
+        "required": ["name", "link"],
+        "properties": {
+            "name": {
+                "type": "string",
+                "description": "The name of the dashboard"
+            },
+            "link": {
+                "type": "string",
+                "format": "uri",
+                "description": "The URL of the dashboard JSON"
+            }
+        },
+        "additionalProperties": false
+    }
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"urlDashboards": {
"type": "array",
"description": "List of dashboards with URLs.",
"default": [],
"items": {}
},
"urlDashboards": {
"type": "array",
"description": "List of dashboards with URLs.",
"default": [],
"items": {
"type": "object",
"required": ["name", "link"],
"properties": {
"name": {
"type": "string",
"description": "The name of the dashboard"
},
"link": {
"type": "string",
"format": "uri",
"description": "The URL of the dashboard JSON"
}
},
"additionalProperties": false
}
}

Comment on lines +38 to +40
resyncPeriod: "30s"
json: |
{{ .json | indent 4 }}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Validate required fields before rendering

Add validation for required fields before rendering the template.

+  {{- if not .json }}
+    {{- fail "Dashboard json is required" }}
+  {{- end }}
   resyncPeriod: "30s"
   json: |
 {{ .json | indent 4 }}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
resyncPeriod: "30s"
json: |
{{ .json | indent 4 }}
{{- if not .json }}
{{- fail "Dashboard json is required" }}
{{- end }}
resyncPeriod: "30s"
json: |
{{ .json | indent 4 }}

Comment on lines +12 to +19
{{- if .Values.instanceSelector | not }}
instanceSelector:
matchLabels:
dashboards: {{ $myNS }}
{{- else }}
instanceSelector:
{{ $instanceSelector | indent 4 }}
{{- end }}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix template variable references and indentation

There are several issues in the instanceSelector conditional block:

  1. .Values is incorrectly referenced (should be Values)
  2. Indentation is incorrect for the instanceSelector template
-  {{- if .Values.instanceSelector | not }}
+  {{- if not .Values.instanceSelector }}
   instanceSelector:
     matchLabels:
       dashboards: {{ $myNS }}
   {{- else }}
   instanceSelector:
-{{ $instanceSelector | indent 4 }}
+    {{- toYaml .Values.instanceSelector | nindent 4 }}
   {{- end }}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{{- if .Values.instanceSelector | not }}
instanceSelector:
matchLabels:
dashboards: {{ $myNS }}
{{- else }}
instanceSelector:
{{ $instanceSelector | indent 4 }}
{{- end }}
{{- if not .Values.instanceSelector }}
instanceSelector:
matchLabels:
dashboards: {{ $myNS }}
{{- else }}
instanceSelector:
{{- toYaml .Values.instanceSelector | nindent 4 }}
{{- end }}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant