| 1 | import * as GCP from "@/GCP"; |
| 2 | import { GcpEnvironment } from "@/GCP/Environment"; |
| 3 | import * as Test from "@/Test/Alchemy"; |
| 4 | import * as aiplatform from "@distilled.cloud/gcp/aiplatform_v1"; |
| 5 | import { expect } from "alchemy-test"; |
| 6 | import * as Effect from "effect/Effect"; |
| 7 | import { MinimumLogLevel } from "effect/References"; |
| 8 | import * as Schedule from "effect/Schedule"; |
| 9 | import { UsersSource } from "./fixtures/features.ts"; |
| 10 | |
| 11 | const { test } = Test.make({ providers: GCP.providers() }); |
| 12 | |
| 13 | const logLevel = Effect.provideService( |
| 14 | MinimumLogLevel, |
| 15 | process.env.DEBUG ? "Debug" : "Info", |
| 16 | ); |
| 17 | |
| 18 | // Bigtable-backed store provisioning takes 1-3 minutes. |
| 19 | const runLifecycle = !process.env.FAST; |
| 20 | |
| 21 | const waitUntilGone = (name: string) => |
| 22 | aiplatform.getProjectsLocationsFeatureOnlineStoresFeatureViews({ name }).pipe( |
| 23 | Effect.as("found" as const), |
| 24 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 25 | Effect.repeat({ |
| 26 | schedule: Schedule.spaced("2 seconds"), |
| 27 | until: (status) => status === "gone", |
| 28 | times: 10, |
| 29 | }), |
| 30 | ); |
| 31 | |
| 32 | test.provider( |
| 33 | "getProjectsLocationsFeatureOnlineStoresFeatureViews on a missing view fails with a typed tag", |
| 34 | (stack) => |
| 35 | Effect.gen(function* () { |
| 36 | const { project } = yield* GcpEnvironment.current; |
| 37 | yield* stack.destroy(); |
| 38 | |
| 39 | const error = yield* Effect.flip( |
| 40 | aiplatform.getProjectsLocationsFeatureOnlineStoresFeatureViews({ |
| 41 | name: `projects/${project}/locations/us-central1/featureOnlineStores/alchemy_missing/featureViews/alchemy_missing`, |
| 42 | }), |
| 43 | ); |
| 44 | expect(error._tag).toEqual("NotFound"); |
| 45 | |
| 46 | yield* stack.destroy(); |
| 47 | }).pipe(logLevel), |
| 48 | { |
| 49 | tags: ["provider:gcp", "provider:gcp:aiplatform", "live"], |
| 50 | timeout: 90_000, |
| 51 | }, |
| 52 | ); |
| 53 | |
| 54 | test.provider.skipIf(!runLifecycle)( |
| 55 | "create, update, and delete a feature online store feature view", |
| 56 | (stack) => |
| 57 | Effect.gen(function* () { |
| 58 | yield* stack.destroy(); |
| 59 | |
| 60 | const created = yield* stack.deploy( |
| 61 | Effect.gen(function* () { |
| 62 | const store = yield* GCP.AIPlatform.FeatureOnlineStore("Serving", { |
| 63 | location: "us-central1", |
| 64 | labels: { env: "test" }, |
| 65 | }); |
| 66 | const inputUri = yield* UsersSource; |
| 67 | const group = yield* GCP.AIPlatform.FeatureGroup("UserFeatures", { |
| 68 | location: "us-central1", |
| 69 | bigQuery: { inputUri, entityIdColumns: ["entity_id"] }, |
| 70 | }); |
| 71 | const feature = yield* GCP.AIPlatform.FeatureGroupsFeature("Age", { |
| 72 | featureGroup: group.name, |
| 73 | location: "us-central1", |
| 74 | versionColumnName: "age", |
| 75 | }); |
| 76 | const view = yield* GCP.AIPlatform.FeatureOnlineStoresFeatureView( |
| 77 | "Users", |
| 78 | { |
| 79 | featureOnlineStore: store.name, |
| 80 | location: "us-central1", |
| 81 | labels: { env: "test" }, |
| 82 | featureRegistrySource: { |
| 83 | featureGroups: [ |
| 84 | { |
| 85 | featureGroupId: group.featureGroupId, |
| 86 | featureIds: [feature.featureId], |
| 87 | }, |
| 88 | ], |
| 89 | }, |
| 90 | syncConfig: { cron: "0 * * * *" }, |
| 91 | }, |
| 92 | ); |
| 93 | return { store, view }; |
| 94 | }), |
| 95 | ); |
| 96 | |
| 97 | expect(created.view.name).toContain("/featureViews/"); |
| 98 | expect(created.view.featureOnlineStore).toEqual(created.store.name); |
| 99 | expect(created.view.labels).toMatchObject({ env: "test" }); |
| 100 | |
| 101 | const fetched = |
| 102 | yield* aiplatform.getProjectsLocationsFeatureOnlineStoresFeatureViews({ |
| 103 | name: created.view.name, |
| 104 | }); |
| 105 | expect(fetched.name).toEqual(created.view.name); |
| 106 | |
| 107 | const updated = yield* stack.deploy( |
| 108 | Effect.gen(function* () { |
| 109 | const store = yield* GCP.AIPlatform.FeatureOnlineStore("Serving", { |
| 110 | featureOnlineStoreId: created.store.featureOnlineStoreId, |
| 111 | location: "us-central1", |
| 112 | labels: { env: "test" }, |
| 113 | }); |
| 114 | const inputUri = yield* UsersSource; |
| 115 | const group = yield* GCP.AIPlatform.FeatureGroup("UserFeatures", { |
| 116 | location: "us-central1", |
| 117 | bigQuery: { inputUri, entityIdColumns: ["entity_id"] }, |
| 118 | }); |
| 119 | const feature = yield* GCP.AIPlatform.FeatureGroupsFeature("Age", { |
| 120 | featureGroup: group.name, |
| 121 | location: "us-central1", |
| 122 | versionColumnName: "age", |
| 123 | }); |
| 124 | const view = yield* GCP.AIPlatform.FeatureOnlineStoresFeatureView( |
| 125 | "Users", |
| 126 | { |
| 127 | featureOnlineStore: store.name, |
| 128 | featureViewId: created.view.featureViewId, |
| 129 | location: "us-central1", |
| 130 | labels: { env: "prod" }, |
| 131 | featureRegistrySource: { |
| 132 | featureGroups: [ |
| 133 | { |
| 134 | featureGroupId: group.featureGroupId, |
| 135 | featureIds: [feature.featureId], |
| 136 | }, |
| 137 | ], |
| 138 | }, |
| 139 | syncConfig: { cron: "0 * * * *" }, |
| 140 | }, |
| 141 | ); |
| 142 | return { store, view }; |
| 143 | }), |
| 144 | ); |
| 145 | |
| 146 | expect(updated.view.name).toEqual(created.view.name); |
| 147 | expect(updated.view.labels).toMatchObject({ env: "prod" }); |
| 148 | |
| 149 | yield* stack.destroy(); |
| 150 | const gone = yield* waitUntilGone(created.view.name); |
| 151 | expect(gone).toEqual("gone"); |
| 152 | }).pipe(logLevel), |
| 153 | { |
| 154 | tags: ["provider:gcp", "provider:gcp:aiplatform", "live"], |
| 155 | timeout: 600_000, |
| 156 | }, |
| 157 | ); |