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
9ce52b06
Commit
9ce52b06
authored
Mar 19, 2020
by
Mikolaj Wawrzyniak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add annotation model
Add model for annotations relation along with spec, factory, and associations.
parent
c49ea125
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
111 additions
and
0 deletions
+111
-0
app/models/clusters/cluster.rb
app/models/clusters/cluster.rb
+1
-0
app/models/environment.rb
app/models/environment.rb
+1
-0
app/models/metrics/dashboard/annotation.rb
app/models/metrics/dashboard/annotation.rb
+33
-0
locale/gitlab.pot
locale/gitlab.pot
+6
-0
spec/factories/metrics/dashboard/annotations.rb
spec/factories/metrics/dashboard/annotations.rb
+15
-0
spec/models/clusters/cluster_spec.rb
spec/models/clusters/cluster_spec.rb
+1
-0
spec/models/environment_spec.rb
spec/models/environment_spec.rb
+1
-0
spec/models/metrics/dashboard/annotation_spec.rb
spec/models/metrics/dashboard/annotation_spec.rb
+53
-0
No files found.
app/models/clusters/cluster.rb
View file @
9ce52b06
...
...
@@ -59,6 +59,7 @@ module Clusters
has_one_cluster_application
:elastic_stack
has_many
:kubernetes_namespaces
has_many
:metrics_dashboard_annotations
,
class_name:
'Metrics::Dashboard::Annotation'
,
inverse_of: :cluster
accepts_nested_attributes_for
:provider_gcp
,
update_only:
true
accepts_nested_attributes_for
:provider_aws
,
update_only:
true
...
...
app/models/environment.rb
View file @
9ce52b06
...
...
@@ -18,6 +18,7 @@ class Environment < ApplicationRecord
has_many
:successful_deployments
,
->
{
success
},
class_name:
'Deployment'
has_many
:active_deployments
,
->
{
active
},
class_name:
'Deployment'
has_many
:prometheus_alerts
,
inverse_of: :environment
has_many
:metrics_dashboard_annotations
,
class_name:
'Metrics::Dashboard::Annotation'
,
inverse_of: :environment
has_many
:self_managed_prometheus_alert_events
,
inverse_of: :environment
has_one
:last_deployment
,
->
{
success
.
order
(
'deployments.id DESC'
)
},
class_name:
'Deployment'
...
...
app/models/metrics/dashboard/annotation.rb
0 → 100644
View file @
9ce52b06
# frozen_string_literal: true
module
Metrics
module
Dashboard
class
Annotation
<
ApplicationRecord
self
.
table_name
=
'metrics_dashboard_annotations'
belongs_to
:environment
,
inverse_of: :metrics_dashboard_annotations
belongs_to
:cluster
,
class_name:
'Clusters::Cluster'
,
inverse_of: :metrics_dashboard_annotations
validates
:starting_at
,
presence:
true
validates
:description
,
presence:
true
,
length:
{
maximum:
255
}
validates
:dashboard_path
,
presence:
true
,
length:
{
maximum:
255
}
validates
:panel_xid
,
length:
{
maximum:
255
}
validate
:single_ownership
validate
:orphaned_annotation
private
def
single_ownership
return
if
cluster
.
nil?
^
environment
.
nil?
errors
.
add
(
:base
,
s_
(
"Metrics::Dashboard::Annotation|Annotation can't belong to both a cluster and an environment at the same time"
))
end
def
orphaned_annotation
return
if
cluster
.
present?
||
environment
.
present?
errors
.
add
(
:base
,
s_
(
"Metrics::Dashboard::Annotation|Annotation must belong to a cluster or an environment"
))
end
end
end
end
locale/gitlab.pot
View file @
9ce52b06
...
...
@@ -12755,6 +12755,12 @@ msgstr ""
msgid "Metrics for environment"
msgstr ""
msgid "Metrics::Dashboard::Annotation|Annotation can't belong to both a cluster and an environment at the same time"
msgstr ""
msgid "Metrics::Dashboard::Annotation|Annotation must belong to a cluster or an environment"
msgstr ""
msgid "Metrics|Add metric"
msgstr ""
...
...
spec/factories/metrics/dashboard/annotations.rb
0 → 100644
View file @
9ce52b06
# frozen_string_literal: true
FactoryBot
.
define
do
factory
:metrics_dashboard_annotation
,
class:
'::Metrics::Dashboard::Annotation'
do
description
{
"Dashbaord annoation description"
}
dashboard_path
{
"custom_dashbaord.yml"
}
starting_at
{
Time
.
current
}
environment
trait
:with_cluster
do
cluster
environment
{
nil
}
end
end
end
spec/models/clusters/cluster_spec.rb
View file @
9ce52b06
...
...
@@ -27,6 +27,7 @@ describe Clusters::Cluster, :use_clean_rails_memory_store_caching do
it
{
is_expected
.
to
have_many
(
:kubernetes_namespaces
)
}
it
{
is_expected
.
to
have_one
(
:cluster_project
)
}
it
{
is_expected
.
to
have_many
(
:deployment_clusters
)
}
it
{
is_expected
.
to
have_many
(
:metrics_dashboard_annotations
)
}
it
{
is_expected
.
to
delegate_method
(
:status
).
to
(
:provider
)
}
it
{
is_expected
.
to
delegate_method
(
:status_reason
).
to
(
:provider
)
}
...
...
spec/models/environment_spec.rb
View file @
9ce52b06
...
...
@@ -17,6 +17,7 @@ describe Environment, :use_clean_rails_memory_store_caching do
it
{
is_expected
.
to
belong_to
(
:project
).
required
}
it
{
is_expected
.
to
have_many
(
:deployments
)
}
it
{
is_expected
.
to
have_many
(
:metrics_dashboard_annotations
)
}
it
{
is_expected
.
to
delegate_method
(
:stop_action
).
to
(
:last_deployment
)
}
it
{
is_expected
.
to
delegate_method
(
:manual_actions
).
to
(
:last_deployment
)
}
...
...
spec/models/metrics/dashboard/annotation_spec.rb
0 → 100644
View file @
9ce52b06
# frozen_string_literal: true
require
'spec_helper'
describe
Metrics
::
Dashboard
::
Annotation
do
describe
'associations'
do
it
{
is_expected
.
to
belong_to
(
:environment
).
inverse_of
(
:metrics_dashboard_annotations
)
}
it
{
is_expected
.
to
belong_to
(
:cluster
).
class_name
(
'Clusters::Cluster'
).
inverse_of
(
:metrics_dashboard_annotations
)
}
end
describe
'validation'
do
it
{
is_expected
.
to
validate_presence_of
(
:description
)
}
it
{
is_expected
.
to
validate_presence_of
(
:dashboard_path
)
}
it
{
is_expected
.
to
validate_presence_of
(
:starting_at
)
}
it
{
is_expected
.
to
validate_length_of
(
:dashboard_path
).
is_at_most
(
255
)
}
it
{
is_expected
.
to
validate_length_of
(
:panel_xid
).
is_at_most
(
255
)
}
it
{
is_expected
.
to
validate_length_of
(
:description
).
is_at_most
(
255
)
}
context
'orphaned annotation'
do
subject
{
build
(
:metrics_dashboard_annotation
,
environment:
nil
)
}
it
{
is_expected
.
not_to
be_valid
}
it
'reports error about both missing relations'
do
subject
.
valid?
expect
(
subject
.
errors
.
full_messages
).
to
include
(
/Annotation must belong to a cluster or an environment/
)
end
end
context
'environments annotation'
do
subject
{
build
(
:metrics_dashboard_annotation
)
}
it
{
is_expected
.
to
be_valid
}
end
context
'clusters annotation'
do
subject
{
build
(
:metrics_dashboard_annotation
,
:with_cluster
)
}
it
{
is_expected
.
to
be_valid
}
end
context
'annotation with shared ownership'
do
subject
{
build
(
:metrics_dashboard_annotation
,
:with_cluster
,
environment:
build
(
:environment
)
)
}
it
'reports error about both shared ownership'
do
subject
.
valid?
expect
(
subject
.
errors
.
full_messages
).
to
include
(
/Annotation can't belong to both a cluster and an environment at the same time/
)
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