監控

在 Vertex AI 特徵儲存庫 (舊版) 中,您可以監控特徵儲存庫和特徵,並設定相關快訊。舉例來說,營運團隊可能會監控特徵商店,追蹤 CPU 使用率。特徵擁有者 (例如資料科學家) 可能會監控特徵值,以偵測一段時間內的偏移情形。

以下各節說明監控特徵商店和特徵的方法:

Featurestore 監控

Vertex AI 特徵儲存庫 (舊版) 會向 Cloud Monitoring 報告特徵儲存庫的指標,例如 CPU 負載、儲存空間容量、要求延遲和帳單。Vertex AI 會為您收集及回報這些指標。您不需要設定或啟用 Feature Store 監控功能。

如要設定門檻和通知,請使用 Cloud Monitoring。舉例來說,如果平均 CPU 負載超過 70%,您就可以設定快訊,這可能表示您需要增加特徵商店節點數量。

您也可以在 Google Cloud 控制台的 Vertex AI 專區中查看特徵儲存庫指標,瞭解一段時間內的趨勢。對於部分圖表,控制台會顯示匯總或計算值,方便您解讀資訊。您隨時可以在 Cloud Monitoring 中查看原始資料。

詳情請參閱 Vertex AI Cloud Monitoring 頁面上的「Vertex AI 特徵儲存庫 (舊版) 監控指標」。

監控在 Feature Store 中處理離線資料的帳單

使用 Google Cloud 控制台監控 featurestores.batchReadFeatureValuesentityTypes.exportFeatureValues 方法離線處理的可計費資料。您可以查看每個特徵商店的可計費位元組。

您可以在指標探索器中,監控 Vertex AI 特徵儲存庫 (舊版) 的「可計費位元組」指標。

控制台

  1. 前往 Google Cloud 控制台的「Metrics Explorer」

    前往 Metrics Explorer

  2. 在「指標」清單中,依序選取「Vertex AI Feature Store」 >「Featurestore」 >「可計費位元組」

  3. 按一下 [套用]。圖表會顯示專案中 Feature Store 的離線可計費資料。

    生成圖表後,即可將其新增至自訂資訊主頁。詳情請參閱「儲存圖表以供日後參考」。

特徵值監控

特徵值監控功能可追蹤特徵值在特徵商店中的分布變化。支援的特徵值監控類型如下:

  • 快照分析:Vertex AI 特徵儲存庫 (舊版) 會定期擷取特徵值快照。隨著時間推移,當您擷取更多資料時,可能會發現特徵值的分布情形有所變化。這項異動表示,使用這些功能的模型可能需要重新訓練。您可以指定門檻,當分布偏差超過門檻時,系統就會在 Cloud Logging 控制台中記錄異常狀況。

    如果資料集超過 500 萬個實體 ID,Vertex AI 特徵儲存庫 (舊版) 會根據您指定為延遲天數的時間範圍內,隨機選取的 500 萬個實體 ID 產生快照。

  • 匯入特徵分析:每項 ImportFeatureValues 作業都會產生匯入 Vertex AI 特徵儲存庫 (舊版) 的值分配統計資料。您可以選擇比較分配統計資料與先前匯入的特徵值分配情形,或 (如已啟用) 快照分配情形,藉此偵測異常狀況。

    如果資料集超過 500 萬個例項,Vertex AI 特徵儲存庫 (舊版) 會根據隨機選取的資料產生快照,如下所示:

    • 如果擷取的資料集內例項數量超過 500 萬個,但未超過 5, 000 萬個,系統會根據隨機選取的 500 萬個例項產生快照。
    • 如果擷取的資料集內執行個體的數量超過 5 千萬個,系統會隨機選取 10% 的執行個體來產生快照。

舉例來說,假設某項特徵會收集最近售出房屋的價格,然後將這些值提供給模型,用於預測房價。近期售出房屋的價格可能會隨著時間大幅變動,或者匯入的值批次可能包含與訓練資料顯著不同的資料。Vertex AI 特徵儲存庫 (舊版) 會提醒您這項異動。然後重新訓練模型,使用最新資訊。

設定監控設定

如要開始監控,您可以為實體類型定義監控設定,啟用下列類型所有特徵的監控功能:

  • BOOL
  • STRING
  • DOUBLE
  • INT64

