Skip to content

Commit

Permalink
Fix slowlogs format option
Browse files Browse the repository at this point in the history
  • Loading branch information
maxschmeling committed Apr 19, 2024
1 parent 737d4ad commit c3113a9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
10 changes: 5 additions & 5 deletions src/bin/vip-slowlogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import {
} from '../lib/app-slowlogs/types';
import command from '../lib/cli/command';
import * as exit from '../lib/cli/exit';
import { formatData } from '../lib/cli/format';
import { OutputFormat, formatData } from '../lib/cli/format';
import { trackEvent } from '../lib/tracker';

const LIMIT_MIN = 1;
const LIMIT_MAX = 500;
const ALLOWED_FORMATS = [ 'csv', 'json', 'text' ];
const ALLOWED_FORMATS: OutputFormat[] = [ 'csv', 'json', 'table' ];
const DEFAULT_POLLING_DELAY_IN_SECONDS = 30;
const MIN_POLLING_DELAY_IN_SECONDS = 5;
const MAX_POLLING_DELAY_IN_SECONDS = 300;
Expand Down Expand Up @@ -150,7 +150,7 @@ function printSlowlogs( slowlogs: Slowlog[], format: SlowlogFormats ): void {
return { timestamp, rowsSent, rowsExamined, queryTime, requestUri, query };
} );

console.log( formatData( slowlogs, format ) );
console.log( formatData( slowlogs, format as OutputFormat ) );
}

export function validateInputs( limit: number, format: SlowlogFormats ): void {
Expand Down Expand Up @@ -186,11 +186,11 @@ void command( {
appContext: true,
appQuery,
envContext: true,
format: true,
format: false,
module: 'slowlogs',
} )
.option( 'limit', 'The maximum number of log lines', 500 )
.option( 'format', 'Output the log lines in CSV or JSON format', 'text' )
.option( 'format', 'Output the log lines in CSV or JSON format', 'table' )
.examples( [
{
description: 'Get the most recent app slowlogs',
Expand Down
6 changes: 2 additions & 4 deletions src/lib/app-slowlogs/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ export interface DefaultOptions {
};
}

export type SlowlogFormats = 'ids' | 'json' | 'csv';
export type SlowlogFormats = 'json' | 'csv' | 'table';

Check failure on line 14 in src/lib/app-slowlogs/types.ts

View workflow job for this annotation

GitHub Actions / Lint

Delete `·`

type Stringable =

Check failure on line 16 in src/lib/app-slowlogs/types.ts

View workflow job for this annotation

GitHub Actions / Lint

Replace `⏎↹|·string⏎↹|·{·toString:·()·=>·string;` with `·string·|·{·toString:·()·=>·string`
| string
| {
toString: () => string;
};
| { toString: () => string; };

export interface GetSlowLogsOptions extends DefaultOptions {
limit: number;
Expand Down
9 changes: 7 additions & 2 deletions src/lib/cli/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,20 @@ type Stringable =
toString: () => string;
};

export type OutputFormat = 'keyValue' | 'ids' | 'json' | 'csv' | 'table';

export function formatData( data: Tuple[], format: 'keyValue' ): string;
export function formatData( data: Record< string, Stringable >[], format: 'table' ): string;
export function formatData(
data: Record< string, unknown >[],
format: 'ids' | 'json' | 'csv'
): string;
export function formatData(

Check failure on line 25 in src/lib/cli/format.ts

View workflow job for this annotation

GitHub Actions / Lint

Replace `⏎↹data:·Record<·string,·Stringable·>[],⏎↹format:·OutputFormat⏎` with `·data:·Record<·string,·Stringable·>[],·format:·OutputFormat·`
data: Record< string, Stringable >[],
format: OutputFormat
): string;
export function formatData(
data: Record< string, unknown >[] | Tuple[],
format: 'keyValue' | 'ids' | 'json' | 'csv' | 'table'
format: OutputFormat
): string {
if ( ! data.length ) {
return '';
Expand Down

0 comments on commit c3113a9

Please sign in to comment.