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
44cebfe7
Commit
44cebfe7
authored
Jan 14, 2020
by
Ryan Cobb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add validation and specs around k8s pod logs
This adds validations and specs around k8s elasticstack pod logs.
parent
bda626cd
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
97 additions
and
1 deletion
+97
-1
ee/app/services/pod_logs_service.rb
ee/app/services/pod_logs_service.rb
+12
-0
ee/spec/fixtures/lib/elasticsearch/query_with_times.json
ee/spec/fixtures/lib/elasticsearch/query_with_times.json
+49
-0
ee/spec/lib/gitlab/elasticsearch/logs_spec.rb
ee/spec/lib/gitlab/elasticsearch/logs_spec.rb
+10
-0
ee/spec/models/ee/clusters/platforms/kubernetes_spec.rb
ee/spec/models/ee/clusters/platforms/kubernetes_spec.rb
+3
-1
ee/spec/services/pod_logs_service_spec.rb
ee/spec/services/pod_logs_service_spec.rb
+20
-0
locale/gitlab.pot
locale/gitlab.pot
+3
-0
No files found.
ee/app/services/pod_logs_service.rb
View file @
44cebfe7
...
@@ -15,6 +15,7 @@ class PodLogsService < ::BaseService
...
@@ -15,6 +15,7 @@ class PodLogsService < ::BaseService
:check_deployment_platform
,
:check_deployment_platform
,
:check_pod_names
,
:check_pod_names
,
:check_pod_name
,
:check_pod_name
,
:check_times
,
:pod_logs
,
:pod_logs
,
:filter_return_keys
:filter_return_keys
...
@@ -72,6 +73,17 @@ class PodLogsService < ::BaseService
...
@@ -72,6 +73,17 @@ class PodLogsService < ::BaseService
success
(
result
)
success
(
result
)
end
end
def
check_times
(
result
)
if
params
[
'start'
]
&&
params
[
'end'
]
Time
.
iso8601
(
params
[
'start'
])
Time
.
iso8601
(
params
[
'end'
])
end
success
(
result
)
rescue
ArgumentError
error
(
_
(
'Invalid start or end time format'
))
end
def
pod_logs
(
result
)
def
pod_logs
(
result
)
response
=
environment
.
deployment_platform
.
read_pod_logs
(
response
=
environment
.
deployment_platform
.
read_pod_logs
(
environment
.
id
,
environment
.
id
,
...
...
ee/spec/fixtures/lib/elasticsearch/query_with_times.json
0 → 100644
View file @
44cebfe7
{
"query"
:
{
"bool"
:
{
"must"
:
[
{
"match_phrase"
:
{
"kubernetes.pod.name"
:
{
"query"
:
"production-6866bc8974-m4sk4"
}
}
},
{
"match_phrase"
:
{
"kubernetes.namespace"
:
{
"query"
:
"autodevops-deploy-9-production"
}
}
}
],
"filter"
:
[
{
"range"
:
{
"@timestamp"
:
{
"gte"
:
"2019-12-13T14:35:34.034Z"
,
"lt"
:
"2019-12-13T14:35:34.034Z"
}
}
}
]
}
},
"sort"
:
[
{
"@timestamp"
:
{
"order"
:
"desc"
}
},
{
"offset"
:
{
"order"
:
"desc"
}
}
],
"_source"
:
[
"@timestamp"
,
"message"
],
"size"
:
500
}
ee/spec/lib/gitlab/elasticsearch/logs_spec.rb
View file @
44cebfe7
...
@@ -18,10 +18,13 @@ describe Gitlab::Elasticsearch::Logs do
...
@@ -18,10 +18,13 @@ describe Gitlab::Elasticsearch::Logs do
let
(
:pod_name
)
{
"production-6866bc8974-m4sk4"
}
let
(
:pod_name
)
{
"production-6866bc8974-m4sk4"
}
let
(
:container_name
)
{
"auto-deploy-app"
}
let
(
:container_name
)
{
"auto-deploy-app"
}
let
(
:search
)
{
"foo +bar "
}
let
(
:search
)
{
"foo +bar "
}
let
(
:start_time
)
{
"2019-12-13T14:35:34.034Z"
}
let
(
:end_time
)
{
"2019-12-13T14:35:34.034Z"
}
let
(
:body
)
{
JSON
.
parse
(
fixture_file
(
'lib/elasticsearch/query.json'
,
dir:
'ee'
))
}
let
(
:body
)
{
JSON
.
parse
(
fixture_file
(
'lib/elasticsearch/query.json'
,
dir:
'ee'
))
}
let
(
:body_with_container
)
{
JSON
.
parse
(
fixture_file
(
'lib/elasticsearch/query_with_container.json'
,
dir:
'ee'
))
}
let
(
:body_with_container
)
{
JSON
.
parse
(
fixture_file
(
'lib/elasticsearch/query_with_container.json'
,
dir:
'ee'
))
}
let
(
:body_with_search
)
{
JSON
.
parse
(
fixture_file
(
'lib/elasticsearch/query_with_search.json'
,
dir:
'ee'
))
}
let
(
:body_with_search
)
{
JSON
.
parse
(
fixture_file
(
'lib/elasticsearch/query_with_search.json'
,
dir:
'ee'
))
}
let
(
:body_with_times
)
{
JSON
.
parse
(
fixture_file
(
'lib/elasticsearch/query_with_times.json'
,
dir:
'ee'
))
}
RSpec
::
Matchers
.
define
:a_hash_equal_to_json
do
|
expected
|
RSpec
::
Matchers
.
define
:a_hash_equal_to_json
do
|
expected
|
match
do
|
actual
|
match
do
|
actual
|
...
@@ -50,5 +53,12 @@ describe Gitlab::Elasticsearch::Logs do
...
@@ -50,5 +53,12 @@ describe Gitlab::Elasticsearch::Logs do
result
=
subject
.
pod_logs
(
namespace
,
pod_name
,
nil
,
search
)
result
=
subject
.
pod_logs
(
namespace
,
pod_name
,
nil
,
search
)
expect
(
result
).
to
eq
([
es_message_4
,
es_message_3
,
es_message_2
,
es_message_1
])
expect
(
result
).
to
eq
([
es_message_4
,
es_message_3
,
es_message_2
,
es_message_1
])
end
end
it
'can further filter the logs by start_time and end_time'
do
expect
(
client
).
to
receive
(
:search
).
with
(
body:
a_hash_equal_to_json
(
body_with_times
)).
and_return
(
es_response
)
result
=
subject
.
pod_logs
(
namespace
,
pod_name
,
nil
,
nil
,
start_time
,
end_time
)
expect
(
result
).
to
eq
([
es_message_4
,
es_message_3
,
es_message_2
,
es_message_1
])
end
end
end
end
end
ee/spec/models/ee/clusters/platforms/kubernetes_spec.rb
View file @
44cebfe7
...
@@ -268,7 +268,9 @@ describe Clusters::Platforms::Kubernetes do
...
@@ -268,7 +268,9 @@ describe Clusters::Platforms::Kubernetes do
'pod_name'
=>
pod_name
,
'pod_name'
=>
pod_name
,
'namespace'
=>
namespace
,
'namespace'
=>
namespace
,
'container'
=>
container
,
'container'
=>
container
,
'search'
=>
nil
'search'
=>
nil
,
'start_time'
=>
nil
,
'end_time'
=>
nil
}
}
]
]
end
end
...
...
ee/spec/services/pod_logs_service_spec.rb
View file @
44cebfe7
...
@@ -197,6 +197,26 @@ describe PodLogsService do
...
@@ -197,6 +197,26 @@ describe PodLogsService do
it_behaves_like
'success'
it_behaves_like
'success'
end
end
context
'when start and end time is specified'
do
let
(
:pod_name
)
{
'some-pod'
}
let
(
:container_name
)
{
nil
}
let
(
:start_time
)
{
'2019-12-13T14:35:34.034Z'
}
let
(
:end_time
)
{
'2019-12-13T14:35:34.034Z'
}
include_context
'return success'
it_behaves_like
'success'
end
context
'when start and end time are invalid'
do
let
(
:pod_name
)
{
'some-pod'
}
let
(
:container_name
)
{
nil
}
let
(
:start_time
)
{
'1'
}
let
(
:end_time
)
{
'2'
}
it_behaves_like
'error'
,
'Invalid start or end time format'
end
context
'when error is returned'
do
context
'when error is returned'
do
include_context
'return error'
,
'Kubernetes API returned status code: 400'
include_context
'return error'
,
'Kubernetes API returned status code: 400'
...
...
locale/gitlab.pot
View file @
44cebfe7
...
@@ -10177,6 +10177,9 @@ msgstr ""
...
@@ -10177,6 +10177,9 @@ msgstr ""
msgid "Invalid server response"
msgid "Invalid server response"
msgstr ""
msgstr ""
msgid "Invalid start or end time format"
msgstr ""
msgid "Invalid two-factor code."
msgid "Invalid two-factor code."
msgstr ""
msgstr ""
...
...
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