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 validations to DatadogDashboardSpec #1704

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

Conversation

shuheiktgw
Copy link
Collaborator

What does this PR do?

Add validations to DatadogDashboardSpec.

Motivation

The same with #1694, but for DatadogDashboardSpec.

Additional Notes

N/A

Minimum Agent Versions

N/A

Describe your test plan

I've tested it locally with the following two manifests.

$ cat missing.yaml
apiVersion: datadoghq.com/v1alpha1
kind: DatadogDashboard
metadata:
  name: example-dashboard
  namespace: system
spec:
  # title: test
  # layoutType: ordered
  tags:
    - "team:tagtest"
  templateVariables:
    - availableValues:
        - host1
        - host2
        - host3
      name: first
      prefix: bar-foo
  notifyList:
    - [email protected]
  widgets: '[{
            "id": 2639892738901474,
            "definition": {
                "title": "",
                "title_size": "16",
                "title_align": "left",
                "show_legend": true,
                "legend_layout": "auto",
                "legend_columns": [
                    "avg",
                    "min",
                    "max",
                    "value",
                    "sum"
                ],
                "type": "timeseries",
                "requests": [
                    {
                        "formulas": [
                            {
                                "formula": "query1"
                            }
                        ],
                        "queries": [
                            {
                                "name": "query1",
                                "data_source": "metrics",
                                "query": "avg:system.cpu.user{*} by {host}"
                            }
                        ],
                        "response_format": "timeseries",
                        "style": {
                            "palette": "dog_classic",
                            "order_by": "values",
                            "line_type": "solid",
                            "line_width": "normal"
                        },
                        "display_type": "line"
                    }
                ]
            },
            "layout": {
                "x": 0,
                "y": 0,
                "width": 4,
                "height": 2
            }
         }]'

$ k apply -f missing.yaml
The DatadogDashboard "example-dashboard" is invalid:
* spec.layoutType: Required value
* spec.title: Required value

$ cat empty.yaml
apiVersion: datadoghq.com/v1alpha1
kind: DatadogDashboard
metadata:
  name: example-dashboard
  namespace: system
spec:
  title: ""
  layoutType: ""
  tags:
    - "team:tagtest"
  templateVariables:
    - availableValues:
        - host1
        - host2
        - host3
      name: first
      prefix: bar-foo
  notifyList:
    - [email protected]
  widgets: '[{
            "id": 2639892738901474,
            "definition": {
                "title": "",
                "title_size": "16",
                "title_align": "left",
                "show_legend": true,
                "legend_layout": "auto",
                "legend_columns": [
                    "avg",
                    "min",
                    "max",
                    "value",
                    "sum"
                ],
                "type": "timeseries",
                "requests": [
                    {
                        "formulas": [
                            {
                                "formula": "query1"
                            }
                        ],
                        "queries": [
                            {
                                "name": "query1",
                                "data_source": "metrics",
                                "query": "avg:system.cpu.user{*} by {host}"
                            }
                        ],
                        "response_format": "timeseries",
                        "style": {
                            "palette": "dog_classic",
                            "order_by": "values",
                            "line_type": "solid",
                            "line_width": "normal"
                        },
                        "display_type": "line"
                    }
                ]
            },
            "layout": {
                "x": 0,
                "y": 0,
                "width": 4,
                "height": 2
            }
         }]'

$ k apply -f empty.yaml
The DatadogDashboard "example-dashboard" is invalid:
* spec.layoutType: Unsupported value: "": supported values: "ordered", "free"
* spec.title: Invalid value: "": spec.title in body should be at least 1 chars long

Checklist

  • PR has at least one valid label: bug, enhancement, refactoring, documentation, tooling, and/or dependencies
  • PR has a milestone or the qa/skip-qa label

@shuheiktgw shuheiktgw added the enhancement New feature or request label Feb 18, 2025
@shuheiktgw shuheiktgw requested a review from a team as a code owner February 18, 2025 08:07
@codecov-commenter
Copy link

codecov-commenter commented Feb 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 49.33%. Comparing base (0cc6abb) to head (b016472).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1704   +/-   ##
=======================================
  Coverage   49.33%   49.33%           
=======================================
  Files         219      219           
  Lines       21314    21314           
=======================================
  Hits        10515    10515           
  Misses      10252    10252           
  Partials      547      547           
Flag Coverage Δ
unittests 49.33% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0cc6abb...b016472. Read the comment docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants