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

GCF: delete extraneous getmetrics sample #1734

Merged
merged 1 commit into from
Apr 22, 2020
Merged
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
47 changes: 0 additions & 47 deletions functions/log/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,52 +48,6 @@ const getLogEntries = async () => {
};
// [END functions_log_retrieve]

// [START functions_log_get_metrics]
// By default, the client will authenticate using the service account file
// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use
// the project specified by the GCLOUD_PROJECT environment variable. See
// https://github.com/googleapis/google-cloud-node/blob/master/docs/authentication.md
const Monitoring = require('@google-cloud/monitoring');

const getMetrics = (callback) => {
// Instantiates a client
const monitoring = Monitoring.v3().metricServiceApi();

// Create two datestrings, a start and end range
const oneWeekAgo = new Date();
oneWeekAgo.setHours(oneWeekAgo.getHours() - 7 * 24);

const options = {
name: monitoring.projectPath(process.env.GCLOUD_PROJECT),
// There is also: cloudfunctions.googleapis.com/function/execution_count
filter:
'metric.type="cloudfunctions.googleapis.com/function/execution_times"',
interval: {
startTime: {
seconds: oneWeekAgo.getTime() / 1000,
},
endTime: {
seconds: Date.now() / 1000,
},
},
view: 1,
};

console.log('Data:');

let error;

// Iterate over all elements.
monitoring
.listTimeSeries(options)
.on('error', (err) => {
error = err;
})
.on('data', (element) => console.log(element))
.on('end', () => callback(error));
// [END functions_log_get_metrics]
};

// [START functions_log_stackdriver]
exports.processLogEntry = (data) => {
const dataBuffer = Buffer.from(data.data, 'base64');
Expand All @@ -106,4 +60,3 @@ exports.processLogEntry = (data) => {
// [END functions_log_stackdriver]

exports.getLogEntries = getLogEntries;
exports.getMetrics = getMetrics;
11 changes: 0 additions & 11 deletions functions/log/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,6 @@ describe('functions_log_retrieve', () => {
});
});

describe('functions_log_get_metrics', () => {
it('getMetrics: should retrieve metrics', () => {
const sample = getSample();
const callback = sinon.stub();

sample.program.getMetrics(callback);

assert.strictEqual(callback.callCount, 1);
});
});

describe('functions_log_stackdriver', () => {
it('processLogEntry: should process log entry', () => {
const sample = getSample();
Expand Down