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
193e6602
Commit
193e6602
authored
Apr 09, 2019
by
Sarah Yasonik
Committed by
Douwe Maan
Apr 09, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Resolve Environments#additional_metrics TypeError, ensure unix format
parent
ca03848d
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
51 additions
and
14 deletions
+51
-14
app/assets/javascripts/monitoring/constants.js
app/assets/javascripts/monitoring/constants.js
+0
-2
app/assets/javascripts/monitoring/utils.js
app/assets/javascripts/monitoring/utils.js
+10
-11
app/controllers/projects/environments_controller.rb
app/controllers/projects/environments_controller.rb
+1
-1
spec/controllers/projects/environments_controller_spec.rb
spec/controllers/projects/environments_controller_spec.rb
+11
-0
spec/javascripts/monitoring/utils_spec.js
spec/javascripts/monitoring/utils_spec.js
+29
-0
No files found.
app/assets/javascripts/monitoring/constants.js
View file @
193e6602
...
@@ -18,5 +18,3 @@ export const timeWindows = {
...
@@ -18,5 +18,3 @@ export const timeWindows = {
threeDays
:
__
(
'
3 days
'
),
threeDays
:
__
(
'
3 days
'
),
oneWeek
:
__
(
'
1 week
'
),
oneWeek
:
__
(
'
1 week
'
),
};
};
export
const
msPerMinute
=
60000
;
app/assets/javascripts/monitoring/utils.js
View file @
193e6602
import
{
timeWindows
,
msPerMinute
}
from
'
./constants
'
;
import
{
timeWindows
}
from
'
./constants
'
;
/**
/**
* method that converts a predetermined time window to minutes
* method that converts a predetermined time window to minutes
...
@@ -6,27 +6,26 @@ import { timeWindows, msPerMinute } from './constants';
...
@@ -6,27 +6,26 @@ import { timeWindows, msPerMinute } from './constants';
* @param {String} timeWindow - The time window to convert to minutes
* @param {String} timeWindow - The time window to convert to minutes
* @returns {number} The time window in minutes
* @returns {number} The time window in minutes
*/
*/
const
getTimeDifference
Minute
s
=
timeWindow
=>
{
const
getTimeDifference
Second
s
=
timeWindow
=>
{
switch
(
timeWindow
)
{
switch
(
timeWindow
)
{
case
timeWindows
.
thirtyMinutes
:
case
timeWindows
.
thirtyMinutes
:
return
30
;
return
60
*
30
;
case
timeWindows
.
threeHours
:
case
timeWindows
.
threeHours
:
return
60
*
3
;
return
60
*
60
*
3
;
case
timeWindows
.
oneDay
:
case
timeWindows
.
oneDay
:
return
60
*
24
*
1
;
return
60
*
60
*
24
*
1
;
case
timeWindows
.
threeDays
:
case
timeWindows
.
threeDays
:
return
60
*
24
*
3
;
return
60
*
60
*
24
*
3
;
case
timeWindows
.
oneWeek
:
case
timeWindows
.
oneWeek
:
return
60
*
24
*
7
*
1
;
return
60
*
60
*
24
*
7
*
1
;
default
:
default
:
return
60
*
8
;
return
60
*
60
*
8
;
}
}
};
};
export
const
getTimeDiff
=
selectedTimeWindow
=>
{
export
const
getTimeDiff
=
selectedTimeWindow
=>
{
const
end
=
Date
.
now
();
const
end
=
Date
.
now
()
/
1000
;
// convert milliseconds to seconds
const
timeDifferenceMinutes
=
getTimeDifferenceMinutes
(
selectedTimeWindow
);
const
start
=
end
-
getTimeDifferenceSeconds
(
selectedTimeWindow
);
const
start
=
new
Date
(
end
-
timeDifferenceMinutes
*
msPerMinute
).
getTime
();
return
{
start
,
end
};
return
{
start
,
end
};
};
};
...
...
app/controllers/projects/environments_controller.rb
View file @
193e6602
...
@@ -193,7 +193,7 @@ class Projects::EnvironmentsController < Projects::ApplicationController
...
@@ -193,7 +193,7 @@ class Projects::EnvironmentsController < Projects::ApplicationController
return
unless
Feature
.
enabled?
(
:metrics_time_window
,
project
)
return
unless
Feature
.
enabled?
(
:metrics_time_window
,
project
)
return
unless
params
[
:start
].
present?
||
params
[
:end
].
present?
return
unless
params
[
:start
].
present?
||
params
[
:end
].
present?
params
.
require
([
:start
,
:end
])
.
values_at
(
:start
,
:end
)
params
.
require
([
:start
,
:end
])
end
end
def
search_environment_names
def
search_environment_names
...
...
spec/controllers/projects/environments_controller_spec.rb
View file @
193e6602
...
@@ -419,6 +419,17 @@ describe Projects::EnvironmentsController do
...
@@ -419,6 +419,17 @@ describe Projects::EnvironmentsController do
expect
(
json_response
[
'data'
]).
to
eq
({})
expect
(
json_response
[
'data'
]).
to
eq
({})
expect
(
json_response
[
'last_update'
]).
to
eq
(
42
)
expect
(
json_response
[
'last_update'
]).
to
eq
(
42
)
end
end
context
'when time params are provided'
do
it
'returns a metrics JSON document'
do
additional_metrics
(
start:
'1554702993.5398998'
,
end:
'1554717396.996232'
)
expect
(
response
).
to
be_ok
expect
(
json_response
[
'success'
]).
to
be
(
true
)
expect
(
json_response
[
'data'
]).
to
eq
({})
expect
(
json_response
[
'last_update'
]).
to
eq
(
42
)
end
end
end
end
context
'when only one time param is provided'
do
context
'when only one time param is provided'
do
...
...
spec/javascripts/monitoring/utils_spec.js
0 → 100644
View file @
193e6602
import
{
getTimeDiff
}
from
'
~/monitoring/utils
'
;
import
{
timeWindows
}
from
'
~/monitoring/constants
'
;
describe
(
'
getTimeDiff
'
,
()
=>
{
it
(
'
defaults to an 8 hour (28800s) difference
'
,
()
=>
{
const
params
=
getTimeDiff
();
expect
(
params
.
end
-
params
.
start
).
toEqual
(
28800
);
});
it
(
'
accepts time window as an argument
'
,
()
=>
{
const
params
=
getTimeDiff
(
timeWindows
.
thirtyMinutes
);
expect
(
params
.
end
-
params
.
start
).
not
.
toEqual
(
28800
);
});
it
(
'
returns a value for every defined time window
'
,
()
=>
{
const
nonDefaultWindows
=
Object
.
keys
(
timeWindows
).
filter
(
window
=>
window
!==
'
eightHours
'
);
nonDefaultWindows
.
forEach
(
window
=>
{
const
params
=
getTimeDiff
(
timeWindows
[
window
]);
const
diff
=
params
.
end
-
params
.
start
;
// Ensure we're not returning the default, 28800 (the # of seconds in 8 hrs)
expect
(
diff
).
not
.
toEqual
(
28800
);
expect
(
typeof
diff
).
toEqual
(
'
number
'
);
});
});
});
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