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
e78938d5
Commit
e78938d5
authored
Feb 14, 2020
by
Adrien Kohlbecker
Committed by
Martin Wortschack
Feb 14, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pass logs api URL to frontend
parent
05f5d6e7
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
49 additions
and
50 deletions
+49
-50
ee/app/assets/javascripts/api.js
ee/app/assets/javascripts/api.js
+2
-12
ee/app/models/ee/clusters/platforms/kubernetes.rb
ee/app/models/ee/clusters/platforms/kubernetes.rb
+0
-4
ee/app/models/ee/environment.rb
ee/app/models/ee/environment.rb
+4
-0
ee/app/serializers/ee/environment_entity.rb
ee/app/serializers/ee/environment_entity.rb
+9
-1
ee/spec/frontend/api_spec.js
ee/spec/frontend/api_spec.js
+3
-16
ee/spec/frontend/logs/mock_data.js
ee/spec/frontend/logs/mock_data.js
+1
-1
ee/spec/frontend/logs/stores/actions_spec.js
ee/spec/frontend/logs/stores/actions_spec.js
+9
-14
ee/spec/serializers/environment_entity_spec.rb
ee/spec/serializers/environment_entity_spec.rb
+21
-2
No files found.
ee/app/assets/javascripts/api.js
View file @
e78938d5
...
...
@@ -11,8 +11,6 @@ export default {
groupEpicsPath
:
'
/api/:version/groups/:id/epics?include_ancestor_groups=:includeAncestorGroups&include_descendant_groups=:includeDescendantGroups
'
,
epicIssuePath
:
'
/api/:version/groups/:id/epics/:epic_iid/issues/:issue_id
'
,
k8sPodLogsPath
:
'
:project_path/-/logs/k8s.json
'
,
elasticsearchPodLogsPath
:
'
:project_path/-/logs/elasticsearch.json
'
,
groupPackagesPath
:
'
/api/:version/groups/:id/packages
'
,
projectPackagesPath
:
'
/api/:version/projects/:id/packages
'
,
projectPackagePath
:
'
/api/:version/projects/:id/packages/:package_id
'
,
...
...
@@ -103,17 +101,9 @@ export default {
* @returns {Promise} Axios promise for the result of a GET request of logs
*/
getPodLogs
({
environment
,
podName
,
containerName
,
search
,
start
,
end
})
{
let
baseUrl
;
if
(
environment
.
enable_advanced_logs_querying
)
{
baseUrl
=
this
.
elasticsearchPodLogsPath
;
}
else
{
baseUrl
=
this
.
k8sPodLogsPath
;
}
const
url
=
this
.
buildUrl
(
baseUrl
.
replace
(
'
:project_path
'
,
environment
.
project_path
));
const
url
=
this
.
buildUrl
(
environment
.
logs_api_path
);
const
params
=
{
environment_name
:
environment
.
name
,
};
const
params
=
{};
if
(
podName
)
{
params
.
pod_name
=
podName
;
...
...
ee/app/models/ee/clusters/platforms/kubernetes.rb
View file @
e78938d5
...
...
@@ -32,10 +32,6 @@ module EE
::
Gitlab
::
Kubernetes
::
RolloutStatus
.
from_deployments
(
*
deployments
,
pods:
pods
,
legacy_deployments:
legacy_deployments
)
end
def
elastic_stack_available?
!!
cluster
.
application_elastic_stack
&
.
installed?
end
private
def
read_deployments
(
namespace
)
...
...
ee/app/models/ee/environment.rb
View file @
e78938d5
...
...
@@ -77,6 +77,10 @@ module EE
result
||
::
Gitlab
::
Kubernetes
::
RolloutStatus
.
loading
end
def
elastic_stack_available?
!!
deployment_platform
&
.
cluster
&
.
application_elastic_stack
&
.
installed?
end
private
def
rollout_status_available?
...
...
ee/app/serializers/ee/environment_entity.rb
View file @
e78938d5
...
...
@@ -16,8 +16,16 @@ module EE
project_logs_path
(
environment
.
project
,
environment_name:
environment
.
name
)
end
expose
:logs_api_path
,
if:
->
(
*
)
{
can_read_pod_logs?
}
do
|
environment
|
if
environment
.
elastic_stack_available?
elasticsearch_project_logs_path
(
environment
.
project
,
environment_name:
environment
.
name
,
format: :json
)
else
k8s_project_logs_path
(
environment
.
project
,
environment_name:
environment
.
name
,
format: :json
)
end
end
expose
:enable_advanced_logs_querying
,
if:
->
(
*
)
{
can_read_pod_logs?
}
do
|
environment
|
environment
.
deployment_platform
&
.
elastic_stack_available?
environment
.
elastic_stack_available?
end
end
...
...
ee/spec/frontend/api_spec.js
View file @
e78938d5
...
...
@@ -166,14 +166,14 @@ describe('Api', () => {
describe
(
'
getPodLogs
'
,
()
=>
{
const
projectPath
=
'
/root/test-project
'
;
const
environmentName
=
'
production
'
;
const
podName
=
'
pod
'
;
const
containerName
=
'
container
'
;
const
search
=
'
foo +bar
'
;
const
expectedUrl
=
'
/gitlab/dummy_api_path.json
'
;
const
environment
=
{
name
:
environmentName
,
enable_advanced_logs_querying
:
false
,
project_path
:
projectPath
,
logs_api_path
:
'
/dummy_api_path.json
'
,
};
const
getRequest
=
()
=>
mock
.
history
.
get
[
0
];
...
...
@@ -187,13 +187,10 @@ describe('Api', () => {
});
it
(
'
calls `axios.get` with pod_name and container_name
'
,
done
=>
{
const
expectedUrl
=
`
${
dummyUrlRoot
}${
projectPath
}
/-/logs/k8s.json`
;
Api
.
getPodLogs
({
environment
,
podName
,
containerName
})
.
then
(()
=>
{
expect
(
getRequest
().
url
).
toBe
(
expectedUrl
);
expect
(
getRequest
().
params
).
toEqual
({
environment_name
:
environmentName
,
pod_name
:
podName
,
container_name
:
containerName
,
});
...
...
@@ -203,27 +200,20 @@ describe('Api', () => {
});
it
(
'
calls `axios.get` without pod_name and container_name
'
,
done
=>
{
const
expectedUrl
=
`
${
dummyUrlRoot
}${
projectPath
}
/-/logs/k8s.json`
;
Api
.
getPodLogs
({
environment
})
.
then
(()
=>
{
expect
(
getRequest
().
url
).
toBe
(
expectedUrl
);
expect
(
getRequest
().
params
).
toEqual
({
environment_name
:
environmentName
,
});
expect
(
getRequest
().
params
).
toEqual
({});
})
.
then
(
done
)
.
catch
(
done
.
fail
);
});
it
(
'
calls `axios.get` with pod_name
'
,
done
=>
{
const
expectedUrl
=
`
${
dummyUrlRoot
}${
projectPath
}
/-/logs/k8s.json`
;
Api
.
getPodLogs
({
environment
,
podName
})
.
then
(()
=>
{
expect
(
getRequest
().
url
).
toBe
(
expectedUrl
);
expect
(
getRequest
().
params
).
toEqual
({
environment_name
:
environmentName
,
pod_name
:
podName
,
});
})
...
...
@@ -232,13 +222,10 @@ describe('Api', () => {
});
it
(
'
calls `axios.get` with pod_name and search
'
,
done
=>
{
const
expectedUrl
=
`
${
dummyUrlRoot
}${
projectPath
}
/-/logs/k8s.json`
;
Api
.
getPodLogs
({
environment
,
podName
,
search
})
.
then
(()
=>
{
expect
(
getRequest
().
url
).
toBe
(
expectedUrl
);
expect
(
getRequest
().
params
).
toEqual
({
environment_name
:
environmentName
,
pod_name
:
podName
,
search
,
});
...
...
ee/spec/frontend/logs/mock_data.js
View file @
e78938d5
...
...
@@ -6,9 +6,9 @@ export const mockDocumentationPath = '/documentation.md';
const
makeMockEnvironment
=
(
id
,
name
,
advancedQuerying
)
=>
({
id
,
logs_path
:
`
${
mockProjectPath
}
/environments/
${
id
}
/logs`
,
project_path
:
mockProjectPath
,
name
,
logs_api_path
:
'
/dummy_logs_path.json
'
,
enable_advanced_logs_querying
:
advancedQuerying
,
});
...
...
ee/spec/frontend/logs/stores/actions_spec.js
View file @
e78938d5
...
...
@@ -154,12 +154,11 @@ describe('Logs Store actions', () => {
state
.
environments
.
current
=
mockEnvName
;
state
.
pods
.
current
=
mockPodName
;
const
endpoint
=
`/
${
mockProjectPath
}
/-/logs/elasticsearch.json`
;
const
endpoint
=
'
/dummy_logs_path.json
'
;
mock
.
onGet
(
endpoint
,
{
params
:
{
environment_name
:
mockEnvName
,
pod_name
:
mockPodName
,
...
mockDefaultRange
,
},
...
...
@@ -194,12 +193,11 @@ describe('Logs Store actions', () => {
state
.
pods
.
current
=
mockPodName
;
state
.
timeRange
.
current
=
mockFixedRange
;
const
endpoint
=
`/
${
mockProjectPath
}
/-/logs/elasticsearch.json`
;
const
endpoint
=
'
/dummy_logs_path.json
'
;
mock
.
onGet
(
endpoint
,
{
params
:
{
environment_name
:
mockEnvName
,
pod_name
:
mockPodName
,
start
:
mockFixedRange
.
start
,
end
:
mockFixedRange
.
end
,
...
...
@@ -233,12 +231,11 @@ describe('Logs Store actions', () => {
state
.
search
=
mockSearch
;
state
.
timeRange
.
current
=
'
INVALID_TIME_RANGE
'
;
const
endpoint
=
`/
${
mockProjectPath
}
/-/logs/elasticsearch.json`
;
const
endpoint
=
'
/dummy_logs_path.json
'
;
mock
.
onGet
(
endpoint
,
{
params
:
{
environment_name
:
mockEnvName
,
pod_name
:
mockPodName
,
search
:
mockSearch
,
},
...
...
@@ -275,11 +272,9 @@ describe('Logs Store actions', () => {
state
.
environments
.
options
=
mockEnvironments
;
state
.
environments
.
current
=
mockEnvName
;
const
endpoint
=
`/
${
mockProjectPath
}
/-/logs/elasticsearch.json`
;
const
endpoint
=
'
/dummy_logs_path.json
'
;
mock
.
onGet
(
endpoint
,
{
params
:
{
environment_name
:
mockEnvName
,
...
mockDefaultRange
}
})
.
reply
(
200
,
{
mock
.
onGet
(
endpoint
,
{
params
:
{
...
mockDefaultRange
}
}).
reply
(
200
,
{
pod_name
:
mockPodName
,
pods
:
mockPods
,
logs
:
mockLogsResult
,
...
...
ee/spec/serializers/environment_entity_spec.rb
View file @
e78938d5
...
...
@@ -4,6 +4,7 @@ require 'spec_helper'
describe
EnvironmentEntity
do
include
KubernetesHelpers
include
Gitlab
::
Routing
.
url_helpers
let
(
:user
)
{
create
(
:user
)
}
let
(
:environment
)
{
create
(
:environment
)
}
...
...
@@ -51,14 +52,32 @@ describe EnvironmentEntity do
stub_licensed_features
(
pod_logs:
true
)
end
it
'exposes logs
_path
'
do
it
'exposes logs
keys
'
do
expect
(
subject
).
to
include
(
:logs_path
)
expect
(
subject
).
to
include
(
:logs_api_path
)
expect
(
subject
).
to
include
(
:enable_advanced_logs_querying
)
end
it
'uses k8s api when ES is not available'
do
expect
(
subject
[
:logs_api_path
]).
to
eq
(
k8s_project_logs_path
(
environment
.
project
,
environment_name:
environment
.
name
,
format: :json
))
end
it
'uses ES api when ES is available'
do
allow
(
environment
).
to
receive
(
:elastic_stack_available?
).
and_return
(
true
)
expect
(
subject
[
:logs_api_path
]).
to
eq
(
elasticsearch_project_logs_path
(
environment
.
project
,
environment_name:
environment
.
name
,
format: :json
))
end
end
context
'when pod_logs are not available'
do
it
'does not expose logs_path'
do
before
do
stub_licensed_features
(
pod_logs:
false
)
end
it
'does not expose logs keys'
do
expect
(
subject
).
not_to
include
(
:logs_path
)
expect
(
subject
).
not_to
include
(
:logs_api_path
)
expect
(
subject
).
not_to
include
(
:enable_advanced_logs_querying
)
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