Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-09-20 02:18:09 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-09-20 02:18:09 +0300
commit6ed4ec3e0b1340f96b7c043ef51d1b33bbe85fde (patch)
treedc4d20fe6064752c0bd323187252c77e0a89144b /app/assets/javascripts/clusters_list
parent9868dae7fc0655bd7ce4a6887d4e6d487690eeed (diff)
Add latest changes from gitlab-org/gitlab@15-4-stable-eev15.4.0-rc42
Diffstat (limited to 'app/assets/javascripts/clusters_list')
-rw-r--r--app/assets/javascripts/clusters_list/clusters_util.js23
-rw-r--r--app/assets/javascripts/clusters_list/components/agents.vue34
2 files changed, 27 insertions, 30 deletions
diff --git a/app/assets/javascripts/clusters_list/clusters_util.js b/app/assets/javascripts/clusters_list/clusters_util.js
index e2d01723dde..ee36a295513 100644
--- a/app/assets/javascripts/clusters_list/clusters_util.js
+++ b/app/assets/javascripts/clusters_list/clusters_util.js
@@ -1,3 +1,5 @@
+import { ACTIVE_CONNECTION_TIME } from './constants';
+
export function generateAgentRegistrationCommand({ name, token, version, address }) {
return `helm repo add gitlab https://charts.gitlab.io
helm repo update
@@ -12,3 +14,24 @@ helm upgrade --install ${name} gitlab/gitlab-agent \\
export function getAgentConfigPath(clusterAgentName) {
return `.gitlab/agents/${clusterAgentName}`;
}
+
+export function getAgentLastContact(tokens = []) {
+ let lastContact = null;
+ tokens.forEach((token) => {
+ const lastContactToDate = new Date(token.lastUsedAt).getTime();
+ if (lastContactToDate > lastContact) {
+ lastContact = lastContactToDate;
+ }
+ });
+ return lastContact;
+}
+
+export function getAgentStatus(lastContact) {
+ if (lastContact) {
+ const now = new Date().getTime();
+ const diff = now - lastContact;
+
+ return diff >= ACTIVE_CONNECTION_TIME ? 'inactive' : 'active';
+ }
+ return 'unused';
+}
diff --git a/app/assets/javascripts/clusters_list/components/agents.vue b/app/assets/javascripts/clusters_list/components/agents.vue
index 8a4a81d3e96..36f0f8e61ba 100644
--- a/app/assets/javascripts/clusters_list/components/agents.vue
+++ b/app/assets/javascripts/clusters_list/components/agents.vue
@@ -3,13 +3,9 @@ import { GlAlert, GlKeysetPagination, GlLoadingIcon, GlBanner } from '@gitlab/ui
import { s__ } from '~/locale';
import glFeatureFlagMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import LocalStorageSync from '~/vue_shared/components/local_storage_sync.vue';
-import {
- MAX_LIST_COUNT,
- ACTIVE_CONNECTION_TIME,
- AGENT_FEEDBACK_ISSUE,
- AGENT_FEEDBACK_KEY,
-} from '../constants';
+import { MAX_LIST_COUNT, AGENT_FEEDBACK_ISSUE, AGENT_FEEDBACK_KEY } from '../constants';
import getAgentsQuery from '../graphql/queries/get_agents.query.graphql';
+import { getAgentLastContact, getAgentStatus } from '../clusters_util';
import AgentEmptyState from './agent_empty_state.vue';
import AgentTable from './agent_table.vue';
@@ -88,8 +84,8 @@ export default {
if (list) {
list = list.map((agent) => {
const configFolder = this.folderList[agent.name];
- const lastContact = this.getLastContact(agent);
- const status = this.getStatus(lastContact);
+ const lastContact = getAgentLastContact(agent?.tokens?.nodes);
+ const status = getAgentStatus(lastContact);
return { ...agent, configFolder, lastContact, status };
});
}
@@ -141,28 +137,6 @@ export default {
});
}
},
- getLastContact(agent) {
- const tokens = agent?.tokens?.nodes;
- let lastContact = null;
- if (tokens?.length) {
- tokens.forEach((token) => {
- const lastContactToDate = new Date(token.lastUsedAt).getTime();
- if (lastContactToDate > lastContact) {
- lastContact = lastContactToDate;
- }
- });
- }
- return lastContact;
- },
- getStatus(lastContact) {
- if (lastContact) {
- const now = new Date().getTime();
- const diff = now - lastContact;
-
- return diff > ACTIVE_CONNECTION_TIME ? 'inactive' : 'active';
- }
- return 'unused';
- },
emitAgentsLoaded() {
const count = this.agents?.project?.clusterAgents?.count;
this.$emit('onAgentsLoad', count);