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

Revert "Logv2" #532

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion .github/workflows/pull_requests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 15
container:
image: mcr.microsoft.com/playwright:v1.40.0-jammy
image: mcr.microsoft.com/playwright:v1.39.0-jammy
env:
MPKIT_EMAIL: ${{ secrets.MPKIT_EMAIL }}
MPKIT_TOKEN: ${{ secrets.MPKIT_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
scope=@platformos
save=false
save=false
3 changes: 0 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# Changelog

## 4.13.0
* Feature: Initial alpha implementation of new logs API

## 4.12.8
* Bug: fix adding env with `--email` option

Expand Down
33 changes: 0 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,39 +96,6 @@ Example:

pos-cli logs staging --filter debug

### Logs V2

#### LOGS

examples:

pos-cli logsv2 search stg --size 5 --from 0

pos-cli logsv2 search stg --sql "select * from logs" --json | jq

pos-cli logsv2 search stg --sql "select message,type from logs" --json | jq

pos-cli logsv2 search stg --sql "select * from logs where str_match(message, 'com')" --start_time 1694694303000000 --size 5 | jq

#### ALERTS

examples:

pos-cli logsv2 alerts list stg # list alerts

pos-cli logsv2 alerts add stg --url SLACK_URL --name descriptive-alert-title-slack-02 --column message --operator Contains --keyword 'this is fine' --channel gcp-alerts

pos-cli logsv2 alerts list stg

pos-cli logsv2 alerts trigger stg --name descriptive-alert-title-slack-02


#### ROADMAP

- alerts delete
- better errors
- GUI

### Listing environments

If you forgot what your environments are called or the URL that corresponds to any name, use:
Expand Down
93 changes: 46 additions & 47 deletions bin/pos-cli-data-clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,68 +7,67 @@ const program = require('commander'),
waitForStatus = require('../lib/data/waitForStatus'),
fetchAuthData = require('../lib/settings').fetchSettings,
logger = require('../lib/logger'),
ServerError = require('../lib/ServerError'),
report = require('../lib/logger/report');

const confirmationText = 'CLEAN DATA';
const spinner = ora({ text: 'Sending data', stream: process.stdout, spinner: 'bouncingBar' });

const confirmCleanup = async (autoConfirm, includeSchema, url) => {
if (autoConfirm) return true;
try {
let schemaText = includeSchema ? 'and database schemas ' : '';
const clean = (gateway, includeSchema) => {
logger.Info('Going to clean data');
gateway
.dataClean(confirmationText, includeSchema)
.then((cleanTask) => {
spinner.stopAndPersist().succeed('Clean started').start(`Cleaning instance`);
waitForStatus(() => gateway.dataCleanStatus(cleanTask.id), 'pending', 'done')
.then(() => {
spinner.stopAndPersist().succeed('Cleaning done');
})
.catch((error) => {
logger.Debug(error);
spinner.fail('Data clean failed');
logger.Error(`Unable to clean instance ${error.error}`);
});
})
.catch({ statusCode: 404 }, () => {
logger.Error('[404] Data clean is not supported by the server');
report('[Err] Data: Clean - Not supported');
});
};

logger.Warn('');
logger.Warn(`WARNING!!! You are going to REMOVE your data ${schemaText}from instance: ${url}`);
logger.Warn('There is no coming back.');
logger.Warn('');
const promptConfirmation = async confirmationText => {
const message = `If you still want to continue please type: '${confirmationText}' `;

const message = `If you still want to continue please type: '${confirmationText}' `;
const response = await prompts({ type: 'text', name: 'confirmation', message: message });
const response = await prompts({ type: 'text', name: 'confirmation', message: message });
return response.confirmation;
};

return response.confirmation == confirmationText;
}
catch(e) {
logger.Error(e)
return false;
const confirmCleanup = async (gateway, inlineConfirmation, includeSchema) => {
let schemaText = includeSchema ? 'and database schemas ' : '';

logger.Warn('');
logger.Warn(`WARNING!!! You are going to REMOVE your data ${schemaText}from instance: ${gateway.url}`);
logger.Warn('There is no coming back.');
logger.Warn('');
const confirmed = inlineConfirmation || (await promptConfirmation(confirmationText)) == confirmationText;
if (confirmed) {
clean(gateway, includeSchema);

report('[OK] Data: Clean');
} else {
logger.Error('Wrong confirmation. Closed without cleaning instance data.');
report('[ERR] Data: Clean - Wrong confirmation');
}
};

program
.name('pos-cli data clean')
.argument('[environment]', 'name of the environment. Example: staging')
.arguments('[environment]', 'name of the environment. Example: staging')
.option('--auto-confirm', 'auto confirm instance clean without prompt')
.option('-i, --include-schema', 'also remove instance files: pages, schemas etc.')
.action(async (environment, params) => {
const spinner = ora({ text: 'Sending data', stream: process.stdout, spinner: 'bouncingBar' });
try {
const gateway = new Gateway(fetchAuthData(environment));
const confirmed = await confirmCleanup(params.autoConfirm, params.includeSchema, gateway.url)
if (confirmed) {
spinner.start(`Cleaning instance`);

const response = await gateway.dataClean(confirmationText, params.includeSchema)
logger.Debug(`Cleanup request id: ${response}`);

const checkDataCleanJobStatus = () => { return gateway.dataCleanStatus(response.id) }
await waitForStatus(checkDataCleanJobStatus, 'pending', 'done')

spinner.stopAndPersist().succeed("DONE. Instance cleaned")
}
else logger.Error('Wrong confirmation. Closed without cleaning instance data.');

}
catch(e) {
spinner.fail(`Instance cleanup has failed.`);
console.log(e.name);
.action((environment, params) => {
const gateway = new Gateway(fetchAuthData(environment, program));

// custom handle 422
if (e.statusCode == 422)
logger.Error('[422] Data clean is either not supported by the server or has been disabled.');
else if (ServerError.isNetworkError(e))
ServerError.handler(e)
else
logger.Error(e)
}
confirmCleanup(gateway, params.autoConfirm, params.includeSchema);
});

program.parse(process.argv);
2 changes: 1 addition & 1 deletion bin/pos-cli-data-export.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const fetchFilesForData = async (data) => {
program
.name('pos-cli data export')
.arguments('[environment]', 'name of the environment. Example: staging')
.requiredOption('-p --path <export-file-path>', 'output for exported data. Example: data.json, data.zip')
.option('-p --path <export-file-path>', 'output for exported data. Example: data.json, data.zip')
.option(
'-e --export-internal-ids <export-internal-ids>',
'use normal object `id` instead of `external_id` in exported json data',
Expand Down
8 changes: 4 additions & 4 deletions bin/pos-cli-data-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,19 @@ const dataImport = async (filename, rawIds, isZipFile) => {

program
.name('pos-cli data import')
.argument('[environment]', 'name of the environment. Example: staging')
.arguments('[environment]', 'name of the environment. Example: staging')
.option(
'-p --path <import-file-path>',
'path of import .json or .zip file. Example: data.json, data.zip',
'data.json'
)
.option('--raw-ids <raw-ids>', 'do not remap ids after import', false)
.option('-z --zip', 'import from zip archive', false)
.option('--raw-ids <raw-ids>', 'do not remap ids after import', 'false')
.option('-z --zip', 'import from zip archive', 'false')
.action((environment, params) => {
const filename = params.path;
const rawIds = params.rawIds;
const zip = params.zip;
const authData = fetchAuthData(environment);
const authData = fetchAuthData(environment, program);
Object.assign(process.env, {
MARKETPLACE_TOKEN: authData.token,
MARKETPLACE_URL: authData.url,
Expand Down
2 changes: 1 addition & 1 deletion bin/pos-cli-deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const runAudit = async () => {

program
.name('pos-cli deploy')
.argument('[environment]', 'name of environment. Example: staging')
.arguments('[environment]', 'name of environment. Example: staging')
.option('-f --force', 'deprecated')
.option('-d --direct-assets-upload', 'deprecated, this is default strategy')
.option('-o --old-assets-upload', 'use old assets upload strategy')
Expand Down
2 changes: 1 addition & 1 deletion bin/pos-cli-env-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const listEnvironments = () => {
logger.Info(`- [${env}] ${settings[env].url}`, { hideTimestamp: true });
}
} else {
logger.Info('No environments registered yet, please see pos-cli env add', { exit: false });
logger.Error('No environments registered yet, please see pos-cli env add', { exit: false });
}
};

Expand Down
2 changes: 1 addition & 1 deletion bin/pos-cli-env.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ program
'Add new environment. Example: pos-cli env add staging --email [email protected] --url https://example.com'
)
.command('list', 'list all environments')
.parse(process.argv);
.parse(process.argv);
5 changes: 1 addition & 4 deletions bin/pos-cli-gui-serve.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env node
const swagger = require('../lib/swagger-client');

const program = require('commander'),
watch = require('../lib/watch'),
Expand Down Expand Up @@ -29,8 +28,7 @@ program
});

try {
const client = await swagger.SwaggerProxy.client(environment);
server.start(env, client);
await server.start(env);
if (params.open) {
await open(`http://localhost:${params.port}`);
}
Expand All @@ -39,7 +37,6 @@ program
watch.start(env, true, false);
}
} catch (e) {
console.log(e);
logger.Error('✖ Failed.');
}
});
Expand Down
57 changes: 24 additions & 33 deletions bin/pos-cli-logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,47 +12,39 @@ const fetchAuthData = require('../lib/settings').fetchSettings,
Gateway = require('../lib/proxy');

class LogStream extends EventEmitter {
constructor(authData, interval) {
constructor(authData) {
super();
this.authData = authData;
this.gateway = new Gateway(authData);
this.interval = interval
}

start() {
const t = this;
setInterval(() => t.fetchData(), t.interval);
logger.Debug('Starting live logging...');
setInterval(() => t.fetchData(), program.interval);
logger.Info('Starting live logging...');
}

fetchData() {
this.gateway.logs({ lastId: storage.lastId })
.then((response) => {
const logs = response && response.logs;
if (!logs) {
return false;
}
this.gateway.logs({ lastId: storage.lastId }).then((response) => {
const logs = response && response.logs;
if (!logs) {
return false;
}

for (let k in logs) {
const row = logs[k];
const filter = !!program.filter && program.filter.toLowerCase();

try {
const errorType = (row.error_type || 'error').toLowerCase();
}
catch(e) {
logger.Error(`${row.error_type} error`)
const errorType = "weird-error-type"
}
for (let k in logs) {
const row = logs[k];
const filter = !!program.filter && program.filter.toLowerCase();
const errorType = (row.error_type || 'error').toLowerCase();

if (!!program.filter && filter !== errorType) continue;
if (!!program.filter && filter !== errorType) continue;

if (!storage.exists(row.id)) {
storage.add(row);
this.emit('message', row);
}
if (!storage.exists(row.id)) {
storage.add(row);
this.emit('message', row);
}
})
}
});
}
}

Expand All @@ -70,13 +62,13 @@ const isError = (msg) => /error/.test(msg.error_type);

program
.name('pos-cli logs')
.argument('[environment]', 'name of environment. Example: staging')
.option('-i, --interval <interval>', 'time to wait between updates in ms', 3000)
.arguments('[environment]', 'name of environment. Example: staging')
.option('--interval <interval>', 'time to wait between updates in ms', 3000)
.option('--filter <log type>', 'display only logs of given type, example: error')
.option('-q, --quiet', 'show only log message, without context')
.action((environment, program, argument) => {
.action((environment) => {
const authData = fetchAuthData(environment, program);
const stream = new LogStream(authData, program.interval);
const stream = new LogStream(authData);

stream.on('message', ({ created_at, error_type, message, data }) => {
if (message == null) message = '';
Expand All @@ -93,7 +85,7 @@ program
'app-name': 'pos-cli',
});

logger.Info(text, options);
logger.Error(text, options);
} else {
logger.Info(text, options);
if (!program.quiet && data) {
Expand All @@ -107,13 +99,12 @@ program
if (data.page) parts.push(`page: ${data.page}`);
if (data.partial) parts.push(`partial: ${data.partial}`);
if (data.user && data.user.email) parts.push(`email: ${data.user.email}`);
if (parts.length > 0) logger.Info(parts.join(' '), options);
if (parts.length > 0) logger.Quiet(parts.join(' '), options);
}
}
});

stream.start();
});

program.showHelpAfterError();
program.parse(process.argv);
Loading