Skip to content

Commit

Permalink
feat(provider/kubernetes): trim runJob logs from executions until exp…
Browse files Browse the repository at this point in the history
…licitly requested (#5014)

A Run Job's log output is excluded from the pipeline
executions list response by default. The query param expand=true is
required to fetch the response including log output.

This PR adds that expand param to the executions service and updates
the k8s v1 runJob to only fetch the full log when a user clicks the
"Console Output" link.  The expand param currently goes unused.
  • Loading branch information
Scott Bloch-Wehba-Seaward authored Mar 16, 2018
1 parent b6a5ba4 commit cab2cec
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ describe('Service: executionService', () => {
SETTINGS.gateUrl,
'applications',
'deck',
'pipelines?limit=3',
'pipelines?limit=3&expand=false',
].join('/');

$httpBackend.expectGET(url).respond(200, []);
Expand All @@ -182,7 +182,7 @@ describe('Service: executionService', () => {
SETTINGS.gateUrl,
'applications',
'deck',
'pipelines?limit=3',
'pipelines?limit=3&expand=false',
].join('/');

$httpBackend.expectGET(url).respond(429, []);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ export class ExecutionService {
return this.getFilteredExecutions(applicationName, this.activeStatuses, this.runningLimit);
}

private getFilteredExecutions(applicationName: string, statuses: string[], limit: number, pipelineConfigIds: string[] = null): IPromise<IExecution[]> {
private getFilteredExecutions(applicationName: string, statuses: string[], limit: number, pipelineConfigIds: string[] = null, expand = false): IPromise<IExecution[]> {
const statusString = statuses.map((status) => status.toUpperCase()).join(',') || null;
const call = pipelineConfigIds ?
this.API.all('executions').getList({ limit, pipelineConfigIds, statuses }) :
this.API.one('applications', applicationName).all('pipelines').getList({ limit, statuses: statusString, pipelineConfigIds });
this.API.one('applications', applicationName).all('pipelines').getList({ limit, statuses: statusString, pipelineConfigIds, expand });

return call.then((data: IExecution[]) => {
if (data) {
Expand All @@ -55,17 +55,17 @@ export class ExecutionService {
* application will be used to correlate and filter the retrieved executions to only include those pipelines
* @return {<IExecution[]>}
*/
public getExecutions(applicationName: string, application: Application = null): IPromise<IExecution[]> {
public getExecutions(applicationName: string, application: Application = null, expand = false): IPromise<IExecution[]> {
const sortFilter: ISortFilter = this.executionFilterModel.asFilterModel.sortFilter;
const pipelines = Object.keys(sortFilter.pipeline);
const statuses = Object.keys(pickBy(sortFilter.status || {}, identity));
const limit = sortFilter.count;
if (application && pipelines.length) {
return this.getConfigIdsFromFilterModel(application).then(pipelineConfigIds => {
return this.getFilteredExecutions(application.name, statuses, limit, pipelineConfigIds);
return this.getFilteredExecutions(application.name, statuses, limit, pipelineConfigIds, expand);
});
}
return this.getFilteredExecutions(applicationName, statuses, limit);
return this.getFilteredExecutions(applicationName, statuses, limit, null, expand);
}

public getExecution(executionId: string): IPromise<IExecution> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { get, has } from 'lodash';

'use strict';

const angular = require('angular');
Expand All @@ -6,9 +8,11 @@ module.exports = angular
.module('spinnaker.kubernetes.pipeline.stage.disableCluster.runJobExecutionDetails.controller', [
require('@uirouter/angularjs').default,
])
.controller('kubernetesRunJobExecutionDetailsCtrl', function ($scope, $stateParams, executionDetailsSectionService, $uibModal) {
.controller('kubernetesRunJobExecutionDetailsCtrl', function ($scope, $stateParams, executionService, executionDetailsSectionService, $uibModal) {

$scope.configSections = ['runJobConfig', 'taskStatus'];
$scope.hasLogs = has($scope.stage, 'context.jobStatus.logs');
$scope.executionId = $stateParams.executionId;

// if the stage is pre-multi-containers
if ($scope.stage.context.container) {
Expand All @@ -28,11 +32,23 @@ module.exports = angular
$scope.displayLogs = () => {
$scope.logs = $scope.stage.context.jobStatus.logs || '';
$scope.jobName = $scope.stage.context.jobStatus.name || '';
return $uibModal.open({
$scope.loading = $scope.logs === '';
$uibModal.open({
templateUrl: require('./runJobLogs.html'),
scope: $scope,
size: 'lg'
});
if ($scope.logs === '') {
const getExecutionPromise = executionService.getExecution($scope.executionId);
getExecutionPromise.finally(() => {
$scope.loading = false;
});
getExecutionPromise.then(execution => {
const fullStage = execution.stages.find(s => s.id === $scope.stage.id);
if (fullStage) {
$scope.logs = get(fullStage, 'context.jobStatus.logs', 'No log output found');
}
});
}
};

});
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
{{[container.imageDescription.repository, execution.trigger.tag].join(':')}}
</dd>
</span>
<dt ng-if="stage.context.jobStatus.logs">Logs</dt>
<dd ng-if="stage.context.jobStatus.logs">
<dt ng-if="hasLogs">Logs</dt>
<dd ng-if="hasLogs">
<dl><a href="" ng-click="displayLogs()">Console Output (Raw)</a></dl>
</dd>
</dl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ <h3>Console Output: {{jobName}}</h3>
</div>
<form role="form">
<div class="modal-body">
<pre>{{logs}}</pre>
<loading-spinner size="'large'" ng-if="loading"></loading-spinner>
<pre ng-if="!loading">{{logs}}</pre>
</div>
<div class="modal-footer">
<button class="btn btn-primary" ng-click="$close()">Close</button>
Expand Down

0 comments on commit cab2cec

Please sign in to comment.