建立實體類型時,您可以設定監控設定。您也可以設定 disableMonitoring 屬性,選擇停用特定功能的監控功能。實體類型監控設定會指定下列項目:

  • 是否啟用監控功能。監控功能預設為停用。
  • 用於偵測異常狀況的門檻。預設門檻為 0.3。
  • 回溯期,以及快照之間的時間間隔 (適用於快照分析)。預設值為 21。
  • 是否啟用匯入特徵分析。預設為停用。

詳情請參閱 API 參考資料中的 FeaturestoreMonitoringConfig 型別。

建立啟用監控功能的實體類型

以下範例會建立實體類型,並啟用特徵監控:

網路使用者介面

使用者介面僅支援快照分析

  1. 在 Google Cloud 控制台的 Vertex AI 專區,前往「Features」頁面。

    前往「Features」(功能) 頁面

  2. 從「Region」(區域) 下拉式清單中選取一個區域。
  3. 按一下「建立實體類型」
  4. 將「特徵監控」部分切換為「已啟用」
  5. 在「監控時間間隔」欄位中,輸入快照之間的天數。
    啟用實體類型或特徵的監控功能後,系統會在最接近的整點執行實體類型或特徵的監控工作。舉例來說,如果您在週一晚上 10:30 啟用監控功能,並指定兩天為監控時間間隔,則第一項監控工作會在週三晚上 11 點執行。
  6. 在「監控回溯期」欄位中,輸入每個快照的回溯天數。
  7. 在「數值警告門檻」欄位中,輸入用於偵測數值特徵異常狀況的門檻值。
  8. 在「類別警告門檻」欄位中,輸入用於偵測這個 EntityType 中類別特徵異常情況的門檻值。
    如要進一步瞭解如何偵測特徵值異常情況,請參閱「查看特徵值異常情況」。
  9. 點選「建立」
  10. 在特徵表格中,按一下實體類型。
  11. 如要為實體新增功能,請按一下「新增功能」
  12. 如要停用特定功能的監控功能,請將「啟用監控」切換為關閉。

REST

如要建立實體型別,請使用 entityTypes.create 方法傳送 POST 要求。

使用任何要求資料之前,請先替換以下項目:

  • LOCATION_ID:特徵儲存庫所在的區域,例如 us-central1
  • PROJECT_ID:您的專案 ID
  • FEATURESTORE_ID:特徵商店的 ID。
  • ENTITY_TYPE_ID:實體類型 ID。
  • DURATION:快照之間的時間間隔,以天為單位。
  • STALENESS_DAYS:拍攝快照時要回溯的天數。
  • NUMERICAL_THRESHOLD_VALUE:偵測此實體類型下數值特徵異常狀況的門檻。系統會使用 Jenson-Shannon 散度計算統計資料偏差。
  • CATEGORICAL_THRESHOLD_VALUE:偵測這個實體類型下類別特徵異常狀況的門檻。統計資料偏差是透過 L-Infinity 距離計算。
  • IMPORT_FEATURE_ANALYSIS_STATE:指出是否啟用匯入功能分析的狀態。
  • IMPORT_FEATURE_ANALYSIS_BASELINE:啟用後,匯入功能分析的基準。

HTTP 方法和網址:

POST https://LOCATION_ID-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION_ID/featurestores/FEATURESTORE_ID/entityTypes?entityTypeId=ENTITY_TYPE_ID

JSON 要求主體:

{
  "monitoringConfig": {
    "snapshotAnalysis": {
      "monitoringIntervalDays": "DURATION"
      "stalenessDays": "STALENESS_DAYS"
    }
  },
 "numericalThresholdConfig": {
    "value": "NUMERICAL_THRESHOLD_VALUE"
  },
  "categoricalThresholdConfig": {
    "value": "CATEGORICAL_THRESHOLD_VALUE"
  },
  "importFeatureAnalysis": {
    "state": "IMPORT_FEATURE_ANALYSIS_STATE",
    "anomalyDetectionBaseline": "IMPORT_FEATURE_ANALYSIS_BASELINE"
  }
}

如要傳送要求,請選擇以下其中一個選項:

curl

將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://LOCATION_ID-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION_ID/featurestores/FEATURESTORE_ID/entityTypes?entityTypeId=ENTITY_TYPE_ID"

PowerShell

將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://LOCATION_ID-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION_ID/featurestores/FEATURESTORE_ID/entityTypes?entityTypeId=ENTITY_TYPE_ID" | Select-Object -Expand Content

