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

fix: tunnels query retry in up #145

Merged
merged 1 commit into from
Jul 26, 2023
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
7 changes: 7 additions & 0 deletions packages/cli/src/commands/up.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
telemetryEmitter,
} from '@preevy/core'
import { tunnelServerFlags } from '@preevy/cli-common'
import { inspect } from 'util'
import { tunnelServerHello } from '../tunnel-server-client'
import MachineCreationDriverCommand from '../machine-creation-driver-command'
import { envIdFlags, urlFlags } from '../common-flags'
Expand Down Expand Up @@ -90,6 +91,12 @@ export default class Up extends MachineCreationDriverCommand<typeof Up> {
envId,
tunnelingKey,
includeAccessCredentials: flags['include-access-credentials'],
retryOpts: {
minTimeout: 1000,
maxTimeout: 2000,
retries: 10,
onFailedAttempt: e => { this.logger.debug(`Failed to query tunnels: ${inspect(e)}`) },
},
})

const urls = await filterUrls({
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/commands/urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export default class Urls extends ProfileCommand<typeof Urls> {
serviceAndPort: args.service ? { service: args.service, port: args.port } : undefined,
tunnelingKey,
includeAccessCredentials: flags['include-access-credentials'],
retryOpts: { retries: 2 },
})

const urls = await filterUrls({
Expand Down
14 changes: 12 additions & 2 deletions packages/core/src/commands/urls.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
import retry from 'p-retry'
import { generateBasicAuthCredentials, jwtGenerator } from '../credentials'
import { queryTunnels } from '../compose-tunnel-agent-client'
import { flattenTunnels, tunnelUrlsForEnv } from '../tunneling'

export const urls = async ({ envId, rootUrl, clientId, serviceAndPort, tunnelingKey, includeAccessCredentials }: {
export const urls = async ({
envId,
rootUrl,
clientId,
serviceAndPort,
tunnelingKey,
includeAccessCredentials,
retryOpts,
}: {
envId: string
rootUrl: string
clientId: string
serviceAndPort?: { service: string; port?: number }
tunnelingKey: string | Buffer
includeAccessCredentials: boolean
retryOpts: retry.Options
}) => {
const tunnelUrlsForService = tunnelUrlsForEnv({ envId, rootUrl: new URL(rootUrl), clientId })

const credentials = await generateBasicAuthCredentials(jwtGenerator(tunnelingKey))

const { tunnels } = await queryTunnels({
tunnelUrlsForService,
retryOpts: { retries: 2 },
retryOpts,
credentials,
includeAccessCredentials,
})
Expand Down
Loading