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):
105class FeaturestoreStateEnum(enum.Enum):
106  """The possible states a Vertex AI featurestore can have.
107
108  https://cloud.google.com/vertex-ai/docs/reference/rest/v1/projects.locations.featurestores#state
109  """
110
111  STATE_UNSPECIFIED = 'STATE_UNSPECIFIED'
112  STABLE = 'STABLE'
113  UPDATING = 'UPDATING'
114
115  def __str__(self):
116    return str(self.value)
STATE_UNSPECIFIED = <FeaturestoreStateEnum.STATE_UNSPECIFIED: 'STATE_UNSPECIFIED'>
STABLE = <FeaturestoreStateEnum.STABLE: 'STABLE'>
UPDATING = <FeaturestoreStateEnum.UPDATING: 'UPDATING'>
class Featurestore(gcpdiag.models.Resource):
119class Featurestore(models.Resource):
120  """Represent a Vertex AI featurestore
121
122  https://cloud.google.com/vertex-ai/docs/reference/rest/v1/projects.locations.featurestores#resource:-featurestore
123  """
124
125  _resource_data: dict
126
127  def __init__(self, project_id, resource_data):
128    super().__init__(project_id=project_id)
129    self._resource_data = resource_data
130
131  @property
132  def full_path(self) -> str:
133    """
134    The 'name' of the featurestore is already in the full path form
135    projects/{project}/locations/{location}/featurestores/{featurestore}.
136    """
137    return self._resource_data[NAME_KEY]
138
139  @property
140  def short_path(self) -> str:
141    path = self.full_path
142    path = re.sub(r'^projects/', '', path)
143    path = re.sub(r'/locations/', '/', path)
144    path = re.sub(r'/featurestores/', '/', path)
145    return path
146
147  @property
148  def name(self) -> str:
149    logging.debug(self._resource_data)
150    return self._resource_data[NAME_KEY]
151
152  @property
153  def state(self) -> str:
154    logging.debug(self._resource_data)
155    return self._resource_data[STATE_KEY]
Featurestore(project_id, resource_data)
127  def __init__(self, project_id, resource_data):
128    super().__init__(project_id=project_id)
129    self._resource_data = resource_data
full_path: str
131  @property
132  def full_path(self) -> str:
133    """
134    The 'name' of the featurestore is already in the full path form
135    projects/{project}/locations/{location}/featurestores/{featurestore}.
136    """
137    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
139  @property
140  def short_path(self) -> str:
141    path = self.full_path
142    path = re.sub(r'^projects/', '', path)
143    path = re.sub(r'/locations/', '/', path)
144    path = re.sub(r'/featurestores/', '/', path)
145    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
147  @property
148  def name(self) -> str:
149    logging.debug(self._resource_data)
150    return self._resource_data[NAME_KEY]
state: str
152  @property
153  def state(self) -> str:
154    logging.debug(self._resource_data)
155    return self._resource_data[STATE_KEY]
@caching.cached_api_call
def get_featurestores( context: gcpdiag.models.Context) -> Dict[str, Featurestore]:
158@caching.cached_api_call
159def get_featurestores(context: models.Context) -> Dict[str, Featurestore]:
160  featurestores: Dict[str, Featurestore] = {}
161  if not apis.is_enabled(context.project_id, 'aiplatform'):
162    return featurestores
163  for region in FEATURE_REGIONS[FEATURESTORES_KEY]:
164    featurestores_res: Dict[str, Featurestore] = {}
165    region_name = REGIONS[region]
166    logging.debug(
167      'fetching list of Vertex AI featurestores in project %s for region %s',
168      context.project_id,
169      region_name,
170    )
171    vertex_api = apis.get_api('aiplatform', 'v1', context.project_id, region_name)
172    query = (
173      vertex_api.projects()
174      .locations()
175      .featurestores()
176      .list(parent=f'projects/{context.project_id}/locations/{region_name}')
177    )
178    try:
179      resp = query.execute(num_retries=config.API_RETRIES)
180      if FEATURESTORES_KEY not in resp:
181        continue
182      for resp_i in resp[FEATURESTORES_KEY]:
183        # verify that we have some minimal data that we expect
184        if NAME_KEY not in resp_i:
185          raise RuntimeError(
186            'missing featurestore name in projects.locations.featurestores.list response'
187          )
188        i = Featurestore(project_id=context.project_id, resource_data=resp_i)
189        featurestores_res[i.full_path] = i
190        if featurestores:
191          featurestores.update(featurestores_res)
192        else:
193          featurestores = featurestores_res
194    except googleapiclient.errors.HttpError as err:
195      raise utils.GcpApiError(err) from err
196  return featurestores