监控

在 Vertex AI Feature Store(旧版)中,您可以监控和设置特征存储区和特征的提醒。例如,运营团队可能会监控特征存储区以跟踪其 CPU 利用率。特征所有者(如数据科学家)可能会监控特征值以检测一段时间内的偏移。

以下部分介绍了监控特征存储区和特征的方法:

特征存储区监控

Vertex AI Feature Store(旧版)向 Cloud Monitoring 报告有关您特征存储区的指标,例如 CPU 负载、存储容量和请求延迟时间。Vertex AI 会为您收集并报告这些指标。您无需配置或启用特征存储区监控。

如需配置阈值和通知,请使用 Cloud Monitoring。例如,如果平均 CPU 负载超过 70%,您可能需要设置提醒,这可能需要增加特征存储区节点的数量。

您还可以在 Google Cloud 控制台的 Vertex AI 部分查看特征存储区指标,了解一段时间内的趋势。对于某些图表,控制台会显示聚合值或计算值以使信息更易于使用。您始终可以在 Cloud Monitoring 中查看原始数据。

如需了解详情,请参阅 Vertex AI Cloud Monitoring 页面上的 Vertex AI Feature Store(旧版)监控指标

特征值监控

特征值监控功能使您能够跟踪特征值分布在特征存储区中变化的程度。系统支持对以下类型的特征值进行监控:

  • 快照分析:Vertex AI Feature Store(旧版)会定期获取特征值的快照。一段时间后,随着您注入更多数据,您可能会注意到特征值的分布发生了变化。此变化表明使用这些特征的所有模型都可能需要重新训练。您可以指定阈值,以便在分布偏差超过阈值时在 Cloud Logging 控制台中记录异常值。

    对于超过 500 万个实体 ID 的数据集,Vertex AI Feature Store(旧版)会根据在您指定的过时天数时长内随机选择的 500 万个实体 ID 生成快照。

  • 导入特征分析:每个 ImportFeatureValues 操作都会为注入到 Vertex AI Feature Store(旧版)的值生成分布统计信息。您可以将分布统计信息与先前导入的特征值分布进行比较,或者通过快照分布(如果已启用),来检测异常值。

    对于超过 500 万个实例的数据集,Vertex AI Feature Store(旧版)会根据随机选择的数据生成快照,如下所示:

    • 如果所注入数据集内的实例数量超过 500 万但未超过 5,000 万,则系统会根据随机选择的 500 万个实例生成快照。
    • 如果所注入数据集内的实例数量超过 5,000 万,则系统会根据随机选择的 10% 的实例生成快照。

例如,假设有一个用于收集最近出售房屋的价格的特征,您可以通过将这些值提供给模型来预测房价。最近出售的房屋的价格可能会随着时间的推移而大幅波动,或者批量导入的值可能会包含与训练数据存在较大偏差的数据。Vertex AI Feature Store(旧版)会提醒您这些变化;以便您可以重新训练模型以使用最新信息。

设置监控配置

如需开始监控,您可以针对特定实体类型定义监控配置,从而为相应类型的所有特征启用监控:

  • BOOL
  • STRING
  • DOUBLE
  • INT64

您可以在创建实体类型时设置监控配置。您还可以通过设置 disableMonitoring 属性来停用对特定特征的监控。实体类型监控配置会指定以下内容:

  • 是否启用监控。监控功能默认处于停用状态。
  • 用于检测异常的阈值。默认阈值为 0.3。
  • 除了快照之间的间隔之外,还提供回溯期(用于快照分析)。默认值为 21。
  • 是否启用导入特征分析。默认为停用。

如需了解详情,请参阅 API 参考文档中的 FeaturestoreMonitoringConfig 类型。

创建启用了监控的实体类型

以下示例将创建一个启用了特征监控的实体类型:

网页界面

该界面仅支持快照分析

  1. 在 Google Cloud 控制台的“Vertex AI”部分,转到特征页面。

    转到“特征”页面

  2. 区域下拉列表中选择一个区域。
  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-无穷大距离计算得出。
  • IMPORT_FEATURE_ANALYSIS_STATE:用于指示是否启用导入特征分析的状态。
  • IMPORT_FEATURE_ANALYSIS_BASELINE:导入特征分析(如果已启用)的基准。