畫面會顯示類似以下的輸出。您可以使用回應中的 OPERATION_ID 取得作業狀態

{
  "name": "projects/PROJECT_ID/locations/LOCATION_ID/operations/OPERATION_ID",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.aiplatform.ui.CreateEntityTypeOperationMetadata",
    "genericMetadata": {
      "createTime": "2022-04-29T20:29:05.206525Z",
      "updateTime": "2022-04-29T20:29:05.206525Z"
    }
  }
}

Java

在試用這個範例之前,請先按照Java使用用戶端程式庫的 Vertex AI 快速入門中的操作說明進行設定。 詳情請參閱 Vertex AI Java API 參考說明文件

如要向 Vertex AI 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。


import com.google.api.gax.longrunning.OperationFuture;
import com.google.cloud.aiplatform.v1.CreateEntityTypeOperationMetadata;
import com.google.cloud.aiplatform.v1.CreateEntityTypeRequest;
import com.google.cloud.aiplatform.v1.EntityType;
import com.google.cloud.aiplatform.v1.FeaturestoreMonitoringConfig;
import com.google.cloud.aiplatform.v1.FeaturestoreMonitoringConfig.SnapshotAnalysis;
import com.google.cloud.aiplatform.v1.FeaturestoreName;
import com.google.cloud.aiplatform.v1.FeaturestoreServiceClient;
import com.google.cloud.aiplatform.v1.FeaturestoreServiceSettings;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class CreateEntityTypeMonitoringSample {

  public static void main(String[] args)
      throws IOException, InterruptedException, ExecutionException, TimeoutException {
    // TODO(developer): Replace these variables before running the sample.
    String project = "YOUR_PROJECT_ID";
    String featurestoreId = "YOUR_FEATURESTORE_ID";
    String entityTypeId = "YOUR_ENTITY_TYPE_ID";
    String description = "YOUR_ENTITY_TYPE_DESCRIPTION";
    int monitoringIntervalDays = 1;
    String location = "us-central1";
    String endpoint = "us-central1-aiplatform.googleapis.com:443";
    int timeout = 300;
    createEntityTypeMonitoringSample(
        project,
        featurestoreId,
        entityTypeId,
        description,
        monitoringIntervalDays,
        location,
        endpoint,
        timeout);
  }

  static void createEntityTypeMonitoringSample(
      String project,
      String featurestoreId,
      String entityTypeId,
      String description,
      int monitoringIntervalDays,
      String location,
      String endpoint,
      int timeout)
      throws IOException, InterruptedException, ExecutionException, TimeoutException {

    FeaturestoreServiceSettings featurestoreServiceSettings =
        FeaturestoreServiceSettings.newBuilder().setEndpoint(endpoint).build();

    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (FeaturestoreServiceClient featurestoreServiceClient =
        FeaturestoreServiceClient.create(featurestoreServiceSettings)) {

      FeaturestoreMonitoringConfig featurestoreMonitoringConfig =
          FeaturestoreMonitoringConfig.newBuilder()
              .setSnapshotAnalysis(
                  SnapshotAnalysis.newBuilder().setMonitoringIntervalDays(monitoringIntervalDays))
              .build();

      EntityType entityType =
          EntityType.newBuilder()
              .setDescription(description)
              .setMonitoringConfig(featurestoreMonitoringConfig)
              .build();

      CreateEntityTypeRequest createEntityTypeRequest =
          CreateEntityTypeRequest.newBuilder()
              .setParent(FeaturestoreName.of(project, location, featurestoreId).toString())
              .setEntityType(entityType)
              .setEntityTypeId(entityTypeId)
              .build();

      OperationFuture<EntityType, CreateEntityTypeOperationMetadata> entityTypeFuture =
          featurestoreServiceClient.createEntityTypeAsync(createEntityTypeRequest);
      System.out.format(
          "Operation name: %s%n", entityTypeFuture.getInitialFuture().get().getName());
      System.out.println("Waiting for operation to finish...");
      EntityType entityTypeResponse = entityTypeFuture.get(timeout, TimeUnit.SECONDS);
      System.out.println("Create Entity Type Monitoring Response");
      System.out.format("Name: %s%n", entityTypeResponse.getName());
    }
  }
}

Node.js

