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
38d7348e
Commit
38d7348e
authored
Apr 14, 2020
by
Kirstie Cook
Committed by
Robert Speicher
Apr 14, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Start annotations post endpoint
Add annotations post endpoint specs Add changelog entry
parent
75a8eeef
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
153 additions
and
0 deletions
+153
-0
changelogs/unreleased/211460-annotations-post-endpoint-revised.yml
...s/unreleased/211460-annotations-post-endpoint-revised.yml
+5
-0
lib/api/api.rb
lib/api/api.rb
+1
-0
lib/api/entities/metrics/dashboard/annotation.rb
lib/api/entities/metrics/dashboard/annotation.rb
+19
-0
lib/api/metrics/dashboard/annotations.rb
lib/api/metrics/dashboard/annotations.rb
+41
-0
spec/requests/api/metrics/dashboard/annotations_spec.rb
spec/requests/api/metrics/dashboard/annotations_spec.rb
+87
-0
No files found.
changelogs/unreleased/211460-annotations-post-endpoint-revised.yml
0 → 100644
View file @
38d7348e
---
title
:
API endpoint to create annotations for environments dashboard
merge_request
:
29089
author
:
type
:
added
lib/api/api.rb
View file @
38d7348e
...
...
@@ -152,6 +152,7 @@ module API
mount
::
API
::
Members
mount
::
API
::
MergeRequestDiffs
mount
::
API
::
MergeRequests
mount
::
API
::
Metrics
::
Dashboard
::
Annotations
mount
::
API
::
Namespaces
mount
::
API
::
Notes
mount
::
API
::
Discussions
...
...
lib/api/entities/metrics/dashboard/annotation.rb
0 → 100644
View file @
38d7348e
# frozen_string_literal: true
module
API
module
Entities
module
Metrics
module
Dashboard
class
Annotation
<
Grape
::
Entity
expose
:id
expose
:starting_at
expose
:ending_at
expose
:dashboard_path
expose
:description
expose
:environment_id
expose
:cluster_id
end
end
end
end
end
lib/api/metrics/dashboard/annotations.rb
0 → 100644
View file @
38d7348e
# frozen_string_literal: true
module
API
module
Metrics
module
Dashboard
class
Annotations
<
Grape
::
API
desc
'Create a new monitoring dashboard annotation'
do
success
Entities
::
Metrics
::
Dashboard
::
Annotation
end
params
do
requires
:starting_at
,
type:
DateTime
,
desc:
'Date time indicating starting moment to which the annotation relates.'
optional
:ending_at
,
type:
DateTime
,
desc:
'Date time indicating ending moment to which the annotation relates.'
requires
:dashboard_path
,
type:
String
,
desc:
'The path to a file defining the dashboard on which the annotation should be added'
requires
:description
,
type:
String
,
desc:
'The description of the annotation'
end
resource
:environments
do
post
':id/metrics_dashboard/annotations'
do
environment
=
::
Environment
.
find
(
params
[
:id
])
not_found!
unless
Feature
.
enabled?
(
:metrics_dashboard_annotations
,
environment
.
project
)
forbidden!
unless
can?
(
current_user
,
:create_metrics_dashboard_annotation
,
environment
)
result
=
::
Metrics
::
Dashboard
::
Annotations
::
CreateService
.
new
(
current_user
,
declared
(
params
).
merge
(
environment:
environment
)).
execute
if
result
[
:status
]
==
:success
present
result
[
:annotation
],
with:
Entities
::
Metrics
::
Dashboard
::
Annotation
else
error!
(
result
,
400
)
end
end
end
end
end
end
end
spec/requests/api/metrics/dashboard/annotations_spec.rb
0 → 100644
View file @
38d7348e
# frozen_string_literal: true
require
'spec_helper'
describe
API
::
Metrics
::
Dashboard
::
Annotations
do
let_it_be
(
:user
)
{
create
(
:user
)
}
let_it_be
(
:project
)
{
create
(
:project
,
:private
,
:repository
,
namespace:
user
.
namespace
)
}
let_it_be
(
:environment
)
{
create
(
:environment
,
project:
project
)
}
let
(
:dashboard
)
{
'config/prometheus/common_metrics.yml'
}
let
(
:starting_at
)
{
Time
.
now
.
iso8601
}
let
(
:ending_at
)
{
1
.
hour
.
from_now
.
iso8601
}
let
(
:params
)
{
attributes_for
(
:metrics_dashboard_annotation
,
environment:
environment
,
starting_at:
starting_at
,
ending_at:
ending_at
,
dashboard_path:
dashboard
)}
describe
'POST /environments/:environment_id/metrics_dashboard/annotations'
do
before
:all
do
project
.
add_developer
(
user
)
end
context
'feature flag metrics_dashboard_annotations'
do
context
'is on'
do
before
do
stub_feature_flags
(
metrics_dashboard_annotations:
{
enabled:
true
,
thing:
project
})
end
context
'with correct permissions'
do
context
'with valid parameters'
do
it
'creates a new annotation'
,
:aggregate_failures
do
post
api
(
"/environments/
#{
environment
.
id
}
/metrics_dashboard/annotations"
,
user
),
params:
params
expect
(
response
).
to
have_gitlab_http_status
(
:created
)
expect
(
json_response
[
'environment_id'
]).
to
eq
(
environment
.
id
)
expect
(
json_response
[
'starting_at'
].
to_time
).
to
eq
(
starting_at
.
to_time
)
expect
(
json_response
[
'ending_at'
].
to_time
).
to
eq
(
ending_at
.
to_time
)
expect
(
json_response
[
'description'
]).
to
eq
(
params
[
:description
])
expect
(
json_response
[
'dashboard_path'
]).
to
eq
(
dashboard
)
end
end
context
'with invalid parameters'
do
it
'returns error messsage'
do
post
api
(
"/environments/
#{
environment
.
id
}
/metrics_dashboard/annotations"
,
user
),
params:
{
dashboard_path:
nil
,
starting_at:
nil
,
description:
nil
}
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
expect
(
json_response
[
'message'
]).
to
include
({
"starting_at"
=>
[
"can't be blank"
],
"description"
=>
[
"can't be blank"
],
"dashboard_path"
=>
[
"can't be blank"
]
})
end
end
context
'with undeclared params'
do
before
do
params
[
:undeclared_param
]
=
'xyz'
end
it
'filters out undeclared params'
do
expect
(
::
Metrics
::
Dashboard
::
Annotations
::
CreateService
).
to
receive
(
:new
).
with
(
user
,
hash_excluding
(
:undeclared_param
))
post
api
(
"/environments/
#{
environment
.
id
}
/metrics_dashboard/annotations"
,
user
),
params:
params
end
end
end
context
'without correct permissions'
do
let_it_be
(
:guest
)
{
create
(
:user
)
}
before
do
project
.
add_guest
(
guest
)
end
it
'returns error messsage'
do
post
api
(
"/environments/
#{
environment
.
id
}
/metrics_dashboard/annotations"
,
guest
),
params:
params
expect
(
response
).
to
have_gitlab_http_status
(
:forbidden
)
end
end
end
context
'is off'
do
before
do
stub_feature_flags
(
metrics_dashboard_annotations:
{
enabled:
false
,
thing:
project
})
end
it
'returns error messsage'
do
post
api
(
"/environments/
#{
environment
.
id
}
/metrics_dashboard/annotations"
,
user
),
params:
params
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
end
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