Skip to content

Commit

Permalink
Frontend - Add support for Minio artifact URIs (#2645)
Browse files Browse the repository at this point in the history
* Frontend - Add support for Minio artifact URIs

* Fixed style

* Removed unused variable

* Old Node does not support named capture groups in regexes

* Made the URL relative
  • Loading branch information
Ark-kun authored and k8s-ci-robot committed Nov 28, 2019
1 parent 9e7e90b commit 5ca787a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
4 changes: 3 additions & 1 deletion frontend/src/components/ArtifactLink.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { generateGcsConsoleUri } from '../lib/Utils';
import { generateGcsConsoleUri, generateMinioArtifactUrl } from '../lib/Utils';

/**
* A component that renders an artifact URL as clickable link if URL is correct
Expand All @@ -14,6 +14,8 @@ export const ArtifactLink: React.FC<{ artifactUri?: string }> = ({ artifactUri }
}
} else if (artifactUri.startsWith('http:') || artifactUri.startsWith('https:')) {
clickableUrl = artifactUri;
} else if (artifactUri.startsWith('minio:')) {
clickableUrl = generateMinioArtifactUrl(artifactUri);
}
}

Expand Down
23 changes: 20 additions & 3 deletions frontend/src/lib/Utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
* limitations under the License.
*/

import { NodePhase } from './StatusUtils';
import {
logger,
formatDateString,
enabledDisplayString,
formatDateString,
generateMinioArtifactUrl,
getRunDuration,
getRunDurationFromWorkflow,
logger,
} from './Utils';
import { NodePhase } from './StatusUtils';

describe('Utils', () => {
describe('log', () => {
Expand Down Expand Up @@ -236,4 +237,20 @@ describe('Utils', () => {
expect(getRunDurationFromWorkflow(workflow)).toBe('-0:00:02');
});
});

describe('generateMinioArtifactUrl', () => {
it('handles minio:// URIs', () => {
expect(generateMinioArtifactUrl('minio://my-bucket/a/b/c')).toBe(
'artifacts/get?source=minio&bucket=my-bucket&key=a/b/c',
);
});

it('handles non-minio URIs', () => {
expect(generateMinioArtifactUrl('minio://my-bucket-a-b-c')).toBe(undefined);
});

it('handles broken minio URIs', () => {
expect(generateMinioArtifactUrl('ZZZ://my-bucket/a/b/c')).toBe(undefined);
});
});
});
24 changes: 24 additions & 0 deletions frontend/src/lib/Utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -321,3 +321,27 @@ export function generateGcsConsoleUri(gcsUri: string): string | undefined {

return GCS_CONSOLE_BASE + gcsUri.substring(GCS_URI_PREFIX.length);
}

const MINIO_URI_PREFIX = 'minio://';

function generateArtifactUrl(source: string, bucket: string, key: string): string {
return `artifacts/get?source=${source}&bucket=${bucket}&key=${key}`;
}

/**
* Generates an HTTPS API URL from minio:// uri
*
* @param minioUri Minio uri that starts with minio://, like minio://ml-pipeline/path/file
* @returns A URL that leads to the artifact data. Returns undefined when minioUri is not valid.
*/
export function generateMinioArtifactUrl(minioUri: string): string | undefined {
if (!minioUri.startsWith(MINIO_URI_PREFIX)) {
return undefined;
}

const matches = minioUri.match(/^minio:\/\/([^\/]+)\/(.+)$/);
if (matches == null) {
return undefined;
}
return generateArtifactUrl('minio', matches[1], matches[2]);
}

0 comments on commit 5ca787a

Please sign in to comment.