在試用這個範例之前,請先按照Node.js使用用戶端程式庫的 Vertex AI 快速入門中的操作說明進行設定。 詳情請參閱 Vertex AI Node.js API 參考說明文件

如要向 Vertex AI 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。

/**
 * TODO(developer): Uncomment these variables before running the sample.\
 * (Not necessary if passing values as arguments)
 */

// const project = 'YOUR_PROJECT_ID';
// const featurestoreId = 'YOUR_FEATURESTORE_ID';
// const entityTypeId = 'YOUR_ENTITY_TYPE_ID';
// const description = 'YOUR_ENTITY_TYPE_DESCRIPTION';
// const duration = <MONITORING_INTERVAL_IN_SECONDS>;
// const location = 'YOUR_PROJECT_LOCATION';
// const apiEndpoint = 'YOUR_API_ENDPOINT';
// const timeout = <TIMEOUT_IN_MILLI_SECONDS>;

// Imports the Google Cloud Featurestore Service Client library
const {FeaturestoreServiceClient} =
  require('@google-cloud/aiplatform').v1beta1;

// Specifies the location of the api endpoint
const clientOptions = {
  apiEndpoint: apiEndpoint,
};

// Instantiates a client
const featurestoreServiceClient = new FeaturestoreServiceClient(
  clientOptions
);

async function createEntityTypeMonitoring() {
  // Configure the parent resource
  const parent = `projects/${project}/locations/${location}/featurestores/${featurestoreId}`;

  const entityType = {
    description: description,
    monitoringConfig: {
      snapshotAnalysis: {
        monitoringInterval: {
          seconds: Number(duration),
        },
      },
    },
  };

  const request = {
    parent: parent,
    entityTypeId: entityTypeId,
    entityType: entityType,
  };

  // Create EntityType request
  const [operation] = await featurestoreServiceClient.createEntityType(
    request,
    {timeout: Number(timeout)}
  );
  const [response] = await operation.promise();

  console.log('Create entity type monitoring response');
  console.log(`Name : ${response.name}`);
  console.log('Raw response:');
  console.log(JSON.stringify(response, null, 2));
}
createEntityTypeMonitoring();

其他語言

如要瞭解如何安裝及使用 Python 適用的 Vertex AI SDK,請參閱「使用 Python 適用的 Vertex AI SDK」。詳情請參閱 Vertex AI SDK for Python API 參考說明文件

選擇不監控新功能

以下範例會建立新功能,並關閉監控功能:

REST

如要建立功能,請使用 features.create 方法傳送 POST 要求。

使用任何要求資料之前,請先替換以下項目:

  • LOCATION_ID:特徵儲存庫所在的區域,例如 us-central1
  • PROJECT_ID:您的專案 ID
  • FEATURESTORE_ID:特徵商店的 ID。
  • ENTITY_TYPE_ID:實體類型 ID。
  • FEATURE_ID:功能的 ID。
  • VALUE_TYPE:特徵的值類型。
  • DISABLE_MONITORING:設為 true 可明確選擇不接受監控。

HTTP 方法和網址:

POST https://LOCATION_ID-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION_ID/featurestores/FEATURESTORE_ID/entityTypes/ENTITY_TYPE_ID?featureId=/FEATURE_ID

JSON 要求主體:

{
  "disableMonitoring": "DISABLE_MONITORING",
  "valueType": "VALUE_TYPE"
}

如要傳送要求,請選擇以下其中一個選項:

curl

將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://LOCATION_ID-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION_ID/featurestores/FEATURESTORE_ID/entityTypes/ENTITY_TYPE_ID?featureId=/FEATURE_ID"

PowerShell

將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://LOCATION_ID-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION_ID/featurestores/FEATURESTORE_ID/entityTypes/ENTITY_TYPE_ID?featureId=/FEATURE_ID" | Select-Object -Expand Content

畫面會顯示類似以下的輸出。您可以使用回應中的 OPERATION_ID 取得作業狀態

{
  "name": "projects/PROJECT_ID/locations/LOCATION_ID/operations/OPERATION_ID",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.aiplatform.ui.CreateFeatureOperationMetadata",
    "genericMetadata": {
      "createTime": "2022-04-29T20:29:05.206525Z",
      "updateTime": "2022-04-29T20:29:05.206525Z"
    }
  }
}

更新監控設定

更新實體類型時,您可以設定監控設定。您也可以設定 disableMonitoring 屬性,選擇停用特定功能的監控功能。

