Page MenuHomePhabricator

Support skipping column names when using `sql` on Tool Labs
Closed, ResolvedPublic

Description

mzmcbride@tools-bastion-03:~$ echo "select dbname from wiki limit 3" | sql -vv meta
Connecting to s7.analytics.db.svc.eqiad.wmflabs
['mysql', '--defaults-file=/home/mzmcbride/replica.my.cnf', '-h', 's7.analytics.db.svc.eqiad.wmflabs', 'meta_p']
dbname
aawiki
aawikibooks
aawiktionary

Including the column header can sometimes be kind of annoying behavior, so let's leverage mysql's -N/--skip-column-names flag!

Using my patched version:

mzmcbride@tools-bastion-03:~$ echo "select dbname from wiki limit 3" | ./sql -N -vv meta
Connecting to s7.analytics.db.svc.eqiad.wmflabs
['mysql', '--defaults-file=/home/mzmcbride/replica.my.cnf', '-N', '-h', 's7.analytics.db.svc.eqiad.wmflabs', 'meta_p']
aawiki
aawikibooks
aawiktionary
mzmcbride@tools-bastion-03:~$ diff -u /usr/bin/sql ./sql 
--- /usr/bin/sql	2018-03-05 18:29:19.000000000 +0000
+++ ./sql	2018-03-12 03:39:32.331253946 +0000
@@ -47,6 +47,9 @@
     '-v', '--verbose', action='count', default=0, dest='loglevel',
     help='increase logging verbosity')
 parser.add_argument(
+    '-N', '--skip-column-names', default=None,
+    action='store_true', help='do not write column names in results')
+parser.add_argument(
     '--cluster', default='analytics',
     choices=['analytics', 'web'],
     help='cluster to connect to')
@@ -77,6 +80,9 @@
         'There is no configuration file for mysql to use, ' +
         'you will probably be unable to access the database')
 
+if args.skip_column_names:
+    exec_args.append('-N')
+
 db = ALIASES.get(args.dbname, args.dbname)
 
 if db == 'meta_p':

Event Timeline

Change 418840 had a related patch set uploaded (by MZMcBride; owner: MZMcBride):
[labs/toollabs@master] sql: Add support for -N/--skip-column-names

https://gerrit.wikimedia.org/r/418840

Change 418840 merged by jenkins-bot:
[labs/toollabs@master] sql: Add support for -N/--skip-column-names

https://gerrit.wikimedia.org/r/418840

Mentioned in SAL (#wikimedia-cloud) [2018-03-12T14:58:50Z] <zhuyifei1999_> building, publishing, and deploying misctools 1.31 5f3561e T189430

03:06:10 0 ✓ zhuyifei1999@tools-bastion-05: ~$ echo "select dbname from wiki limit 3" | sql -N -vv meta
Connecting to s7.analytics.db.svc.eqiad.wmflabs
['mysql', '--defaults-file=/home/zhuyifei1999/replica.my.cnf', '-N', '-h', 's7.analytics.db.svc.eqiad.wmflabs', 'meta_p']
aawiki
aawikibooks
aawiktionary

I don't think I can run clush:

root@tools-clushmaster-01:~# clush -w @all -b '/usr/bin/dpkg -s misctools &>/dev/null && sudo apt-get update -qq && sudo /usr/bin/env DEBIAN_FRONTEND=noninteractive apt-get install -q -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" misctools'
Only members of tools.admin group can use clush interactively
This is to make sure we have a nice and clean audit trail
root@tools-clushmaster-01:~# getent group tools.admin
Do not run this directly as root or use sudo
tools.admin:*:51051:valhallasw,scfc,yuvipanda,bd808,ariel,andrew,jmm,rush,quiddity,aborrero,petrb,oblivian,akosiaris,chicocvenancio,madhuvishy,reedy,bstorm

I guess I'll just leave the apt auto-upgrading to upgrade the packages on the other two bastions.

zhuyifei1999 claimed this task.
03:34:44 0 ✓ zhuyifei1999@tools-bastion-02: ~$ sql -N -vv meta "select dbname from wiki limit 3"
Connecting to s7.analytics.db.svc.eqiad.wmflabs
['mysql', '--defaults-file=/home/zhuyifei1999/replica.my.cnf', '-N', '-h', 's7.analytics.db.svc.eqiad.wmflabs', 'meta_p', '-e', 'select dbname from wiki limit 3']
+--------------+
| aawiki       |
| aawikibooks  |
| aawiktionary |
+--------------+
[...]
03:35:00 0 ✓ zhuyifei1999@tools-bastion-03: ~$ sql -N -vv meta "select dbname from wiki limit 3"
Connecting to s7.analytics.db.svc.eqiad.wmflabs
['mysql', '--defaults-file=/home/zhuyifei1999/replica.my.cnf', '-N', '-h', 's7.analytics.db.svc.eqiad.wmflabs', 'meta_p', '-e', 'select dbname from wiki limit 3']
+--------------+
| aawiki       |
| aawikibooks  |
| aawiktionary |
+--------------+