
                            d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddl	mZ dd	l	mZ dd
l	mZ ddl	mZ ddl	mZ ddlmZ ddlmZ ddiZd Zd Z ej.                  ej0                  j2                         G d dej4                               Z ej.                  ej0                  j8                  ej0                  j:                         G d dej4                               Zee_        ee_        y)z/Vertex AI model monitoring jobs create command.    )absolute_import)division)unicode_literals)client)base)	constants)endpoint_util)flags)model_monitoring_jobs_util)region_util)
validation)labels_util)logEXAMPLESaf  
    To create a model deployment monitoring job under project ``example'' in region ``us-central1'' for endpoint ``123'', run:

      $ {command} --project=example --region=us-central1 --display-name=my_monitoring_job --emails=a@gmail.com,b@gmail.com --endpoint=123 --prediction-sampling-rate=0.2

    To create a model deployment monitoring job with drift detection for all the deployed models under the endpoint ``123'', run:

      $ {command} --project=example --region=us-central1 --display-name=my_monitoring_job --emails=a@gmail.com,b@gmail.com --endpoint=123 --prediction-sampling-rate=0.2 --feature-thresholds=feat1=0.1,feat2=0.2,feat3=0.2,feat4=0.3

    To create a model deployment monitoring job with skew detection for all the deployed models under the endpoint ``123'', with training dataset from Google Cloud Storage, run:

      $ {command} --project=example --region=us-central1 --display-name=my_monitoring_job --emails=a@gmail.com,b@gmail.com --endpoint=123 --prediction-sampling-rate=0.2 --feature-thresholds=feat1=0.1,feat2=0.2,feat3=0.2,feat4=0.3 --target-field=price --data-format=csv --gcs-uris=gs://test-bucket/dataset.csv

    To create a model deployment monitoring job with skew detection for all the deployed models under the endpoint ``123'', with training dataset from Vertex AI dataset ``456'', run:

      $ {command} --project=example --region=us-central1 --display-name=my_monitoring_job --emails=a@gmail.com,b@gmail.com --endpoint=123 --prediction-sampling-rate=0.2 --feature-thresholds=feat1=0.1,feat2=0.2,feat3=0.2,feat4=0.3 --target-field=price --dataset=456

    To create a model deployment monitoring job with different drift detection or skew detection for different deployed models, run:

      $ {command} --project=example --region=us-central1 --display-name=my_monitoring_job --emails=a@gmail.com,b@gmail.com --endpoint=123 --prediction-sampling-rate=0.2 --monitoring-config-from-file=your_objective_config.yaml

    After creating the monitoring job, be sure to send some predict requests. It will be used to generate some metadata for analysis purpose, like predict and analysis instance schema.
    c                 &   t        j                  | dt        j                  t        j
                               t        j                  d      j                  |        t        j                  d      j                  |        t        j                  d      j                  |        t        j                  d      j                  |        t        j                  d      j                  |        t        j                  d      j                  |        t        j                  d      j                  |        t        j                  d      j                  |        t        j                  d      j                  |        t        j                   | d       t        j"                  | d       t        j$                  d      j                  |        t        j&                  d      j                  |        t)        j*                  |        y)zAdd flags for create command.z)to create model deployment monitoring job)prompt_funczmodel deployment monitoring jobT)requiredFN)r
   AddRegionResourceArgr   GetPromptForRegionFuncr   'SUPPORTED_MODEL_MONITORING_JOBS_REGIONSGetDisplayNameArgAddToParserGetEndpointIdArgGetEmailsArgGetPredictionSamplingRateArgGetMonitoringFrequencyArgGetPredictInstanceSchemaArgGetAnalysisInstanceSchemaArgGetSamplingPredictRequestArgGetMonitoringLogTtlArg AddObjectiveConfigGroupForCreateAddKmsKeyResourceArgGetAnomalyCloudLoggingArgGetNotificationChannelsArgr   AddCreateLabelsFlagsparsers    .lib/surface/ai/model_monitoring_jobs/create.py_Argsr)   <   sr   144

;
;=>
 ;<HHP$'33F;d#//7$$d3??G!!51==fE##U3??G$$e4@@H$$e4@@H.::6B((%@V%FG!!51==fE""E2>>vF""6*    c                 <   t        j                  | j                         | j                  j                  j                         }|j                         d   }t        j                  ||      5  t        j                  |      j                  ||       }d}|r|d|z   z  }t        j                  j                  t        j                   j#                  t%        j&                  |j(                        ||j*                               |cddd       S # 1 sw Y   yxY w)zRun method for create command.locationsId)versionregion)r-   gcloud )id
cmd_prefixstateN)r   ValidateDisplayNamedisplay_nameCONCEPTSr.   ParseAsDictr	   AiplatformEndpointOverridesr   ModelMonitoringJobsClientCreater   statusPrintr   -MODEL_MONITORING_JOB_CREATION_DISPLAY_MESSAGEformatr   ParseJobNamenamer3   )argsr-   release_prefix
region_refr.   responser2   s          r(   _RunrF   S   s      !2!23}}##))+*}-&00f&//@GGDHJC.((jJJ??FF)66x}}E!.. 	G 	"#
 & & &s   .BDDc                   &    e Zd ZdZed        Zd Zy)CreateGa,Create a new Vertex AI model monitoring job.c                     t        |        y Nr)   r&   s    r(   ArgszCreateGa.Argsk   	    	&Mr*   c                 h    t        |t        j                  | j                         j                        S rK   )rF   r   
GA_VERSIONReleaseTrackprefixselfrB   s     r(   RunzCreateGa.Runo   s&    i**D,=,=,?,F,FGGr*   N__name__
__module____qualname____doc__staticmethodrM   rU    r*   r(   rH   rH   g   s    4 Hr*   rH   c                   &    e Zd ZdZed        Zd Zy)r;   rI   c                     t        |        y rK   rL   r&   s    r(   rM   zCreate.Argsw   rN   r*   c                 h    t        |t        j                  | j                         j                        S rK   )rF   r   BETA_VERSIONrQ   rR   rS   s     r(   rU   z
Create.Run{   s&    i,,d.?.?.A.H.HIIr*   NrV   r\   r*   r(   r;   r;   s   s    4 Jr*   r;   N) rZ   
__future__r   r   r   /googlecloudsdk.api_lib.ai.model_monitoring_jobsr   googlecloudsdk.callioper   googlecloudsdk.command_lib.air   r	   r
   r   r   r   $googlecloudsdk.command_lib.util.argsr   googlecloudsdk.corer   DETAILED_HELPr)   rF   ReleaseTracksrQ   GACreateCommandrH   ALPHABETAr;   detailed_helpr\   r*   r(   <module>rn      s    6 &  ' B ( 3 7 / D 5 4 < # 	8+.( D%%(()Ht!! H *H D%%++T->->-C-CDJT J EJ % & r*   