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

added couchbase probe for couchnode package #498

Closed
wants to merge 9 commits 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
3 changes: 2 additions & 1 deletion AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion extract_all_binaries.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
Expand Down
2 changes: 1 addition & 1 deletion get_from_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import json,sys

if len(sys.argv) < 2:
print "Usage get_from_json file <field>"
print("Usage get_from_json file <field>")
exit (-1)

with open(sys.argv[1]) as f:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "appmetrics",
"version": "3.1.2",
"version": "3.1.3",
"engines": {
"node": ">=4"
},
Expand Down
96 changes: 96 additions & 0 deletions probes/couchbase-probe.js
Original file line number Diff line number Diff line change
@@ -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;
49 changes: 49 additions & 0 deletions tests/probes/couchbase-probe-tests.js
Original file line number Diff line number Diff line change
@@ -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');
});
});