Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Frontend - Add support for Minio artifact URIs #2645

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]);
}