import {z} from 'zod' export type GetApiV1b3ProjectsProjectIdJobsJobIdMetricsArgs = {projectId: string, jobId: string, location?: string | undefined, startTime?: unknown | undefined}; export type GetApiV1b3ProjectsProjectIdJobsJobIdMetricsOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; export const metricStructuredName = z.object({context: z.record(z.string(), z.string()).optional(), name: z.string().optional(), origin: z.string().optional()}); export const metricUpdate = z.object({boundedTrie: z.unknown(), cumulative: z.boolean().optional(), distribution: z.unknown(), gauge: z.unknown(), internal: z.unknown(), kind: z.string().optional(), meanCount: z.unknown(), meanSum: z.unknown(), name: metricStructuredName.optional(), scalar: z.unknown(), set: z.unknown(), trie: z.unknown(), updateTime: z.string().optional()}); export const jobMetrics = z.object({metricTime: z.string().optional(), metrics: z.array(metricUpdate).optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Request the job status. To request the status of a job, we recommend using `projects.locations.jobs.getMetrics` with a [regional endpoint] (https://cloud.google.com/dataflow/docs/concepts/regional-endpoints). Using `projects.jobs.getMetrics` is not recommended, as you can only request the status of jobs that are running in `us-central1`. # IAM Permissions Requires the `dataflow.metrics.get` permission on the job. * * GET /v1b3/projects/{projectId}/jobs/{jobId}/metrics * * Also accepts auth: Oauth2 + Oauth2c */ export const getApiV1b3ProjectsProjectIdJobsJobIdMetrics = async (args: GetApiV1b3ProjectsProjectIdJobsJobIdMetricsArgs, options?: GetApiV1b3ProjectsProjectIdJobsJobIdMetricsOptions) => { const {baseUrl = "https://dataflow.googleapis.com", fetch: fetchFn = fetch, Oauth2, Oauth2c} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.location != null) query.append("location", String(args.location)) if (args.startTime != null) query.append("startTime", String(args.startTime)) if (Oauth2 !== undefined) headers.set('authorization', `Bearer ${Oauth2}`) if (Oauth2c !== undefined) headers.set('authorization', `Bearer ${Oauth2c}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1b3/projects/${encodeURIComponent(String(args.projectId))}/jobs/${encodeURIComponent(String(args.jobId))}/metrics${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(jobMetrics, await res.json()) };