更新實體類型和特徵的監控設定

以下範例會更新現有實體類型的監控設定,以及該實體類型的特定特徵:

網路使用者介面

使用者介面僅支援快照分析

  1. 在 Google Cloud 控制台的 Vertex AI 專區中,前往「Features」頁面。
  2. 從「Region」(區域) 下拉式清單中選取一個區域。
  3. 在功能表格中,查看「實體類型」欄,找出要更新的實體類型。
  4. 按一下實體類型名稱,即可查看實體詳細資料頁面。
  5. 在動作列中,按一下「編輯資訊」
  6. 在「監控時間間隔」中,輸入快照之間的天數。
    啟用實體類型或特徵的監控功能後,系統會在最接近的整點執行實體類型或特徵的監控工作。舉例來說,如果您在週一晚上 10:30 啟用監控功能,並指定兩天為監控時間間隔,則第一項監控工作會在週三晚上 11 點執行。
  7. 按一下「更新」
  8. 同樣地,在功能表格中,查看「功能」欄,找出要更新的功能。
  9. 按一下功能名稱即可查看詳細資料頁面。
  10. 在動作列中,按一下「編輯資訊」
  11. 如要停用特定功能的監控功能,請將「已啟用監控」切換為關閉。

REST

如要更新實體類型,請使用 entityTypes.patch 方法傳送 PATCH 要求。

使用任何要求資料之前,請先替換以下項目:

  • LOCATION_ID:特徵儲存庫所在的區域,例如 us-central1
  • PROJECT_ID:您的專案 ID
  • FEATURESTORE_ID:特徵商店的 ID。
  • ENTITY_TYPE_ID:實體類型 ID。
  • DURATION_IN_DAYS:快照之間的時間間隔,以天為單位。
  • STALENESS_DAYS:拍攝快照時要回溯的天數。
  • NUMERICAL_THRESHOLD_VALUE:偵測此實體類型下數值特徵異常狀況的門檻。系統會使用 Jenson-Shannon 散度計算統計資料偏差。
  • CATEGORICAL_THRESHOLD_VALUE:偵測這個實體類型下類別特徵異常狀況的門檻。統計資料偏差是透過 L-Infinity 距離計算。
  • IMPORT_FEATURE_ANALYSIS_STATE:指出是否啟用匯入功能分析的狀態。
  • IMPORT_FEATURE_ANALYSIS_BASELINE:表示「????」的基準線

HTTP 方法和網址:

PATCH https://LOCATION_ID-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION_ID/featurestores/FEATURESTORE_ID/entityTypes/ENTITY_TYPE_ID

JSON 要求主體:

{
  "monitoringConfig": {
    "snapshotAnalysis": {
      "monitoringIntervalDays": "DURATION_IN_DAYS",
      "stalenessDays": "STALENESS_DAYS"
    }
  },
  "numericalThresholdConfig": {
    "value": "NUMERICAL_THRESHOLD_VALUE"
  },
  "categoricalThresholdConfig": {
    "value": "CATEGORICAL_THRESHOLD_VALUE"
  },
  "importFeatureAnalysis": {
    "state": "IMPORT_FEATURE_ANALYSIS_STATE",
    "anomalyDetectionBaseline": "IMPORT_FEATURE_ANALYSIS_BASELINE"
  }
}

如要傳送要求,請選擇以下其中一個選項:

curl

將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

curl -X PATCH \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://LOCATION_ID-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION_ID/featurestores/FEATURESTORE_ID/entityTypes/ENTITY_TYPE_ID"

PowerShell

