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

refactor: add web framework plugin types and script to fetch types #621

Merged
merged 5 commits into from
Jan 23, 2018

Conversation

kjin
Copy link
Contributor

@kjin kjin commented Dec 5, 2017

Fixes #620

This change adds TypeScript types for all web framework tracing plugins and subjects them to gts, In addition, it introduces an npm verb to download type definitions separately into a directory distinct from node_modules. The purpose of this is to depend on several versions of type definitions, something that isn't supported by npm. Currently, this doesn't apply to any type definitions (Koa 1 and 2 have different types, but @types/koa@1 doesn't exist, and the minimal type definitions for koa 1 can share types with koa 2).

I'm considering avoiding this entirely (it adds a considerable amount of complexity to the codebase), and having the Trace Agent simply depend on one version of each module instead. So far this is feasible, but it might not be in the long term. I would like to get thoughts on this.

This change also fixes a bug where framework-specific routing trace labels aren't generated because the Trace Agent expects them on the wrong property. This is apparent in koa (#620) and connect (because AFAIK connect's route path is the original URL).

Update: Changed this so that plugin types are simply installed under devDependencies. There is no script to fetch types anymore. I might add that later, thinking of crossing that bridge when the times comes (currently, besides Koa 1 which has no @types module anyway, there are no modules whose interfaces change dramatically between versions)

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Dec 5, 2017
@kjin kjin force-pushed the plugin-types branch 4 times, most recently from f10d0a5 to 1335a4f Compare December 5, 2017 01:23
@kjin kjin force-pushed the plugin-types branch 3 times, most recently from d5f73f7 to 7f25b90 Compare December 5, 2017 22:11
@codecov
Copy link

codecov bot commented Jan 19, 2018

Codecov Report

Merging #621 into master will decrease coverage by 0.41%.
The diff coverage is 90.69%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #621      +/-   ##
==========================================
- Coverage      91%   90.59%   -0.42%     
==========================================
  Files          30       30              
  Lines        1390     1403      +13     
  Branches      275      288      +13     
==========================================
+ Hits         1265     1271       +6     
- Misses         53       54       +1     
- Partials       72       78       +6
Impacted Files Coverage Δ
src/plugins/plugin-express.ts 100% <100%> (ø) ⬆️
src/plugins/plugin-restify.ts 96.96% <100%> (ø) ⬆️
src/plugins/plugin-koa.ts 87.93% <86.11%> (-4.67%) ⬇️
src/plugins/plugin-hapi.ts 91.3% <87.09%> (-3.94%) ⬇️
src/plugins/plugin-connect.ts 91.66% <87.5%> (-2.09%) ⬇️
src/trace-writer.ts 85.27% <0%> (-0.78%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a212d70...1393994. Read the comment docs.

@kjin
Copy link
Contributor Author

kjin commented Jan 19, 2018

CI failures are due to flakes. In anticipation of pending reviews I'm not restarting them right now

Copy link
Contributor

@jinwoo jinwoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly nits

scripts/index.ts Outdated
@@ -2,6 +2,7 @@ const [bin, script, ...steps] = process.argv;

import { checkInstall } from './check-install';
import { encryptCredentials, decryptCredentials } from './credentials';
import { getPluginTypes } from './get-plugin-types';

This comment was marked as spam.

This comment was marked as spam.


const SUPPORTED_VERSIONS = '3.x';

function getFirstHeader(req: IncomingMessage, key: string) {

This comment was marked as spam.

This comment was marked as spam.

@@ -42,8 +66,8 @@ function createMiddleware(api) {
api.wrapEmitter(req);
api.wrapEmitter(res);

var url = (req.headers['X-Forwarded-Proto'] || 'http') +
'://' + req.headers.host + req.originalUrl;
const url = (req.headers['X-Forwarded-Proto'] || 'http') + '://' +

This comment was marked as spam.

This comment was marked as spam.

@@ -55,16 +58,16 @@ function patchModuleRoot(express, api) {
api.wrapEmitter(req);
api.wrapEmitter(res);

var url = req.protocol + '://' + req.hostname + req.originalUrl;
const url = req.protocol + '://' + req.hostname + req.originalUrl;

This comment was marked as spam.

This comment was marked as spam.


const SUPPORTED_VERSIONS = '8 - 16';

function getFirstHeader(req: IncomingMessage, key: string) {

This comment was marked as spam.

This comment was marked as spam.

var url = (req.headers['X-Forwarded-Proto'] || 'http') +
'://' + req.headers.host + req.url;

const url = (req.headers['X-Forwarded-Proto'] || 'http') + '://' +

This comment was marked as spam.

This comment was marked as spam.

interface KoaModule<T> {
// TypeScript isn't expressive enough, but KoaModule#use should return `this`.
// tslint:disable-next-line:no-any
readonly prototype: {use: (m: T) => any};

This comment was marked as spam.

This comment was marked as spam.

// propagateContext flag. The type of "next" differs between Koa 1 and 2.
type GetNextFn<T> = (propagateContext: boolean) => T;

function getFirstHeader(req: IncomingMessage, key: string) {

This comment was marked as spam.

This comment was marked as spam.

}

api.wrapEmitter(req);
api.wrapEmitter(res);

const url = (req.headers['X-Forwarded-Proto'] || 'http') +
'://' + req.headers.host + req.url;
const url = (req.headers['X-Forwarded-Proto'] || 'http') + '://' +

This comment was marked as spam.

This comment was marked as spam.


function createMiddleware(api: PluginTypes.TraceAgent): koa_1.Middleware {
// Koa 1 type definitions use any here.
// tslint:disable-next-line:no-any

This comment was marked as spam.

This comment was marked as spam.

@kjin kjin force-pushed the plugin-types branch 2 times, most recently from f98e5c8 to 544bbb7 Compare January 19, 2018 22:13
@kjin
Copy link
Contributor Author

kjin commented Jan 20, 2018

New changes are in 1393994 only

@kjin
Copy link
Contributor Author

kjin commented Jan 23, 2018

Ignoring codecov for now... will be fixed in follow-up PR.

@kjin kjin merged commit 54dd734 into googleapis:master Jan 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Koa route path labels are likely never applied
3 participants