Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,12 @@ export const registerFileUploadAnalyticsEvents = (analytics: AnalyticsServiceSet
description: 'The time taken to upload the file in milliseconds.',
},
},
file_extension: {
type: 'keyword',
_meta: {
description: 'The file extension of the uploaded file.',
},
},
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ interface FileUploadEvent {
upload_success: boolean;
upload_cancelled: boolean;
upload_time_ms: number;
file_extension: string;
location?: string;
}

Expand All @@ -59,6 +60,14 @@ interface UploadSessionEvent {
export class FileUploadTelemetryService {
constructor(private analytics: AnalyticsServiceStart, private location: string) {}

public static generateId(): string {
return crypto.randomUUID().substring(0, 13);
}

public static getFileExtension(fileName: string): string {
return fileName.split('.').pop() ?? 'unknown';
}

private reportEvent(eventType: string, eventData: Record<string, unknown>) {
try {
this.analytics.reportEvent(eventType, eventData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export class FileUploadManager {
this.http = dependencies.http;
this.notifications = dependencies.notifications;

this.uploadSessionId = Math.random().toString(36).substring(2, 15);
this.uploadSessionId = FileUploadTelemetryService.generateId();
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
this.setExistingIndexName(existingIndexName);
this.initializedWithExistingIndex = existingIndexName !== null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ jest.mock('./file_size_check');
jest.mock('../src/utils');
jest.mock('./doc_count_service');

Object.defineProperty(global.crypto, 'randomUUID', {
value: jest.fn(() => 'test-uuid-1234567890'),
});

describe('FileWrapper', () => {
let fileWrapper: FileWrapper;
let mockFile: File;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import { BehaviorSubject } from 'rxjs';
import type { FileUploadPluginStartApi } from '@kbn/file-upload-plugin/public/api';
import {
FileUploadTelemetryService,
isAbortError,
type FileUploadTelemetryService,
type FindFileStructureResponse,
type FormattedOverrides,
type ImportFailure,
Expand Down Expand Up @@ -112,7 +112,7 @@ export class FileWrapper {
private fileUploadTelemetryService: FileUploadTelemetryService,
private uploadSessionId: string
) {
this.fileId = Math.random().toString(36).substring(2, 15);
this.fileId = FileUploadTelemetryService.generateId();
this.fileSizeChecker = new FileSizeChecker(fileUpload, file);
this.analyzedFile$.next({
...this.analyzedFile$.getValue(),
Expand Down Expand Up @@ -587,7 +587,7 @@ export class FileWrapper {
upload_session_id: this.uploadSessionId,
file_id: this.fileId,
file_type: analysisResults.results.format,
file_extension: this.file.name.split('.').pop() ?? 'unknown',
file_extension: FileUploadTelemetryService.getFileExtension(this.file.name),
file_size_bytes: this.file.size ?? 0,
num_lines_analyzed: analysisResults.results.num_lines_analyzed,
num_messages_analyzed: analysisResults.results.num_messages_analyzed,
Expand All @@ -605,7 +605,7 @@ export class FileWrapper {
upload_session_id: this.uploadSessionId,
file_id: this.fileId,
file_type: 'unknown',
file_extension: this.file.name.split('.').pop() ?? 'unknown',
file_extension: FileUploadTelemetryService.getFileExtension(this.file.name),
file_size_bytes: this.file.size ?? 0,
num_lines_analyzed: 0,
num_messages_analyzed: 0,
Expand Down Expand Up @@ -638,6 +638,7 @@ export class FileWrapper {
upload_success: resp?.success === true,
upload_cancelled: importStatus === STATUS.ABORTED,
upload_time_ms: uploadTimeMs,
file_extension: FileUploadTelemetryService.getFileExtension(this.file.name),
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

import React from 'react';
import { EuiSkeletonText } from '@elastic/eui';
import type { FileUploadComponentProps } from '../lazy_load_bundle';
import type { GeoUploadWizardProps } from '../lazy_load_bundle';
import { lazyLoadModules } from '../lazy_load_bundle';

interface State {
GeoUploadWizard: React.ComponentType<FileUploadComponentProps> | null;
GeoUploadWizard: React.ComponentType<GeoUploadWizardProps> | null;
}

export class GeoUploadWizardAsyncWrapper extends React.Component<FileUploadComponentProps, State> {
export class GeoUploadWizardAsyncWrapper extends React.Component<GeoUploadWizardProps, State> {
state: State = {
GeoUploadWizard: null,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,21 @@ import React, { Component } from 'react';
import { EuiFilePicker, EuiFormRow } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { MB } from '@kbn/file-upload-common/src/constants';
import { FileUploadTelemetryService } from '@kbn/file-upload-common';
import { GEO_FILE_TYPES, geoImporterFactory } from '../../importer/geo';
import type { GeoFileImporter, GeoFilePreview } from '../../importer/geo';
import { hasSidecarFiles } from '../utils';

export type OnFileSelectParameters = GeoFilePreview & {
indexName: string;
importer: GeoFileImporter;
getFilesTelemetry: () => {
total_files: number;
total_size_bytes: number;
main_file_size: number;
main_file_extension: string;
sidecar_files: Array<{ size: number; extension: string }>;
};
};

interface Props {
Expand All @@ -28,6 +37,7 @@ interface State {
isLoadingPreview: boolean;
importer: GeoFileImporter | null;
previewSummary: string | null;
file: File | null;
}

export class GeoFilePicker extends Component<Props, State> {
Expand All @@ -39,6 +49,7 @@ export class GeoFilePicker extends Component<Props, State> {
isLoadingPreview: false,
importer: null,
previewSummary: null,
file: null,
};

async componentDidMount() {
Expand All @@ -58,6 +69,7 @@ export class GeoFilePicker extends Component<Props, State> {
isLoadingPreview: false,
importer: null,
previewSummary: null,
file: null,
});

if (files && files.length) {
Expand All @@ -68,6 +80,7 @@ export class GeoFilePicker extends Component<Props, State> {
{
defaultIndexName: file.name.split('.')[0].toLowerCase(),
importer,
file,
},
this._loadFilePreview
);
Expand Down Expand Up @@ -116,11 +129,35 @@ export class GeoFilePicker extends Component<Props, State> {
: null,
});

if (preview) {
if (preview && this.state.importer && this.state.file) {
this.props.onSelect({
...preview,
importer: this.state.importer,
indexName: this.state.defaultIndexName ? this.state.defaultIndexName : 'features',
getFilesTelemetry: () => {
const mainFile = this.state.file!;
const mainFileExtension = FileUploadTelemetryService.getFileExtension(mainFile.name);

// Get sidecar files if available
const sidecarFiles = hasSidecarFiles(this.state.importer)
? this.state.importer.getSidecarFiles?.() ?? []
: [];

const totalFiles = 1 + sidecarFiles.length;
const totalSize =
mainFile.size + sidecarFiles.reduce((total, file) => total + file.size, 0);

return {
total_files: totalFiles,
total_size_bytes: totalSize,
main_file_size: mainFile.size,
main_file_extension: mainFileExtension,
sidecar_files: sidecarFiles.map((file) => ({
size: file.size,
extension: FileUploadTelemetryService.getFileExtension(file.name),
})),
};
},
});
}
};
Expand Down
Loading
Loading