將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method PATCH `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://LOCATION_ID-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION_ID/featurestores/FEATURESTORE_ID/entityTypes/ENTITY_TYPE_ID" | Select-Object -Expand Content

您應該會收到如下的 JSON 回應:

{
  "name": "projects/PROJECT_NUMBER/locations/LOCATION_ID/featurestores/FEATURESTORE_ID/entityTypes/ENTITY_TYPE_ID",
  "createTime": "2021-07-22T23:18:31.339972Z",
  "updateTime": "2021-07-29T22:24:40.221821Z",
  "etag": "AMEw9yPGDpwUwHx39gIDIg5mTQz65GMhnYHRzRslVPonm1g8xTnsTC5YUibmWo2MIuI=",
  "monitoringConfig": {
    "snapshotAnalysis": {
      "monitoringIntervalDays": "DURATION_IN_DAYS",
      "stalenessDays": "STALENESS_DAYS"
    }
  },
  "numericalThresholdConfig": {
    "value": "NUMERICAL_THRESHOLD_VALUE"
  },
  "categoricalThresholdConfig": {
    "value": "CATEGORICAL_THRESHOLD_VALUE"
  },
  "importFeatureAnalysis": {
    "state": "IMPORT_FEATURE_ANALYSIS_STATE",
    "anomalyDetectionBaseline": "IMPORT_FEATURE_ANALYSIS_BASELINE"
  }
}

Java

在試用這個範例之前,請先按照Java使用用戶端程式庫的 Vertex AI 快速入門中的操作說明進行設定。 詳情請參閱 Vertex AI Java API 參考說明文件

如要向 Vertex AI 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。


import com.google.cloud.aiplatform.v1.EntityType;
import com.google.cloud.aiplatform.v1.EntityTypeName;
import com.google.cloud.aiplatform.v1.FeaturestoreMonitoringConfig;
import com.google.cloud.aiplatform.v1.FeaturestoreMonitoringConfig.SnapshotAnalysis;
import com.google.cloud.aiplatform.v1.FeaturestoreServiceClient;
import com.google.cloud.aiplatform.v1.FeaturestoreServiceSettings;
import com.google.cloud.aiplatform.v1.UpdateEntityTypeRequest;
import java.io.IOException;

public class UpdateEntityTypeMonitoringSample {

  public static void main(String[] args) throws IOException {
    // TODO(developer): Replace these variables before running the sample.
    String project = "YOUR_PROJECT_ID";
    String featurestoreId = "YOUR_FEATURESTORE_ID";
    String entityTypeId = "YOUR_ENTITY_TYPE_ID";
    int monitoringIntervalDays = 1;
    String location = "us-central1";
    String endpoint = "us-central1-aiplatform.googleapis.com:443";
    updateEntityTypeMonitoringSample(
        project, featurestoreId, entityTypeId, monitoringIntervalDays, location, endpoint);
  }

  static void updateEntityTypeMonitoringSample(
      String project,
      String featurestoreId,
      String entityTypeId,
      int monitoringIntervalDays,
      String location,
      String endpoint)
      throws IOException {

    FeaturestoreServiceSettings featurestoreServiceSettings =
        FeaturestoreServiceSettings.newBuilder().setEndpoint(endpoint).build();

    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (FeaturestoreServiceClient featurestoreServiceClient =
        FeaturestoreServiceClient.create(featurestoreServiceSettings)) {
      FeaturestoreMonitoringConfig featurestoreMonitoringConfig =
          FeaturestoreMonitoringConfig.newBuilder()
              .setSnapshotAnalysis(
                  SnapshotAnalysis.newBuilder().setMonitoringIntervalDays(monitoringIntervalDays))
              .build();
      EntityType entityType =
          EntityType.newBuilder()
              .setName(
                  EntityTypeName.of(project, location, featurestoreId, entityTypeId).toString())
              .setMonitoringConfig(featurestoreMonitoringConfig)
              .build();

      UpdateEntityTypeRequest updateEntityTypeRequest =
          UpdateEntityTypeRequest.newBuilder().setEntityType(entityType).build();
      EntityType entityTypeResponse =
          featurestoreServiceClient.updateEntityType(updateEntityTypeRequest);
      System.out.println("Update Entity Type Monitoring Response");
      System.out.println(entityTypeResponse);
    }
  }
}

Node.js

在試用這個範例之前,請先按照Node.js使用用戶端程式庫的 Vertex AI 快速入門中的操作說明進行設定。 詳情請參閱 Vertex AI Node.js API 參考說明文件

如要向 Vertex AI 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。

/**
 * TODO(developer): Uncomment these variables before running the sample.\
 * (Not necessary if passing values as arguments)
 */

// const project = 'YOUR_PROJECT_ID';
// const featurestoreId = 'YOUR_FEATURESTORE_ID';
// const entityTypeId = 'YOUR_ENTITY_TYPE_ID';
// const duration = <MONITORING_INTERVAL_IN_SECONDS>;
// const location = 'YOUR_PROJECT_LOCATION';
// const apiEndpoint = 'YOUR_API_ENDPOINT';
// const timeout = <TIMEOUT_IN_MILLI_SECONDS>;

// Imports the Google Cloud Featurestore Service Client library
const {FeaturestoreServiceClient} =
  require('@google-cloud/aiplatform').v1beta1;

// Specifies the location of the api endpoint
const clientOptions = {
  apiEndpoint: apiEndpoint,
};

// Instantiates a client
const featurestoreServiceClient = new FeaturestoreServiceClient(
  clientOptions
);

async function updateEntityTypeMonitoring() {
  // Configure the name resource
  const name = `projects/${project}/locations/${location}/featurestores/${featurestoreId}/entityTypes/${entityTypeId}`;

  // Constructing the monitoring configuration
  const monitoringConfig = {
    snapshotAnalysis: {
      monitoringInterval: {
        seconds: Number(duration),
      },
    },
  };

  // Constructing the entityType
  const entityType = {
    name: name,
    monitoringConfig: monitoringConfig,
  };

  const request = {
    entityType: entityType,
  };

  // Update EntityType request
  const [response] = await featurestoreServiceClient.updateEntityType(
    request,
    {timeout: Number(timeout)}
  );

  console.log('Update entity type monitoring response');
  console.log(`Name : ${response.name}`);
  console.log('Raw response:');
  console.log(JSON.stringify(response, null, 2));
}
updateEntityTypeMonitoring();

選擇不監控特定功能

以下範例會關閉現有特徵的監控功能:

REST

如要更新功能,請使用 features.patch 方法傳送 PATCH 要求。

使用任何要求資料之前,請先替換以下項目:

  • LOCATION_ID:特徵儲存庫所在的區域,例如 us-central1
  • PROJECT_ID:您的專案 ID
  • FEATURESTORE_ID:特徵商店的 ID。
  • ENTITY_TYPE_ID:實體類型 ID。
  • FEATURE_ID:要更新的功能 ID。
  • DISABLE_MONITORING:設為 true 可明確選擇不接受監控。

HTTP 方法和網址:

PATCH https://LOCATION_ID-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION_ID/featurestores/FEATURESTORE_ID/entityTypes/ENTITY_TYPE_ID/features/FEATURE_ID

JSON 要求主體:

{
  "disableMonitoring": "DISABLE_MONITORING"
}

如要傳送要求,請選擇以下其中一個選項:

curl

將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

curl -X PATCH \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://LOCATION_ID-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION_ID/featurestores/FEATURESTORE_ID/entityTypes/ENTITY_TYPE_ID/features/FEATURE_ID"

PowerShell

將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method PATCH `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://LOCATION_ID-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION_ID/featurestores/FEATURESTORE_ID/entityTypes/ENTITY_TYPE_ID/features/FEATURE_ID" | Select-Object -Expand Content

