mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Introduce and use get(Milli)SecondsFromUnixEpochInjectable
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
ce614461ce
commit
5798f6722e
5 files changed
+40
-7
No files matched your search
@@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import moment from "moment";
|
||||
import getSecondsFromUnixEpochInjectable from "../../../utils/date/get-seconds-from-unix-epoch.injectable";
|
||||
import { apiBaseInjectionToken } from "../../api-base";
|
||||
import type { MetricData } from "../metrics.api";
|
||||
|
||||
@@ -47,14 +47,14 @@ const requestMetricsInjectable = getInjectable({
|
||||
id: "request-metrics",
|
||||
instantiate: (di) => {
|
||||
const apiBase = di.inject(apiBaseInjectionToken);
|
||||
const getSecondsFromUnixEpoch = di.inject(getSecondsFromUnixEpochInjectable);
|
||||
|
||||
return (async (query: object, params: RequestMetricsParams = {}) => {
|
||||
const { range = 3600, step = 60, namespace } = params;
|
||||
let { start, end } = params;
|
||||
|
||||
if (!start && !end) {
|
||||
const timeNow = Date.now() / 1000;
|
||||
const now = moment.unix(timeNow).startOf("minute").unix(); // round date to minutes
|
||||
const now = getSecondsFromUnixEpoch();
|
||||
|
||||
start = now - range;
|
||||
end = now;
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
|
||||
const getMillisecondsFromUnixEpochInjectable = getInjectable({
|
||||
id: "get-current-time",
|
||||
instantiate: () => () => Date.now(),
|
||||
causesSideEffects: true,
|
||||
});
|
||||
|
||||
export default getMillisecondsFromUnixEpochInjectable;
|
||||
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import getMillisecondsFromUnixEpochInjectable from "./get-milliseconds-from-unix-epoch.injectable";
|
||||
|
||||
const getSecondsFromUnixEpochInjectable = getInjectable({
|
||||
id: "get-seconds-from-unix-epoch",
|
||||
instantiate: (di) => {
|
||||
const getMilisecondsFromUnixEpoch = di.inject(getMillisecondsFromUnixEpochInjectable);
|
||||
|
||||
return () => Math.floor(getMilisecondsFromUnixEpoch() / 1000);
|
||||
},
|
||||
});
|
||||
|
||||
export default getSecondsFromUnixEpochInjectable;
|
||||
Reference in new issue
Block a user