Hey there, I'm struggling to retrieve a list of SLOs in my Google Cloud project via the REST API using TypeScript. Unfortunately, I keep running into an error message. Could you lend me a hand with this? The error reads:
(node:47173) UnhandledPromiseRejectionWarning: Error: 3 INVALID_ARGUMENT: Received invalid service name: [object Object] at Object.callErrorFromStatus (/Users/mpanova/workspace/node/monitoring-automation/node_modules/@grpc/grpc-js/src/call.ts:81:24) at Object.onReceiveStatus (/Users/mpanova/workspace/node/monitoring-automation/node_modules/@grpc/grpc-js/src/client.ts:334:36) at Object.onReceiveStatus (/Users/mpanova/workspace/node/monitoring-automation/node_modules/@grpc/grpc-js/src/client-interceptors.ts:434:34) at Object.onReceiveStatus (/Users/mpanova/workspace/node/monitoring-automation/node_modules/@grpc/grpc-js/src/client-interceptors.ts:397:48) at Http2CallStream.outputStatus (/Users/mpanova/workspace/node/monitoring-automation/node_modules/@grpc/grpc-js/src/call-stream.ts:230:22) at Http2CallStream.maybeOutputStatus (/Users/mpanova/workspace/node/monitoring-automation/node_modules/@grpc/grpc-js/src/call-stream.ts:280:14) at Http2CallStream.endCall (/Users/mpanova/workspace/node/monitoring-automation/node_modules/@grpc/grpc-js/src/call-stream.ts:263:12) at Http2CallStream.handleTrailers (/Users/mpanova/workspace/node/monitoring-automation/node_modules/@grpc/grpc-js/src/call-stream.ts:412:10) at ClientHttp2Stream.emit (events.js:314:20) at emit (internal/http2/core.js:291:8) at processTicksAndRejections (internal/process/task_queues.js:83:22) at emitUnhandledRejectionWarning (internal/process/promises.js:168:15) at processPromiseRejections (internal/process/promises.js:247:11) at processTicksAndRejections (internal/process/task_queues.js:94:32)
To be frank, I'm relatively new to TypeScript as I usually work with Java, so perhaps the error is something simple that I am overlooking.
This is the code snippet causing issues: list_slos.ts in source directory
export module ListSloTest {
export async function listSlos(projectId: string) {
// Imports the Google Cloud client library
const monitoring = require('@google-cloud/monitoring');
// Creates a client
const client = new monitoring.ServiceMonitoringServiceClient();
const request = {
parent: client.projectPath(projectId),
};
console.log(projectId)
const [slos] = await client.listServiceLevelObjectives({parent: request});
slos.forEach((slo: any) => {
console.log('');
console.log('slo: %j', slo);
});
**list_slos.ts in test directory**
import "mocha";
import * as assert from "assert";
import {ListSloTest} from "../dist/list_slos";
describe("list_slos",()=>{
before(function () {
process.env = {GOOGLE_CLOUD_PROJECT: 'projectId',
GOOGLE_APPLICATION_CREDENTIALS: '/somePath/projectId-a17ce3d7c2e6.json'};
});
it("should list slos in given project",()=>{
ListSloTest.listSlos("projectId");
//console.log("hello, world!")
assert.ok(true);
});
});
I typically compile the code from the source directory to the dist directory before running tests on it.