您應該會收到如下的 JSON 回應:

{
  "name": "projects/PROJECT_NUMBER/locations/LOCATION_ID/featurestores/FEATURESTORE_ID/entityTypes/ENTITY_TYPE_ID/features/FEATURE_ID",
  "valueType": "FEATURE_VALUE_TYPE",
  "createTime": "2021-07-22T23:18:31.339972Z",
  "updateTime": "2021-07-29T22:24:40.221821Z",
  "etag": "AMEw9yPGDpwUwHx39gIDIg5mTQz65GMhnYHRzRslVPonm1g8xTnsTC5YUibmWo2MIuI=",
  "disableMonitoring": "DISABLE_MONITORING"
}

查看特徵值分布情形

使用 Google Cloud 控制台查看特徵值分布變化趨勢。

網路使用者介面

  1. 在 Google Cloud 控制台的 Vertex AI 專區中,前往「Features」頁面。

    前往「Features」(功能) 頁面

  2. 從「Region」(區域) 下拉式清單中選取一個區域。

  3. 如要查看實體類型所有特徵的特徵值分布情形,請在「實體類型」欄中按一下實體類型。

  4. 如要查看特徵的特徵值分布指標,請按照下列步驟操作:

    1. 在「功能」欄中,按一下所需功能。

    2. 按一下「指標」分頁標籤,即可查看特徵值分布指標。

查看特徵值異常

