Skip to content

Commit

Permalink
Reduce API usage by utilizing reference name in reference resource API (
Browse files Browse the repository at this point in the history
#1824)

* Regenerated run api for frontend

* Added support for reference name to resource reference API in frontend

* Revert "Regenerated run api for frontend"

* Addressed PR comments

* Removed extra if statement by setting default value of parameter

* Removed the whole comment

* Addressed PR feedback

* Addressed PR feedback

* Simplified logic after offline discussion
  • Loading branch information
ajchili authored and rileyjbauer committed Aug 16, 2019
1 parent ea67c99 commit afe8a69
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
22 changes: 15 additions & 7 deletions frontend/src/lib/RunUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ export interface MetricMetadata {
name: string;
}

export interface ExperimentInfo {
displayName?: string;
id: string;
}

function getParametersFromRun(run: ApiRunDetail): ApiParameter[] {
return getParametersFromRuntime(run.pipeline_runtime);
}
Expand Down Expand Up @@ -59,16 +64,18 @@ function getWorkflowManifest(run?: ApiRun | ApiJob): string | null {
return (run && run.pipeline_spec && run.pipeline_spec.workflow_manifest) || null;
}

function getFirstExperimentReference(run?: ApiRun | ApiJob): ApiResourceReference | null {
return getAllExperimentReferences(run)[0] || null;
}

function getFirstExperimentReferenceId(run?: ApiRun | ApiJob): string | null {
if (run) {
const reference = getAllExperimentReferences(run)[0];
return reference && reference.key && reference.key.id || null;
}
return null;
const reference = getFirstExperimentReference(run);
return reference && reference.key && reference.key.id || null;
}

function getFirstExperimentReference(run?: ApiRun | ApiJob): ApiResourceReference | null {
return run && getAllExperimentReferences(run)[0] || null;
function getFirstExperimentReferenceName(run?: ApiRun | ApiJob): string | null {
const reference = getFirstExperimentReference(run);
return reference && reference.name || null;
}

function getAllExperimentReferences(run?: ApiRun | ApiJob): ApiResourceReference[] {
Expand Down Expand Up @@ -133,6 +140,7 @@ export default {
getAllExperimentReferences,
getFirstExperimentReference,
getFirstExperimentReferenceId,
getFirstExperimentReferenceName,
getParametersFromRun,
getParametersFromRuntime,
getPipelineId,
Expand Down
26 changes: 14 additions & 12 deletions frontend/src/pages/RunList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import * as React from 'react';
import CustomTable, { Column, Row, CustomRendererProps } from '../components/CustomTable';
import Metric from '../components/Metric';
import RunUtils, { MetricMetadata } from '../../src/lib/RunUtils';
import RunUtils, { MetricMetadata, ExperimentInfo } from '../../src/lib/RunUtils';
import { ApiRun, ApiResourceType, ApiRunMetric, RunStorageState, ApiRunDetail } from '../../src/apis/run';
import { Apis, RunSortKeys, ListRequest } from '../lib/Apis';
import { Link, RouteComponentProps } from 'react-router-dom';
Expand All @@ -29,11 +29,6 @@ import { commonCss, color } from '../Css';
import { formatDateString, logger, errorToMessage, getRunDuration } from '../lib/Utils';
import { statusToIcon } from './Status';

interface ExperimentInfo {
displayName?: string;
id: string;
}

interface PipelineInfo {
displayName?: string;
id?: string;
Expand Down Expand Up @@ -386,13 +381,20 @@ class RunList extends React.PureComponent<RunListProps, RunListState> {
private async _getAndSetExperimentNames(displayRun: DisplayRun): Promise<void> {
const experimentId = RunUtils.getFirstExperimentReferenceId(displayRun.run);
if (experimentId) {
try {
const experiment = await Apis.experimentServiceApi.getExperiment(experimentId);
displayRun.experiment = { displayName: experiment.name || '', id: experimentId };
} catch (err) {
// This could be an API exception, or a JSON parse exception.
displayRun.error = 'Failed to get associated experiment: ' + await errorToMessage(err);
let experimentName = RunUtils.getFirstExperimentReferenceName(displayRun.run);
if (!experimentName) {
try {
const experiment = await Apis.experimentServiceApi.getExperiment(experimentId);
experimentName = experiment.name || '';
} catch (err) {
displayRun.error = 'Failed to get associated experiment: ' + await errorToMessage(err);
return;
}
}
displayRun.experiment = {
displayName: experimentName,
id: experimentId
};
}
}
}
Expand Down

0 comments on commit afe8a69

Please sign in to comment.