mirror of
https://github.com/grpc/grpc-node.git
synced 2025-12-08 18:23:54 +00:00
grpc-js: Add a few basic trace lines to the server
This commit is contained in:
parent
1e15d058a3
commit
a53bcb3c97
@ -20,12 +20,19 @@ import * as http2 from 'http2';
|
||||
import { Duplex, Readable, Writable } from 'stream';
|
||||
|
||||
import { StatusObject } from './call-stream';
|
||||
import { Status, DEFAULT_MAX_SEND_MESSAGE_LENGTH, DEFAULT_MAX_RECEIVE_MESSAGE_LENGTH } from './constants';
|
||||
import { Status, DEFAULT_MAX_SEND_MESSAGE_LENGTH, DEFAULT_MAX_RECEIVE_MESSAGE_LENGTH, LogVerbosity } from './constants';
|
||||
import { Deserialize, Serialize } from './make-client';
|
||||
import { Metadata } from './metadata';
|
||||
import { StreamDecoder } from './stream-decoder';
|
||||
import { ObjectReadable, ObjectWritable } from './object-stream';
|
||||
import { ChannelOptions } from './channel-options';
|
||||
import * as logging from './logging';
|
||||
|
||||
const TRACER_NAME = 'server_call';
|
||||
|
||||
function trace(text: string): void {
|
||||
logging.trace(LogVerbosity.DEBUG, TRACER_NAME, text);
|
||||
}
|
||||
|
||||
interface DeadlineUnitIndexSignature {
|
||||
[name: string]: number;
|
||||
@ -294,6 +301,7 @@ export interface UnaryHandler<RequestType, ResponseType> {
|
||||
serialize: Serialize<ResponseType>;
|
||||
deserialize: Deserialize<RequestType>;
|
||||
type: HandlerType;
|
||||
path: string;
|
||||
}
|
||||
|
||||
export interface ClientStreamingHandler<RequestType, ResponseType> {
|
||||
@ -301,6 +309,7 @@ export interface ClientStreamingHandler<RequestType, ResponseType> {
|
||||
serialize: Serialize<ResponseType>;
|
||||
deserialize: Deserialize<RequestType>;
|
||||
type: HandlerType;
|
||||
path: string;
|
||||
}
|
||||
|
||||
export interface ServerStreamingHandler<RequestType, ResponseType> {
|
||||
@ -308,6 +317,7 @@ export interface ServerStreamingHandler<RequestType, ResponseType> {
|
||||
serialize: Serialize<ResponseType>;
|
||||
deserialize: Deserialize<RequestType>;
|
||||
type: HandlerType;
|
||||
path: string;
|
||||
}
|
||||
|
||||
export interface BidiStreamingHandler<RequestType, ResponseType> {
|
||||
@ -315,6 +325,7 @@ export interface BidiStreamingHandler<RequestType, ResponseType> {
|
||||
serialize: Serialize<ResponseType>;
|
||||
deserialize: Deserialize<RequestType>;
|
||||
type: HandlerType;
|
||||
path: string;
|
||||
}
|
||||
|
||||
export type Handler<RequestType, ResponseType> =
|
||||
@ -521,6 +532,8 @@ export class Http2ServerCallStream<
|
||||
return;
|
||||
}
|
||||
|
||||
trace('Request to method ' + this.handler?.path + ' ended with status code: ' + Status[statusObj.code] + ' details: ' + statusObj.details);
|
||||
|
||||
clearTimeout(this.deadline);
|
||||
|
||||
if (!this.wantTrailers) {
|
||||
|
||||
@ -46,14 +46,21 @@ import {
|
||||
import { ServerCredentials } from './server-credentials';
|
||||
import { ChannelOptions } from './channel-options';
|
||||
import { createResolver, ResolverListener, mapUriDefaultScheme } from './resolver';
|
||||
import { log } from './logging';
|
||||
import * as logging from './logging';
|
||||
import {
|
||||
SubchannelAddress,
|
||||
TcpSubchannelAddress,
|
||||
isTcpSubchannelAddress,
|
||||
subchannelAddressToString,
|
||||
} from './subchannel';
|
||||
import { parseUri } from './uri-parser';
|
||||
|
||||
const TRACER_NAME = 'server';
|
||||
|
||||
function trace(text: string): void {
|
||||
logging.trace(LogVerbosity.DEBUG, TRACER_NAME, text);
|
||||
}
|
||||
|
||||
interface BindResult {
|
||||
port: number;
|
||||
count: number;
|
||||
@ -269,6 +276,7 @@ export class Server {
|
||||
}
|
||||
return Promise.all(
|
||||
addressList.map((address) => {
|
||||
trace('Attempting to bind ' + subchannelAddressToString(address));
|
||||
let addr: SubchannelAddress;
|
||||
if (isTcpSubchannelAddress(address)) {
|
||||
addr = {
|
||||
@ -288,6 +296,7 @@ export class Server {
|
||||
http2Server.once('error', onError);
|
||||
|
||||
http2Server.listen(addr, () => {
|
||||
trace('Successfully bound ' + subchannelAddressToString(address));
|
||||
this.http2ServerList.push(http2Server);
|
||||
const boundAddress = http2Server.address()!;
|
||||
if (typeof boundAddress === 'string') {
|
||||
@ -378,11 +387,11 @@ export class Server {
|
||||
(bindResult) => {
|
||||
if (bindResult.count === 0) {
|
||||
const errorString = `No address added out of total ${addressList.length} resolved`;
|
||||
log(LogVerbosity.ERROR, errorString);
|
||||
logging.log(LogVerbosity.ERROR, errorString);
|
||||
callback(new Error(errorString), 0);
|
||||
} else {
|
||||
if (bindResult.count < addressList.length) {
|
||||
log(
|
||||
logging.log(
|
||||
LogVerbosity.INFO,
|
||||
`WARNING Only ${bindResult.count} addresses added out of total ${addressList.length} resolved`
|
||||
);
|
||||
@ -392,7 +401,7 @@ export class Server {
|
||||
},
|
||||
(error) => {
|
||||
const errorString = `No address added out of total ${addressList.length} resolved`;
|
||||
log(LogVerbosity.ERROR, errorString);
|
||||
logging.log(LogVerbosity.ERROR, errorString);
|
||||
callback(new Error(errorString), 0);
|
||||
}
|
||||
);
|
||||
@ -444,6 +453,7 @@ export class Server {
|
||||
serialize,
|
||||
deserialize,
|
||||
type,
|
||||
path: name,
|
||||
} as UntypedHandler);
|
||||
return true;
|
||||
}
|
||||
@ -528,9 +538,11 @@ export class Server {
|
||||
|
||||
try {
|
||||
const path = headers[http2.constants.HTTP2_HEADER_PATH] as string;
|
||||
trace('Received call to method ' + path + ' at address ' + http2Server.address()?.toString());
|
||||
const handler = this.handlers.get(path);
|
||||
|
||||
if (handler === undefined) {
|
||||
trace('No handler registered for method ' + path + '. Sending UNIMPLEMENTED status.');
|
||||
throw getUnimplementedStatusResponse(path);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user