Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
aea00b87
Commit
aea00b87
authored
Jan 28, 2020
by
Kirstie Cook
Committed by
Nick Thomas
Jan 28, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding validation models
Initial commit to add PrometheusDashboard object
parent
36b70d9c
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
344 additions
and
0 deletions
+344
-0
app/models/performance_monitoring/prometheus_dashboard.rb
app/models/performance_monitoring/prometheus_dashboard.rb
+31
-0
app/models/performance_monitoring/prometheus_metric.rb
app/models/performance_monitoring/prometheus_metric.rb
+25
-0
app/models/performance_monitoring/prometheus_panel.rb
app/models/performance_monitoring/prometheus_panel.rb
+24
-0
app/models/performance_monitoring/prometheus_panel_group.rb
app/models/performance_monitoring/prometheus_panel_group.rb
+22
-0
changelogs/unreleased/custom-dashboard-validation.yml
changelogs/unreleased/custom-dashboard-validation.yml
+5
-0
ee/spec/models/performance_monitoring/prometheus_dashboard_spec.rb
...odels/performance_monitoring/prometheus_dashboard_spec.rb
+69
-0
ee/spec/models/performance_monitoring/prometheus_metric_spec.rb
...c/models/performance_monitoring/prometheus_metric_spec.rb
+59
-0
ee/spec/models/performance_monitoring/prometheus_panel_group_spec.rb
...els/performance_monitoring/prometheus_panel_group_spec.rb
+54
-0
ee/spec/models/performance_monitoring/prometheus_panel_spec.rb
...ec/models/performance_monitoring/prometheus_panel_spec.rb
+55
-0
No files found.
app/models/performance_monitoring/prometheus_dashboard.rb
0 → 100644
View file @
aea00b87
# frozen_string_literal: true
module
PerformanceMonitoring
class
PrometheusDashboard
include
ActiveModel
::
Model
attr_accessor
:dashboard
,
:panel_groups
validates
:dashboard
,
presence:
true
validates
:panel_groups
,
presence:
true
def
self
.
from_json
(
json_content
)
dashboard
=
new
(
dashboard:
json_content
[
'dashboard'
],
panel_groups:
json_content
[
'panel_groups'
].
map
{
|
group
|
PrometheusPanelGroup
.
from_json
(
group
)
}
)
dashboard
.
tap
(
&
:validate!
)
end
def
to_yaml
self
.
as_json
(
only:
valid_attributes
).
to_yaml
end
private
def
valid_attributes
%w(panel_groups panels metrics group priority type title y_label weight id unit label query query_range dashboard)
end
end
end
app/models/performance_monitoring/prometheus_metric.rb
0 → 100644
View file @
aea00b87
# frozen_string_literal: true
module
PerformanceMonitoring
class
PrometheusMetric
include
ActiveModel
::
Model
attr_accessor
:id
,
:unit
,
:label
,
:query
,
:query_range
validates
:unit
,
presence:
true
validates
:query
,
presence:
true
,
unless: :query_range
validates
:query_range
,
presence:
true
,
unless: :query
def
self
.
from_json
(
json_content
)
metric
=
PrometheusMetric
.
new
(
id:
json_content
[
'id'
],
unit:
json_content
[
'unit'
],
label:
json_content
[
'label'
],
query:
json_content
[
'query'
],
query_range:
json_content
[
'query_range'
]
)
metric
.
tap
(
&
:validate!
)
end
end
end
app/models/performance_monitoring/prometheus_panel.rb
0 → 100644
View file @
aea00b87
# frozen_string_literal: true
module
PerformanceMonitoring
class
PrometheusPanel
include
ActiveModel
::
Model
attr_accessor
:type
,
:title
,
:y_label
,
:weight
,
:metrics
validates
:title
,
presence:
true
validates
:metrics
,
presence:
true
def
self
.
from_json
(
json_content
)
panel
=
new
(
type:
json_content
[
'type'
],
title:
json_content
[
'title'
],
y_label:
json_content
[
'y_label'
],
weight:
json_content
[
'weight'
],
metrics:
json_content
[
'metrics'
].
map
{
|
metric
|
PrometheusMetric
.
from_json
(
metric
)
}
)
panel
.
tap
(
&
:validate!
)
end
end
end
app/models/performance_monitoring/prometheus_panel_group.rb
0 → 100644
View file @
aea00b87
# frozen_string_literal: true
module
PerformanceMonitoring
class
PrometheusPanelGroup
include
ActiveModel
::
Model
attr_accessor
:group
,
:priority
,
:panels
validates
:group
,
presence:
true
validates
:panels
,
presence:
true
def
self
.
from_json
(
json_content
)
panel_group
=
new
(
group:
json_content
[
'group'
],
priority:
json_content
[
'priority'
],
panels:
json_content
[
'panels'
].
map
{
|
panel
|
PrometheusPanel
.
from_json
(
panel
)
}
)
panel_group
.
tap
(
&
:validate!
)
end
end
end
changelogs/unreleased/custom-dashboard-validation.yml
0 → 100644
View file @
aea00b87
---
title
:
Add validation for custom PrometheusDashboard
merge_request
:
22893
author
:
type
:
added
ee/spec/models/performance_monitoring/prometheus_dashboard_spec.rb
0 → 100644
View file @
aea00b87
# frozen_string_literal: true
require
'spec_helper'
describe
PerformanceMonitoring
::
PrometheusDashboard
do
let
(
:json_content
)
do
{
"dashboard"
=>
"Dashboard Title"
,
"panel_groups"
=>
[{
"group"
=>
"Group Title"
,
"panels"
=>
[{
"type"
=>
"area-chart"
,
"title"
=>
"Chart Title"
,
"y_label"
=>
"Y-Axis"
,
"metrics"
=>
[{
"id"
=>
"metric_of_ages"
,
"unit"
=>
"count"
,
"label"
=>
"Metric of Ages"
,
"query_range"
=>
"http_requests_total"
}]
}]
}]
}
end
describe
'.from_json'
do
subject
{
described_class
.
from_json
(
json_content
)
}
it
'creates a PrometheusDashboard object'
do
expect
(
subject
).
to
be_a
PerformanceMonitoring
::
PrometheusDashboard
expect
(
subject
.
dashboard
).
to
eq
(
json_content
[
'dashboard'
])
expect
(
subject
.
panel_groups
).
to
all
(
be_a
PerformanceMonitoring
::
PrometheusPanelGroup
)
end
describe
'validations'
do
context
'when dashboard is missing'
do
before
do
json_content
[
'dashboard'
]
=
nil
end
subject
{
described_class
.
from_json
(
json_content
)
}
it
{
expect
{
subject
}.
to
raise_error
(
ActiveModel
::
ValidationError
)
}
end
context
'when panel groups are missing'
do
before
do
json_content
[
'panel_groups'
]
=
[]
end
subject
{
described_class
.
from_json
(
json_content
)
}
it
{
expect
{
subject
}.
to
raise_error
(
ActiveModel
::
ValidationError
)
}
end
end
end
describe
'#to_yaml'
do
let
(
:expected_yaml
)
do
"---
\n
panel_groups:
\n
- panels:
\n
- metrics:
\n
- id: metric_of_ages
\n
unit: count
\n
label: Metric of Ages
\n
query:
\n
query_range: http_requests_total
\n
type: area-chart
\n
title: Chart Title
\n
y_label: Y-Axis
\n
weight:
\n
group: Group Title
\n
priority:
\n
dashboard: Dashboard Title
\n
"
end
let
(
:prometheus_dashboard
)
{
described_class
.
from_json
(
json_content
)
}
let
(
:subject
)
{
prometheus_dashboard
.
to_yaml
}
it
{
is_expected
.
to
eq
(
expected_yaml
)
}
end
end
ee/spec/models/performance_monitoring/prometheus_metric_spec.rb
0 → 100644
View file @
aea00b87
# frozen_string_literal: true
require
'spec_helper'
describe
PerformanceMonitoring
::
PrometheusMetric
do
let
(
:json_content
)
do
{
"id"
=>
"metric_of_ages"
,
"unit"
=>
"count"
,
"label"
=>
"Metric of Ages"
,
"query_range"
=>
"http_requests_total"
}
end
describe
'.from_json'
do
subject
{
described_class
.
from_json
(
json_content
)
}
it
'creates a PrometheusMetric object'
do
expect
(
subject
).
to
be_a
PerformanceMonitoring
::
PrometheusMetric
expect
(
subject
.
id
).
to
eq
(
json_content
[
'id'
])
expect
(
subject
.
unit
).
to
eq
(
json_content
[
'unit'
])
expect
(
subject
.
label
).
to
eq
(
json_content
[
'label'
])
expect
(
subject
.
query_range
).
to
eq
(
json_content
[
'query_range'
])
end
describe
'validations'
do
context
'when unit is missing'
do
before
do
json_content
[
'unit'
]
=
nil
end
subject
{
described_class
.
from_json
(
json_content
)
}
it
{
expect
{
subject
}.
to
raise_error
(
ActiveModel
::
ValidationError
)
}
end
context
'when query and query_range is missing'
do
before
do
json_content
[
'query_range'
]
=
nil
end
subject
{
described_class
.
from_json
(
json_content
)
}
it
{
expect
{
subject
}.
to
raise_error
(
ActiveModel
::
ValidationError
)
}
end
context
'when query_range is missing but query is available'
do
before
do
json_content
[
'query_range'
]
=
nil
json_content
[
'query'
]
=
'http_requests_total'
end
subject
{
described_class
.
from_json
(
json_content
)
}
it
{
is_expected
.
to
be_valid
}
end
end
end
end
ee/spec/models/performance_monitoring/prometheus_panel_group_spec.rb
0 → 100644
View file @
aea00b87
# frozen_string_literal: true
require
'spec_helper'
describe
PerformanceMonitoring
::
PrometheusPanelGroup
do
let
(
:json_content
)
do
{
"group"
=>
"Group Title"
,
"panels"
=>
[{
"type"
=>
"area-chart"
,
"title"
=>
"Chart Title"
,
"y_label"
=>
"Y-Axis"
,
"metrics"
=>
[{
"id"
=>
"metric_of_ages"
,
"unit"
=>
"count"
,
"label"
=>
"Metric of Ages"
,
"query_range"
=>
"http_requests_total"
}]
}]
}
end
describe
'.from_json'
do
subject
{
described_class
.
from_json
(
json_content
)
}
it
'creates a PrometheusPanelGroup object'
do
expect
(
subject
).
to
be_a
PerformanceMonitoring
::
PrometheusPanelGroup
expect
(
subject
.
group
).
to
eq
(
json_content
[
'group'
])
expect
(
subject
.
panels
).
to
all
(
be_a
PerformanceMonitoring
::
PrometheusPanel
)
end
describe
'validations'
do
context
'when group is missing'
do
before
do
json_content
[
'group'
]
=
nil
end
subject
{
described_class
.
from_json
(
json_content
)
}
it
{
expect
{
subject
}.
to
raise_error
(
ActiveModel
::
ValidationError
)
}
end
context
'when panels are missing'
do
before
do
json_content
[
'panels'
]
=
[]
end
subject
{
described_class
.
from_json
(
json_content
)
}
it
{
expect
{
subject
}.
to
raise_error
(
ActiveModel
::
ValidationError
)
}
end
end
end
end
ee/spec/models/performance_monitoring/prometheus_panel_spec.rb
0 → 100644
View file @
aea00b87
# frozen_string_literal: true
require
'spec_helper'
describe
PerformanceMonitoring
::
PrometheusPanel
do
let
(
:json_content
)
do
{
"type"
=>
"area-chart"
,
"title"
=>
"Chart Title"
,
"y_label"
=>
"Y-Axis"
,
"weight"
=>
1
,
"metrics"
=>
[{
"id"
=>
"metric_of_ages"
,
"unit"
=>
"count"
,
"label"
=>
"Metric of Ages"
,
"query_range"
=>
"http_requests_total"
}]
}
end
describe
'.from_json'
do
subject
{
described_class
.
from_json
(
json_content
)
}
it
'creates a PrometheusPanelGroup object'
do
expect
(
subject
).
to
be_a
PerformanceMonitoring
::
PrometheusPanel
expect
(
subject
.
type
).
to
eq
(
json_content
[
'type'
])
expect
(
subject
.
title
).
to
eq
(
json_content
[
'title'
])
expect
(
subject
.
y_label
).
to
eq
(
json_content
[
'y_label'
])
expect
(
subject
.
weight
).
to
eq
(
json_content
[
'weight'
])
expect
(
subject
.
metrics
).
to
all
(
be_a
PerformanceMonitoring
::
PrometheusMetric
)
end
describe
'validations'
do
context
'when title is missing'
do
before
do
json_content
[
'title'
]
=
nil
end
subject
{
described_class
.
from_json
(
json_content
)
}
it
{
expect
{
subject
}.
to
raise_error
(
ActiveModel
::
ValidationError
)
}
end
context
'when metrics are missing'
do
before
do
json_content
[
'metrics'
]
=
[]
end
subject
{
described_class
.
from_json
(
json_content
)
}
it
{
expect
{
subject
}.
to
raise_error
(
ActiveModel
::
ValidationError
)
}
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment