import {z} from 'zod' export type GetApiApiV1DataMetricsMetadataMetricNameArgs = {metric_name: string}; export type GetApiApiV1DataMetricsMetadataMetricNameOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const datav1Source = z.enum(["PROMETHEUS", "STATSD", "OPEN_METRICS", "CARBON", "OPEN_TELEMETRY", "SIGNALFX", "WAVEFRONT", "DOGSTATSD", "CHRONO_GCP", "CLOUDWATCH_METRIC_STREAM", "CHRONO_AZURE", "TAGGED_STATSD", "CHRONO_CLOUDFLARE", "CHRONO_INTEGRATION"]); export const datav1MetricType = z.enum(["CUMULATIVE_COUNTER", "GAUGE", "DELTA_COUNTER", "MEASUREMENT", "CUMULATIVE_EXPONENTIAL_HISTOGRAM", "DELTA_EXPONENTIAL_HISTOGRAM"]); export const datav1MetricMetadata = z.object({description: z.string().optional(), name: z.string().optional(), source: datav1Source.optional(), type: datav1MetricType.optional()}); export const datav1ReadMetricMetadataResponse = z.object({metadata: datav1MetricMetadata.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 }; /** * Metric Metadata * * GET /api/v1/data/metrics:metadata/{metric_name} */ export const getApiApiV1DataMetricsMetadataMetricName = async (args: GetApiApiV1DataMetricsMetadataMetricNameArgs, options?: GetApiApiV1DataMetricsMetadataMetricNameOptions) => { const {baseUrl = "https://tenant.chronosphere.io", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("API-Token", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/data/metrics:metadata/${encodeURIComponent(String(args.metric_name))}${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(datav1ReadMetricMetadataResponse, await res.json()) };