HTTP 方法和网址:

POST http://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 \
"http://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 "http://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

在尝试此示例之前,请按照《Vertex AI 快速入门:使用客户端库》中的 Java 设置说明执行操作。如需了解详情,请参阅 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

在尝试此示例之前,请按照《Vertex AI 快速入门:使用客户端库》中的 Node.js 设置说明执行操作。如需了解详情,请参阅 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。如需了解详情,请参阅 Python 版 Vertex AI SDK 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 http://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 \
"http://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 "http://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”部分,转到特征页面。
  2. 区域下拉列表中选择一个区域。
  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-无穷大距离计算得出。
  • IMPORT_FEATURE_ANALYSIS_STATE:用于指示是否启用导入特征分析的状态。
  • IMPORT_FEATURE_ANALYSIS_BASELINE:用于表示 ???? 的基准

HTTP 方法和网址:

PATCH http://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 \
"http://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 "http://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

在尝试此示例之前,请按照《Vertex AI 快速入门:使用客户端库》中的 Java 设置说明执行操作。如需了解详情,请参阅 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

在尝试此示例之前,请按照《Vertex AI 快速入门:使用客户端库》中的 Node.js 设置说明执行操作。如需了解详情,请参阅 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 http://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 \
"http://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 "http://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”部分,转到特征页面。

    转到“特征”页面

  2. 区域下拉列表中选择一个区域。

  3. 如需查看实体类型所有特征的特征值分布,请在实体类型列中点击实体类型。

  4. 如需查看某个特征的特征值分布指标,请执行以下操作:

    1. 特征列中,点击此特征。

    2. 点击指标标签页以查看特征值分布指标。

查看特征值异常

如果特征值分布偏差,超出监控流水线中指定的阈值,则会被视为异常值。异常值有两种类型:训练-应用偏差和偏移。为了计算偏差,Vertex AI 会将生产环境中的最新特征值与基准进行比较。

  • 为了检测训练-应用偏差,Vertex AI 会将生产环境中的最新特征值与训练数据中特征值的统计分布进行比较。在这种情况下,训练数据中的特征值的统计分布会被视为基准分布。详细了解训练-应用偏差。

  • 为了检测偏移,Vertex AI 会将生产环境中的最新特征值与至少一小时之前最近一次监控运行的特征值的统计分布进行比较。在这种情况下,最近一次监控运行的特征值的统计分布会被视为基准分布。详细了解偏移。

在这两种情况下,基准分布会与生产环境中的最新特征值进行比较,以计算距离得分。

  • 对于分类特征,距离得分使用 L-无穷大距离计算得出。 在这种情况下,如果距离得分超过您在分类提醒阈值字段中指定的阈值,则系统会将其标识为异常值。

  • 对于数值特征,距离得分使用 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 控制台监控离线存储空间的写入错误。

查看流式注入到离线存储空间的指标

您可以在 Metrics Explorer 中监控 Vertex AI Feature Store(旧版)的用于流式写入的离线存储空间写入指标。

网页界面

  1. 在 Google Cloud 控制台中,转到 Metrics Explorer

    打开 Metrics Explorer

  2. 在工具栏中,选择浏览器标签页。

  3. 配置标签页中,指定要在图表上显示的数据:

    • 资源和指标:选择指标 Vertex AI Feature Store - 用于流式写入的离线存储空间写入

    • 分组依据:选择 error_code

    • 最短校准时间段:指定校准图表中数据的最小时间间隔。

  4. 更新这些字段后,图表会显示各种错误代码的离线存储空间写入错误。

    生成图表后,您可以将它添加到自定义信息中心。如需了解详情,请参阅保存图表以供日后参考

查看 Vertex AI Feature Store(旧版)日志

您可以在 Logs Explorer 中查看特征存储区的日志条目,包括在离线存储区写入错误期间生成的日志。

网页界面

  1. 在 Google Cloud 控制台中,转到 Logs Explorer 页面。

    前往 Logs Explorer

  2. 查询构建器中,添加以下查询参数,然后点击运行查询

    • 资源:选择 Vertex AI Feature Store
    • 日志名称:在 Vertex AI API 下面,选择 aiplatform.googlapis.com/featurestore_log