如果監控管道中的特徵值分布情形超出指定門檻,系統就會視為異常。異常狀況分為兩種:訓練/服務偏斜和漂移。為計算偏差,Vertex AI 會比較實際工作環境中的最新特徵值與基準。

  • 為偵測訓練/應用偏差,Vertex AI 會比較正式環境中的最新特徵值與訓練資料中特徵值的統計分布情形。在本例中,訓練資料中特徵值的統計分布情況會視為基準分布情況。進一步瞭解訓練/服務偏差。

  • 為偵測漂移,Vertex AI 會比較生產環境中的最新特徵值,以及至少一小時前最近一次監控作業的特徵值統計分布。在這種情況下,系統會將最近一次監控作業的特徵值統計分布視為基準分布。進一步瞭解漂移。

在這兩種情況下,系統都會比較基準分配情形與最新特徵值,然後計算距離分數。

  • 如果是類別特徵,距離分數會使用 L-infinity 距離計算。在這種情況下,如果距離分數超過您在「類別警報門檻」欄位中指定的門檻,系統就會將其視為異常。

  • 如果是數值特徵,距離分數會使用 Jensen-Shannon 散度計算。在本例中,如果距離分數超過您在「數值警報門檻」欄位中指定的門檻,系統就會將其視為異常。

無論是哪種情況,異常情形都可能是訓練/應用偏差或偏移,具體取決於用於計算距離分數的基準分布。異常記錄會寫入 Cloud Logging,記錄名稱為 featurestore_log。您可以將記錄檔同步至 Cloud Logging 支援的任何下游服務,例如 Pub/Sub。

如要進一步瞭解如何設定警告門檻,請參閱「建立已啟用監控功能的實體類型」。

查詢特定特徵商店產生的所有異常狀況

logName="projects/model-monitoring-demo/logs/aiplatform.googleapis.com%2FFfeaturestore_log"
resource.labels.resource_container=<project_number>
resource.labels.featurestore_id=<featurestore_id>

異常記錄項目範例

{
  "insertId": "ktbx5jf7vdn7b",
  "jsonPayload": {
    "threshold": 0.001,
    "featureName": "projects/<project_number>/locations/us-central1/featurestores/<featurestore_id>/entityTypes/<entity_type_id>/features/<feature_id>",
    "deviation": 1,
    "@type": "type.googleapis.com/google.cloud.aiplatform.logging.FeatureAnomalyLogEntry",
    "objective": "Featurestore Monitoring Snapshot Drift Anomaly"
  },
  "resource": {
    "type": "aiplatform.googleapis.com/Featurestore",
    "labels": {
      "resource_container": "<project_number>",
      "location": "us-central1",
      "featurestore_id": "<featurestore_id>"
    }
  },
  "timestamp": "2022-02-06T00:54:06.455501Z",
  "severity": "WARNING",
  "logName": "projects/model-monitoring-demo/logs/aiplatform.googleapis.com%2Ffeaturestore_log",
  "receiveTimestamp": "2022-02-06T00:54:06.476107155Z"
}

監控串流擷取的離線儲存空間寫入錯誤

使用 Google Cloud 控制台監控串流擷取期間離線儲存空間的寫入錯誤。

查看串流擷取至離線儲存空間的指標

您可以在指標探索器中,監控 Vertex AI 特徵儲存庫 (舊版) 的「離線儲存空間寫入串流寫入」指標。

網路使用者介面

  1. 前往 Google Cloud 控制台的「Metrics Explorer」

    前往 Metrics Explorer

  2. 指定要在圖表中顯示的資料:

    • 資源和指標:依序選取指標「Vertex AI Feature Store」>「Offline storage write for streaming write」

    • 篩選器:選取 error_code

  3. 按一下 [套用]。圖表會顯示各種錯誤代碼的離線儲存空間寫入錯誤。

    生成圖表後,您可以將其新增至自訂資訊主頁。詳情請參閱「儲存圖表以供日後參考」。

查看 Vertex AI 特徵儲存庫 (舊版) 記錄

您可以在記錄檔探索工具中,查看特徵商店的記錄項目,包括離線商店寫入錯誤期間產生的記錄。

網路使用者介面

  1. 前往 Google Cloud 控制台的「Logs Explorer」頁面:

    前往記錄檔探索工具

  2. 在「查詢建立工具」中,加入下列查詢參數,然後點選「執行查詢」

    • 資源:選取「Vertex AI 特徵儲存庫」
    • 記錄名稱:在「Vertex AI API」下方,選取 aiplatform.googlapis.com/featurestore_log