Repository: rueckstiess/mtools

Issue:
Update matplotlib & numpy requirements
matplotlib & numpy are pinned to very old versions in `requirements.txt`:

```
matplotlib==1.3.1
numpy==1.8.0
```
It looks like the versions may be based on a pip freeze when `mplotqueries` was originally developed in ~2013.

Comments:

Patch:
diff --git a/mtools/mplotqueries/mplotqueries.py b/mtools/mplotqueries/mplotqueries.py
index 4f8dce6..7256eca 100644
--- a/mtools/mplotqueries/mplotqueries.py
+++ b/mtools/mplotqueries/mplotqueries.py
@@ -14,6 +14,7 @@ from mtools import __version__
 from mtools.util.cmdlinetool import LogFileTool
 
 try:
+    import matplotlib
     import matplotlib.pyplot as plt
     from matplotlib.dates import AutoDateFormatter, date2num, AutoDateLocator
     from matplotlib import __version__ as mpl_version
diff --git a/mtools/mplotqueries/plottypes/scatter_type.py b/mtools/mplotqueries/plottypes/scatter_type.py
index 6fca067..70c9ac4 100644
--- a/mtools/mplotqueries/plottypes/scatter_type.py
+++ b/mtools/mplotqueries/plottypes/scatter_type.py
@@ -6,8 +6,6 @@ from operator import itemgetter
 from mtools.mplotqueries.plottypes.base_type import BasePlotType
 
 try:
-    import matplotlib.pyplot as plt
-
     from matplotlib import __version__ as mpl_version
     from matplotlib.dates import date2num
     from matplotlib.patches import Polygon
diff --git a/mtools/util/logevent.py b/mtools/util/logevent.py
index f9023de..7901e56 100644
--- a/mtools/util/logevent.py
+++ b/mtools/util/logevent.py
@@ -181,7 +181,10 @@ class LogEvent(object):
             # split_tokens = self.split_tokens
             line_str = self.line_str
 
-            if line_str and line_str.endswith('ms'):
+            if (line_str
+                and line_str.endswith('ms')
+                and 'Scheduled new oplog query' not in line_str):
+
                 try:
                     # find duration from end
                     space_pos = line_str.rfind(" ")
diff --git a/requirements.txt b/requirements.txt
index 7c0d657..1dd45d3 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,6 +1,6 @@
 ordereddict==1.1
 python-dateutil==2.7
-matplotlib==1.3.1
-numpy==1.8.0
+matplotlib==2.2.2
+numpy==1.14.5
 pymongo==3.6
 psutil==5.4
diff --git a/setup.py b/setup.py
index f79cbc4..2cdc6a1 100644
--- a/setup.py
+++ b/setup.py
@@ -17,12 +17,12 @@ try:
     # simplify the default install experience, particularly where a build
     # toolchain is required.
     extras_requires = {
-        "all": ['matplotlib==1.3.1', 'numpy==1.8.0', 'pymongo==3.6', 'psutil==5.4'],
+        "all": ['matplotlib==2.2.2', 'numpy==1.14.5', 'pymongo==3.6', 'psutil==5.4'],
         "mlaunch": ['pymongo==3.6', 'psutil==5.4'],
         "mlogfilter": [],
-        "mloginfo": ['numpy==1.8.0'],
+        "mloginfo": ['numpy==1.14.5'],
         "mlogvis": [],
-        "mplotqueries": ['matplotlib==1.3.1', 'numpy==1.8.0'],
+        "mplotqueries": ['matplotlib==2.2.2', 'numpy==1.14.5'],
     }
 
     try:


Test patch:
diff --git a/mtools/test/test_util_logevent.py b/mtools/test/test_util_logevent.py
index 7c4d68b..e0d93e1 100644
--- a/mtools/test/test_util_logevent.py
+++ b/mtools/test/test_util_logevent.py
@@ -63,6 +63,7 @@ line_truncated_24 = ("Wed Jan 28 00:31:16.302 [conn12345] warning: log line "
                      "reslen:256993 1445ms")
 line_fassert = ("***aborting after fassert() failure")
 line_empty = ("")
+line_new_oplog_query = ('2018-05-01T21:57:45.989+0000 I REPL [replication-0] Scheduled new oplog query Fetcher source: host.name database: local query: { find: "oplog.rs", filter: { ts: { $gte: Timestamp(1525211859, 1) } }, tailable: true, oplogReplay: true, awaitData: true, maxTimeMS: 60000, batchSize: 13981010, term: 1, readConcern: { afterClusterTime: Timestamp(1525211859, 1) } } query metadata: { $replData: 1, $oplogQueryData: 1, $readPreference: { mode: "secondaryPreferred" } } active: 1 findNetworkTimeout: 65000ms getMoreNetworkTimeout: 7500ms shutting down?: 0 first: 1 firstCommandScheduler: RemoteCommandRetryScheduler request: RemoteCommand 16543 -- target:host.name db:local cmd:{ find: "oplog.rs", filter: { ts: { $gte: Timestamp(1525211859, 1) } }, tailable: true, oplogReplay: true, awaitData: true, maxTimeMS: 60000, batchSize: 13981010, term: 1, readConcern: { afterClusterTime: Timestamp(1525211859, 1) } } active: 1 callbackHandle.valid: 1 callbackHandle.cancelled: 0 attempt: 1 retryPolicy: RetryPolicyImpl maxAttempts: 1 maxTimeMillis: -1ms')
 
 # fake system.profile documents
 profile_doc1 = {"op": "query", "ns": "test.foo",
@@ -252,6 +253,11 @@ def test_logevent_non_log_line():
     assert(le.nreturned == None)
     assert(le.pattern == None)
 
+def test_logevent_new_oplog_query():
+    """ Check that LogEvent correctly ignores new oplog query for duration extraction """
+    le = LogEvent(line_new_oplog_query)
+    assert(le.duration == None)
+
 def test_logevent_lazy_evaluation():
     """ Check that all LogEvent variables are evaluated lazily. """