gcpdiag.queries.vertex

Queries related to GCP Vertex AI
FEATURESTORES_KEY = 'featurestores'
NAME_KEY = 'name'
STATE_KEY = 'state'
REGIONS = {1: 'asia-east1', 2: 'asia-east2', 3: 'asia-northeast1', 4: 'asia-northeast2', 5: 'asia-northeast3', 6: 'asia-south1', 7: 'asia-south2', 8: 'asia-southeast1', 9: 'asia-southeast2', 10: 'australia-southeast1', 11: 'australia-southeast2', 12: 'europe-central2', 13: 'europe-north1', 14: 'europe-southwest1', 15: 'europe-west1', 16: 'europe-west2', 17: 'europe-west3', 18: 'europe-west4', 19: 'europe-west6', 20: 'europe-west8', 21: 'europe-west9', 22: 'europe-west12', 23: 'me-central1', 24: 'me-west1', 25: 'northamerica-northeast1', 26: 'northamerica-northeast2', 27: 'southamerica-east1', 28: 'southamerica-west1', 29: 'us-central1', 30: 'us-east1', 31: 'us-east4', 32: 'us-east5', 33: 'us-south1', 34: 'us-west1', 35: 'us-west2', 36: 'us-west3', 37: 'us-west4'}
FEATURE_REGIONS = {'featurestores': [1, 2, 3, 5, 6, 8, 9, 10, 12, 15, 16, 17, 18, 19, 21, 25, 26, 27, 29, 30, 31, 34, 35, 36, 37]}
class FeaturestoreStateEnum(enum.Enum):
83class FeaturestoreStateEnum(enum.Enum):
84  """The possible states a Vertex AI featurestore can have.
85
86  https://cloud.google.com/vertex-ai/docs/reference/rest/v1/projects.locations.featurestores#state
87  """
88
89  STATE_UNSPECIFIED = 'STATE_UNSPECIFIED'
90  STABLE = 'STABLE'
91  UPDATING = 'UPDATING'
92
93  def __str__(self):
94    return str(self.value)
STATE_UNSPECIFIED = <FeaturestoreStateEnum.STATE_UNSPECIFIED: 'STATE_UNSPECIFIED'>
STABLE = <FeaturestoreStateEnum.STABLE: 'STABLE'>
UPDATING = <FeaturestoreStateEnum.UPDATING: 'UPDATING'>
class Featurestore(gcpdiag.models.Resource):
 97class Featurestore(models.Resource):
 98  """Represent a Vertex AI featurestore
 99
100  https://cloud.google.com/vertex-ai/docs/reference/rest/v1/projects.locations.featurestores#resource:-featurestore
101  """
102
103  _resource_data: dict
104
105  def __init__(self, project_id, resource_data):
106    super().__init__(project_id=project_id)
107    self._resource_data = resource_data
108
109  @property
110  def full_path(self) -> str:
111    """
112    The 'name' of the featurestore is already in the full path form
113    projects/{project}/locations/{location}/featurestores/{featurestore}.
114    """
115    return self._resource_data[NAME_KEY]
116
117  @property
118  def short_path(self) -> str:
119    path = self.full_path
120    path = re.sub(r'^projects/', '', path)
121    path = re.sub(r'/locations/', '/', path)
122    path = re.sub(r'/featurestores/', '/', path)
123    return path
124
125  @property
126  def name(self) -> str:
127    logging.info(self._resource_data)
128    return self._resource_data[NAME_KEY]
129
130  @property
131  def state(self) -> str:
132    logging.info(self._resource_data)
133    return self._resource_data[STATE_KEY]
Featurestore(project_id, resource_data)
105  def __init__(self, project_id, resource_data):
106    super().__init__(project_id=project_id)
107    self._resource_data = resource_data
full_path: str
109  @property
110  def full_path(self) -> str:
111    """
112    The 'name' of the featurestore is already in the full path form
113    projects/{project}/locations/{location}/featurestores/{featurestore}.
114    """
115    return self._resource_data[NAME_KEY]

The 'name' of the featurestore is already in the full path form projects/{project}/locations/{location}/featurestores/{featurestore}.

short_path: str
117  @property
118  def short_path(self) -> str:
119    path = self.full_path
120    path = re.sub(r'^projects/', '', path)
121    path = re.sub(r'/locations/', '/', path)
122    path = re.sub(r'/featurestores/', '/', path)
123    return path

Returns the short name for this resource.

Note that it isn't clear from this name what kind of resource it is.

Example: 'gke1'

name: str
125  @property
126  def name(self) -> str:
127    logging.info(self._resource_data)
128    return self._resource_data[NAME_KEY]
state: str
130  @property
131  def state(self) -> str:
132    logging.info(self._resource_data)
133    return self._resource_data[STATE_KEY]
@caching.cached_api_call
def get_featurestores( context: gcpdiag.models.Context) -> Dict[str, Featurestore]:
136@caching.cached_api_call
137def get_featurestores(context: models.Context) -> Dict[str, Featurestore]:
138  featurestores: Dict[str, Featurestore] = {}
139  if not apis.is_enabled(context.project_id, 'aiplatform'):
140    return featurestores
141  for region in FEATURE_REGIONS[FEATURESTORES_KEY]:
142    featurestores_res: Dict[str, Featurestore] = {}
143    region_name = REGIONS[region]
144    logging.info(
145        'fetching list of Vertex AI featurestores in project %s for region %s',
146        context.project_id, region_name)
147    vertex_api = apis.get_api('aiplatform', 'v1', context.project_id,
148                              region_name)
149    query = vertex_api.projects().locations().featurestores().list(
150        parent=f'projects/{context.project_id}/locations/{region_name}')
151    try:
152      resp = query.execute(num_retries=config.API_RETRIES)
153      if FEATURESTORES_KEY not in resp:
154        continue
155      for resp_i in resp[FEATURESTORES_KEY]:
156        # verify that we have some minimal data that we expect
157        if NAME_KEY not in resp_i:
158          raise RuntimeError(
159              'missing featurestore name in projects.locations.featurestores.list response'
160          )
161        i = Featurestore(project_id=context.project_id, resource_data=resp_i)
162        featurestores_res[i.full_path] = i
163        if featurestores:
164          featurestores.update(featurestores_res)
165        else:
166          featurestores = featurestores_res
167    except googleapiclient.errors.HttpError as err:
168      raise utils.GcpApiError(err) from err
169  return featurestores