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

simplify API and allow running via docker-compose and GKE #46

Merged
merged 5 commits into from
Nov 9, 2019

Conversation

youngj
Copy link
Contributor

@youngj youngj commented Oct 27, 2019

This PR simplifies tryn-api so that it only returns vehicle state from S3 and no longer returns route configuration, so that it doesn't need code to handle different transit data providers.

Since this is a change that would break existing clients, the PR includes several other schema changes at the same time:

  • root query trynState field renamed to state, pointReliabilities parameter removed
  • all timestamps are in now seconds instead of milliseconds
  • endTime parameter was inclusive, now is exclusive
  • in RouteState type, vtime field renamed to timestamp
  • Route type renamed to RouteHistory, rid field renamed to routeId, routeStates renamed to states
  • Vehicle type renamed to VehicleState, and added tripId, stopIndex, and status fields to provide data collected from GTFS-realtime providers
  • TrynState type renamed to AgencyState, id and pointReliabilities fields removed

It also no longer needs config files or the Restbus API.

To avoid breaking existing clients, this should be deployed to new URL while the existing service continues running the old code at the old URL. Then clients should be updated to use the new API at the new URL, and once everyone is using the new API the old service can be shut down.

This also fixes an issue with agency names containing dashes, and avoids returning data outside the requested time range that is within the same minute as the start time or end time.

It also now uses the same approach as metrics-mvp and orion for running with docker-compose in development and GKE in production, with a cloudbuild.yaml script that can be configured with Google Cloud Build to automatically deploy to production when new code is merged into the master branch.

…and point reliabilities; use seconds instead of milliseconds; add new vehicle fields for gtfs-realtime providers; rename some fields and type names; remove unused code
Copy link
Member

@EddyIonescu EddyIonescu left a comment

Choose a reason for hiding this comment

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

Thanks so much for cleaning this up, for resolving some issues it had, and for the great documentation! I'll delete the wiki-page and have the API link on the homepage direct to the readme here instead. See my comments before merging.

src/resolvers.js Outdated
const { agency, routes } = params;

let { startTime, endTime, pointReliabilities } = params;
let { startTime, endTime } = params;

// times are returned as strings because GraphQL numbers are only 32-bit
// https://github.com/graphql/graphql-js/issues/292
Copy link
Member

Choose a reason for hiding this comment

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

Since it's being changed to seconds epoch, could timestamp, startTime, and endTime be Int instead? I only used String as a workaround for the timestamp being in milliseconds as JavaScript's Date library uses milliseconds epoch (and the codebase was all in js too).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I kept timestamps as String to avoid the Year 2038 problem, since GraphQL would throw an error if a timestamp is greater than or equal to 2147483648 (Tuesday, January 19, 2038 3:14:08 AM GMT), in case this code stays around for another 18 years and GraphQL still only allows 32 bit signed ints, although I don't feel strongly about this if you'd still prefer to use Int.

Copy link
Member

Choose a reason for hiding this comment

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

It still seems less worse than using strings for timestamps in seconds, and would avoid the need for casting it to Int (for metrics-mvp and possibly other users) so that's why I prefer it.

It looks like the best solution is to make a scalar (https://www.apollographql.com/docs/graphql-tools/scalars/) for either Long or an Epoch type - but it's definitely not worth doing now.

Also adding a scalar wouldn't break metrics-mvp as python ints are 24-bit, so it could always be done in the future. And Int would use less space than strings when making API calls but that's probably negligible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the information about scalars - I just implemented it and it seems to work well.

src/resolvers.js Outdated Show resolved Hide resolved
}
});
});
})));
}

function getTimestamp(key) {
var keyParts = key.split('-');
return Math.floor(Number(keyParts[keyParts.length - 1].split('.json')[0])/1000);
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for fixing this!

src/helpers/s3Helper.js Outdated Show resolved Hide resolved
if (timestamp >= startEpoch && timestamp < endEpoch && !timestampsMap[timestamp]) {
timestampsMap[timestamp] = true;
res.push(key);
}
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for fixing this as well!

@youngj
Copy link
Contributor Author

youngj commented Nov 9, 2019

I also changed the agency parameter and field name to agencyId to match the name I'm using in metrics-mvp's other GraphQL API for route config and metrics (in a branch I'm currently working on at https://github.com/trynmaps/metrics-mvp/tree/youngj-agencies)

Copy link
Member

@EddyIonescu EddyIonescu left a comment

Choose a reason for hiding this comment

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

Thanks for adding bigint - it's less complex/more cleaner than I thought it'd be so thanks for looking into that. Also, renaming to agencyId makes sense, especially given the changes in metrics-mvp (Can't wait to see other agencies being supported there!). Everything else looks good to me.

README.md Outdated Show resolved Hide resolved
@youngj youngj merged commit b60de6a into master Nov 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants