diff --git a/AUTHORS.md b/AUTHORS.md index 70422135..14072956 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -17,4 +17,5 @@ Authors ordered by first contribution: - Luca Bigon (https://github.com/bigluck) - Gibson Fahnestock (https://github.com/gibfahn) - ? (https://github.com/nqvst) - + - Vladislav Botvin (https://github.com/darky) + - Jake Warren (https://github.com/astub) diff --git a/README.md b/README.md index bedd64ff..368356a8 100644 --- a/README.md +++ b/README.md @@ -445,7 +445,7 @@ Requests are a special type of event emitted by appmetrics. All the probes name The Node Application Metrics agent supports the following runtime environments where a Node.js runtime is available: -* **Node.js v4, v7 and v8** on: +* **Node.js v4 and v8** on: * 64-bit or 32-bit runtime on Windows (x64 or x86) * 64-bit or 32-bit runtime on Linux (x64, x86, PPC32, PPC64, PPC64LE, z31, z64) * 64-bit or 32-bit runtime on AIX (PPC64) @@ -505,12 +505,13 @@ The npm package for this project uses a semver-parsable X.0.Z version number for Non-release versions of this project (for example on github.com/RuntimeTools/appmetrics) will use semver-parsable X.0.Z-dev.B version numbers, where X.0.Z is the last release with Z incremented and B is an integer. For further information on the development process go to the [appmetrics wiki][3]: [Developing](https://github.com/RuntimeTools/appmetrics/wiki/Developing). ## Version -3.1.2 +3.1.3 ## Release History +`3.1.3` - Packaging fix. `3.1.2` - Bug fixes. `3.1.1` - Node v6 on z/OS support. -`3.1.0` - HTTPS probe added. +`3.1.0` - HTTPS probe added. Remove support for Node v7. `3.0.2` - Probe defect for Node 8 support. `3.0.1` - Packaging bug fix to allow build from source if binary not present. `3.0.0` - Remove express probe. Additional data available in http and request events. Code improvements. diff --git a/extract_all_binaries.js b/extract_all_binaries.js index df511fe1..a4979f35 100644 --- a/extract_all_binaries.js +++ b/extract_all_binaries.js @@ -42,7 +42,7 @@ var AGENTCORE_PLATFORMS = [ 'os390-s390x', ]; var AGENTCORE_VERSION = '3.2.6'; -var APPMETRICS_VERSION = '3.1.2'; +var APPMETRICS_VERSION = '3.1.3'; var LOG_FILE = path.join(INSTALL_DIR, 'install.log'); var logFileStream = fs.createWriteStream(LOG_FILE, { flags: 'a' }); diff --git a/get_from_json.py b/get_from_json.py index 00b9f607..9ca43735 100644 --- a/get_from_json.py +++ b/get_from_json.py @@ -16,7 +16,7 @@ import json,sys if len(sys.argv) < 2: - print "Usage get_from_json file " + print("Usage get_from_json file ") exit (-1) with open(sys.argv[1]) as f: diff --git a/package.json b/package.json index 2e1cce91..647f3093 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "appmetrics", - "version": "3.1.2", + "version": "3.1.3", "engines": { "node": ">=4" }, diff --git a/probes/couchbase-probe.js b/probes/couchbase-probe.js new file mode 100644 index 00000000..dca248dc --- /dev/null +++ b/probes/couchbase-probe.js @@ -0,0 +1,96 @@ +/******************************************************************************* + * Copyright 2017 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *******************************************************************************/ +'use strict'; + +var Probe = require('../lib/probe.js'); +var aspect = require('../lib/aspect.js'); +var util = require('util'); +var am = require('../'); + +function CouchbaseProbe() { + Probe.call(this, 'couchbase'); +} +util.inherits(CouchbaseProbe, Probe); + +CouchbaseProbe.prototype.aspectBucketMethod = function(bucket, method) { + var that = this; + aspect.before(bucket, method, function(target, methodName, methodArgs, probeData) { + that.metricsProbeStart(probeData, method, methodArgs); + if (aspect.findCallbackArg(methodArgs) != undefined) { + aspect.aroundCallback(methodArgs, probeData, function(target, args) { + that.metricsProbeEnd(probeData, methodName, bucket._name, args[0]); + }); + } + }); +}; + +// Most used couchbase bucket methods +const bucketMethods = ['query', 'upsert', 'insert', 'replace', 'remove', 'get', 'getMulti']; + +CouchbaseProbe.prototype.attach = function(name, target) { + var that = this; + if (name != 'couchbase') return target; + if (target.__ddProbeAttached__) return target; + target.__ddProbeAttached__ = true; + + var mock = target['Mock']['Cluster'].prototype; + var cluster = target['Cluster'].prototype; + var data = {}; + + // couchbase mock cluster + aspect.after(mock, 'openBucket', data, function(target, methodName, args, probeData, bucket) { + for(key in bucketMethods) { + that.aspectBucketMethod(bucket, bucketMethods[key]); + } + return bucket; + }); + + // couchbase cluster + aspect.after(cluster, 'openBucket', data, function(target, methodName, args, probeData, bucket) { + for(key in bucketMethods) { + that.aspectBucketMethod(bucket, bucketMethods[key]); + } + return bucket; + }); + + return target; +}; + +/* + * Lightweight metrics probe for couchbase queries + * + * These provide: + * time: time event started + * bucket: The bucket executed on + * method: the method called on the bucket + * duration: the time for the request to respond + */ +CouchbaseProbe.prototype.metricsEnd = function(probeData, method, bucketName, err) { + if (probeData && probeData.timer) { + probeData.timer.stop(); + var eventTimer = probeData.timer; + am.emit('couchbase', { + time: eventTimer.startTimeMillis, + bucket: bucketName, + method: method, + duration: eventTimer.timeDelta, + error: err + }); + } +}; + + +module.exports = CouchbaseProbe; diff --git a/tests/probes/couchbase-probe-tests.js b/tests/probes/couchbase-probe-tests.js new file mode 100644 index 00000000..969f9ca7 --- /dev/null +++ b/tests/probes/couchbase-probe-tests.js @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright 2015 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *******************************************************************************/ +'use strict'; + +// This script tests the client instance functionality of the couchnode module. +var appmetrics = require('appmetrics'); +var tap = require('tap'); + +// Live monitoring +var amapi = appmetrics.monitor(); + +// Testing variables +var actualEvents = 0; +var expectedEvents = 2; + +// all cb events +amapi.on('couchbase', function(response) { + actualEvents++; +}); + +var couchbase = require('couchbase').Mock; +var cluster = new couchbase.Cluster(); +var bucket = cluster.openBucket(); + +bucket.upsert('testdoc', {name:'Frank'}, function(err, result) { + if (err) throw err; + + bucket.get('testdoc', function(err, result) { + if (err) throw err; + + console.log(result.value); + // {name: Frank} + + tap.equals(actualEvents, expectedEvents, 'the callback was not called'); + }); +});