Skip to content

Commit

Permalink
Reconfigured to use latestDeploymentSummary in job-row computed prope…
Browse files Browse the repository at this point in the history
…rties
  • Loading branch information
philrenaud committed May 1, 2024
1 parent 6dd557d commit bfd8849
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 62 deletions.
94 changes: 41 additions & 53 deletions ui/app/components/job-row.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,29 @@ import { action } from '@ember/object';
import { inject as service } from '@ember/service';
import { tracked } from '@glimmer/tracking';

Check failure on line 11 in ui/app/components/job-row.js

View workflow job for this annotation

GitHub Actions / pre-test

'tracked' is defined but never used
import { task } from 'ember-concurrency';
import { computed } from '@ember/object';

Check failure on line 13 in ui/app/components/job-row.js

View workflow job for this annotation

GitHub Actions / pre-test

'computed' is defined but never used

export default class JobRow extends Component {
@service router;
@service store;
@service system;

@tracked activeDeployment = null;
// @tracked fullActiveDeploymentObject = {};

// /**
// * If our job has an activeDeploymentID, as determined by the statuses endpoint,
// * we check if this component's activeDeployment has the same ID.
// * If it does, we don't need to do any fetching: we can simply check this.activeDeployment.requiresPromotion
// * we check if this component's fullActiveDeploymentObject has the same ID.
// * If it does, we don't need to do any fetching: we can simply check this.fullActiveDeploymentObject.requiresPromotion
// * If it doesn't, we need to fetch the deployment with the activeDeploymentID
// * and set it to this.activeDeployment, then check this.activeDeployment.requiresPromotion.
// * and set it to this.fullActiveDeploymentObject, then check this.fullActiveDeploymentObject.requiresPromotion.
// */
// get requiresPromotion() {
// if (!this.args.job.hasActiveCanaries || !this.args.job.activeDeploymentID) {
// return false;
// }

// if (this.activeDeployment && this.activeDeployment.id === this.args.job.activeDeploymentID) {
// return this.activeDeployment.requiresPromotion;
// if (this.fullActiveDeploymentObject && this.fullActiveDeploymentObject.id === this.args.job.activeDeploymentID) {
// return this.fullActiveDeploymentObject.requiresPromotion;
// }

// this.fetchActiveDeployment();
Expand All @@ -42,7 +43,7 @@ export default class JobRow extends Component {
// async fetchActiveDeployment() {
// if (this.args.job.hasActiveCanaries && this.args.job.activeDeploymentID) {
// let deployment = await this.store.findRecord('deployment', this.args.job.activeDeploymentID);
// this.activeDeployment = deployment;
// this.fullActiveDeploymentObject = deployment;
// }
// }

Expand Down Expand Up @@ -79,37 +80,54 @@ export default class JobRow extends Component {
}

@task(function* () {

Check failure on line 82 in ui/app/components/job-row.js

View workflow job for this annotation

GitHub Actions / pre-test

This generator function does not have 'yield'
// ID: jobDeployments[0]?.id,
// IsActive: jobDeployments[0]?.status === 'running',
// // IsActive: true,
// JobVersion: jobDeployments[0]?.versionNumber,
// Status: jobDeployments[0]?.status,
// StatusDescription: jobDeployments[0]?.statusDescription,
// AllAutoPromote: false,
// RequiresPromotion: true, // TODO: lever

/**
* @typedef DeploymentSummary
* @property {string} id
* @property {boolean} isActive
* @property {string} jobVersion
* @property {string} status
* @property {string} statusDescription
* @property {boolean} allAutoPromote
* @property {boolean} requiresPromotion
*/
/**
* @type {DeploymentSummary}
*/
let latestDeploymentSummary = this.args.job.latestDeploymentSummary;

console.log(
'checking if requries promotion',
this.args.job.name,
this.args.job.latestDeploymentSummary,
latestDeploymentSummary,
this.args.job.hasActiveCanaries
);
if (
!this.args.job.hasActiveCanaries ||
!this.args.job.latestDeploymentSummary?.IsActive
) {
// Early return false if we don't have an active deployment
if (latestDeploymentSummary.isActive) {
return false;
}

if (
!this.latestDeploymentSummary?.IsActive ||
this.activeDeployment.id !== this.args.job?.latestDeploymentSummary.ID
) {
this.activeDeployment = yield this.store.findRecord(
'deployment',
this.args.job.latestDeploymentSummary.ID
);
// Early return if we our deployment doesn't have any canaries
if (!this.args.job.hasActiveCanaries) {
return false;
}

if (this.activeDeployment.requiresPromotion) {
if (latestDeploymentSummary.requiresPromotion) {
if (this.canariesHealthy) {
return 'canary-promote';
}
if (this.someCanariesHaveFailed) {
return 'canary-failure';
}
if (this.activeDeployment.isAutoPromoted) {
if (latestDeploymentSummary.allAutoPromote) {
// return "This deployment is set to auto-promote; canaries are being checked now";
return false;
} else {
Expand All @@ -135,38 +153,8 @@ export default class JobRow extends Component {
})
promote;

/**
* If there is not a deployment happening,
* and the running allocations have a jobVersion that differs from the job's version,
* we can assume a failed latest deployment.
*/
get latestDeploymentFailed() {
/**
* Import from app/models/job.js
* @type {import('../models/job').default}
*/
const job = this.args.job;
if (job.latestDeploymentSummary?.IsActive) {
return false;
}

// We only want to show this status if the job is running, to indicate to
// the user that the job is not running the version they expect given their
// latest deployment.
if (
!(
job.aggregateAllocStatus.label === 'Healthy' ||
job.aggregateAllocStatus.label === 'Degraded' ||
job.aggregateAllocStatus.label === 'Recovering'
)
) {
return false;
}
const runningAllocs = job.allocations.filter(
(a) => a.clientStatus === 'running'
);
const jobVersion = job.version;
return runningAllocs.some((a) => a.jobVersion !== jobVersion);
return this.args.job.latestDeploymentSummary.status === 'failed';
}

@action
Expand Down
8 changes: 4 additions & 4 deletions ui/app/models/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ export default class Job extends Model {
}
}

@attr() latestDeploymentSummary; // TODO: model this out
@attr({ defaultValue: () => ({}) }) latestDeploymentSummary; // TODO: model this out

get hasActiveCanaries() {
// console.log('tell me about ur active canaries plz', this.allocBlocks, this.allocations, this.activeDeploymentID);
// TODO: Monday/Tuesday: go over AllocBlocks.{all}.canary and if there are any? make the latestDeployment lookup,
// and check to see if it requires promotion / isnt yet promoted.
if (!this.latestDeploymentSummary?.IsActive) {
if (!this.latestDeploymentSummary.isActive) {
return false;
}
return Object.keys(this.allocBlocks)
Expand Down Expand Up @@ -142,7 +142,7 @@ export default class Job extends Model {
get allocBlocks() {
let availableSlotsToFill = this.expectedRunningAllocCount;

let isDeploying = this.latestDeploymentSummary?.IsActive;
let isDeploying = this.latestDeploymentSummary.isActive;
// Initialize allocationsOfShowableType with empty arrays for each clientStatus
/**
* @type {AllocationBlock}
Expand Down Expand Up @@ -328,7 +328,7 @@ export default class Job extends Model {
let totalAllocs = this.expectedRunningAllocCount;

// If deploying:
if (this.latestDeploymentSummary?.IsActive) {
if (this.latestDeploymentSummary.isActive) {
return { label: 'Deploying', state: 'highlight' };
}

Expand Down
16 changes: 15 additions & 1 deletion ui/app/serializers/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { assign } from '@ember/polyfills';
import ApplicationSerializer from './application';
import queryString from 'query-string';
import classic from 'ember-classic-decorator';
import { camelize } from '@ember/string';

@classic
export default class JobSerializer extends ApplicationSerializer {
Expand Down Expand Up @@ -120,8 +121,21 @@ export default class JobSerializer extends ApplicationSerializer {
};
}
if (job.LatestDeployment) {
job.LatestDeploymentSummary = job.LatestDeployment;
// camelize property names and save it as a non-conflicting name (latestDeployment is already used as a computed property on the job model)
job.LatestDeploymentSummary = Object.keys(job.LatestDeployment).reduce(
(acc, key) => {
if (key === 'ID') {
acc.id = job.LatestDeployment[key];
} else {
acc[camelize(key)] = job.LatestDeployment[key];
}
return acc;
},
{}
);
delete job.LatestDeployment;
} else {
job.LatestDeploymentSummary = {};
}
job._aggregate = true;
});
Expand Down
7 changes: 3 additions & 4 deletions ui/app/templates/components/job-row.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
}}
{{on "click" (action this.gotoJob @job)}}
{{did-insert this.requiresPromotionTask.perform}}
{{did-update this.requiresPromotionTask.perform @job.activeDeploymentID @job.hasActiveCanaries}}
class="job-row is-interactive {{if @job.assumeGC "assume-gc"}}"
{{did-update this.requiresPromotionTask.perform @job.latestDeploymentSummary.id @job.hasActiveCanaries}}
class="job-row {{if @job.assumeGC "assume-gc"}}"
data-test-job-row={{@job.plainId}}
data-test-modify-index={{@job.modifyIndex}}
>
Expand Down Expand Up @@ -82,7 +82,6 @@
@allocBlocks={{@job.allocBlocks}}
@steady={{true}}
@compact={{true}}
{{!-- @runningAllocs={{@job.runningAllocs}} --}}
@runningAllocs={{@job.allocBlocks.running.healthy.nonCanary.length}}
@groupCountSum={{@job.expectedRunningAllocCount}}
/>
Expand All @@ -104,7 +103,7 @@
{{hds-tooltip "Some canaries have failed; you will have to investigate"
options=(hash placement="right")}}
@name="alert-triangle" @color="#c84034" />
{{/if}}
{{/if}}
{{/if}}
</div>
{{/if}}
Expand Down

0 comments on commit bfd8849

Please sign in to comment.