github.com/GoogleCloudPlatform/compute-image-tools/cli_tools@v0.0.0-20240516224744-de2dabc4ed1b/common/utils/logging/service/log_entry.go (about) 1 // Copyright 2019 Google Inc. All Rights Reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package service 16 17 import "github.com/GoogleCloudPlatform/compute-image-tools/proto/go/pb" 18 19 // logRequest is a server-side pre-defined data structure 20 type logRequest struct { 21 ClientInfo clientInfo `json:"client_info"` 22 LogSource int64 `json:"log_source"` 23 RequestTimeMs int64 `json:"request_time_ms"` 24 LogEvent []logEvent `json:"log_event"` 25 } 26 27 // ClientInfo is a server-side pre-defined data structure 28 type clientInfo struct { 29 // ClientType is defined on server side to clarify which client library is used. 30 ClientType string `json:"client_type"` 31 } 32 33 // LogEvent is a server-side pre-defined data structure 34 type logEvent struct { 35 EventTimeMs int64 `json:"event_time_ms"` 36 EventUptimeMs int64 `json:"event_uptime_ms"` 37 SourceExtensionJSON string `json:"source_extension_json"` 38 } 39 40 // logResponse is a server-side pre-defined data structure 41 type logResponse struct { 42 NextRequestWaitMillis int64 `json:"NextRequestWaitMillis,string"` 43 LogResponseDetails []logResponseDetails `json:"LogResponseDetails"` 44 } 45 46 // LogResponseDetails is a server-side pre-defined data structure 47 type logResponseDetails struct { 48 ResponseAction responseAction `json:"ResponseAction"` 49 } 50 51 // ResponseAction is a server-side pre-defined data structure 52 type responseAction string 53 54 const ( 55 // responseActionUnknown - If the client sees this, it should delete the logRequest (not retry). 56 // It may indicate that a new response action was added, which the client 57 // doesn't yet understand. (Deleting rather than retrying will prevent 58 // infinite loops.) The server will do whatever it can to prevent this 59 // occurring (by not indicating an action to clients that are behind the 60 // requisite version for the action). 61 responseActionUnknown responseAction = "RESPONSE_ACTION_UNKNOWN" 62 // retryRequestLater - The client should retry the request later, via normal scheduling. 63 retryRequestLater responseAction = "RETRY_REQUEST_LATER" 64 // deleteRequest - The client should delete the request. This action will apply for 65 // successful requests, and non-retryable requests. 66 deleteRequest responseAction = "DELETE_REQUEST" 67 ) 68 69 // ComputeImageToolsLogExtension contains all log info, which should be align with sawmill server side configuration. 70 type ComputeImageToolsLogExtension struct { 71 // This id is a random guid for correlation among multiple log lines of a single call 72 ID string `json:"id"` 73 CloudBuildID string `json:"cloud_build_id"` 74 ToolAction string `json:"tool_action"` 75 Status string `json:"status"` 76 ElapsedTimeMs int64 `json:"elapsed_time_ms"` 77 EventTimeMs int64 `json:"event_time_ms"` 78 InputParams *InputParams `json:"input_params,omitempty"` 79 OutputInfo *OutputInfo `json:"output_info,omitempty"` 80 } 81 82 // InputParams contains the union of all APIs' param info. To simplify logging service, we 83 // avoid defining different schemas for each API. 84 type InputParams struct { 85 ImageImportParams *ImageImportParams `json:"image_import_input_params,omitempty"` 86 ImageExportParams *ImageExportParams `json:"image_export_input_params,omitempty"` 87 InstanceImportParams *InstanceImportParams `json:"instance_import_input_params,omitempty"` 88 MachineImageImportParams *MachineImageImportParams `json:"machine_image_import_input_params,omitempty"` 89 WindowsUpgradeParams *WindowsUpgradeParams `json:"windows_upgrade_input_params,omitempty"` 90 OnestepImageImportParams *OnestepImageImportParams `json:"onestep_image_import_input_params,omitempty"` 91 InstanceExportParams *InstanceExportParams `json:"instance_export_input_params,omitempty"` 92 MachineImageExportParams *MachineImageExportParams `json:"machine_image_export_input_params,omitempty"` 93 } 94 95 // ImageImportParams contains all input params for image import 96 type ImageImportParams struct { 97 *CommonParams 98 99 ImageName string `json:"image_name,omitempty"` 100 DataDisk bool `json:"data_disk"` 101 OS string `json:"os,omitempty"` 102 SourceFile string `json:"source_file,omitempty"` 103 SourceImage string `json:"source_image,omitempty"` 104 NoGuestEnvironment bool `json:"no_guest_environment"` 105 Family string `json:"family,omitempty"` 106 Description string `json:"description,omitempty"` 107 NoExternalIP bool `json:"no_external_ip"` 108 HasKmsKey bool `json:"has_kms_key"` 109 HasKmsKeyring bool `json:"has_kms_keyring"` 110 HasKmsLocation bool `json:"has_kms_location"` 111 HasKmsProject bool `json:"has_kms_project"` 112 StorageLocation string `json:"storage_location,omitempty"` 113 InspectionResults *pb.InspectionResults `json:"inspection_results,omitempty"` 114 ComputeServiceAccount string `json:"compute_service_account,omitempty"` 115 } 116 117 // ImageExportParams contains all input params for image export 118 type ImageExportParams struct { 119 *CommonParams 120 121 DestinationURI string `json:"destination_uri,omitempty"` 122 SourceImage string `json:"source_image,omitempty"` 123 Format string `json:"format,omitempty"` 124 ComputeServiceAccount string `json:"compute_service_account,omitempty"` 125 SourceDiskSnapshot string `json:"source_disk_snapshot,omitempty"` 126 } 127 128 // OnestepImageImportParams contains all input params for onestep image import 129 type OnestepImageImportParams struct { 130 *CommonParams 131 132 // Image import params 133 ImageName string `json:"image_name,omitempty"` 134 OS string `json:"os,omitempty"` 135 NoGuestEnvironment bool `json:"no_guest_environment"` 136 Family string `json:"family,omitempty"` 137 Description string `json:"description,omitempty"` 138 NoExternalIP bool `json:"no_external_ip"` 139 HasKmsKey bool `json:"has_kms_key"` 140 HasKmsKeyring bool `json:"has_kms_keyring"` 141 HasKmsLocation bool `json:"has_kms_location"` 142 HasKmsProject bool `json:"has_kms_project"` 143 StorageLocation string `json:"storage_location,omitempty"` 144 ComputeServiceAccount string `json:"compute_service_account,omitempty"` 145 146 // AWS related params 147 AWSAMIID string `json:"aws_ami_id,omitempty"` 148 AWSAMIExportLocation string `json:"aws_ami_export_location,omitempty"` 149 AWSSourceAMIFilePath string `json:"aws_source_ami_file_path,omitempty"` 150 } 151 152 // InstanceImportParams contains all input params for instance import 153 type InstanceImportParams struct { 154 *CommonParams 155 156 InstanceName string `json:"instance_name,omitempty"` 157 OvfGcsPath string `json:"ovf_gcs_path,omitempty"` 158 CanIPForward bool `json:"can_ip_forward"` 159 DeletionProtection bool `json:"deletion_protection"` 160 MachineType string `json:"machine_type,omitempty"` 161 NetworkInterface string `json:"network_interface,omitempty"` 162 NetworkTier string `json:"network_tier,omitempty"` 163 PrivateNetworkIP string `json:"private_network_ip,omitempty"` 164 NoExternalIP bool `json:"no_external_ip,omitempty"` 165 NoRestartOnFailure bool `json:"no_restart_on_failure"` 166 OS string `json:"os,omitempty"` 167 ShieldedIntegrityMonitoring bool `json:"shielded_integrity_monitoring"` 168 ShieldedSecureBoot bool `json:"shielded_secure_boot"` 169 ShieldedVtpm bool `json:"shielded_vtpm"` 170 Tags string `json:"tags,omitempty"` 171 HasBootDiskKmsKey bool `json:"has_boot_disk_kms_key"` 172 HasBootDiskKmsKeyring bool `json:"has_boot_disk_kms_keyring"` 173 HasBootDiskKmsLocation bool `json:"has_boot_disk_kms_location"` 174 HasBootDiskKmsProject bool `json:"has_boot_disk_kms_project"` 175 NoGuestEnvironment bool `json:"no_guest_environment"` 176 NodeAffinityLabel string `json:"node_affinity_label,omitempty"` 177 ComputeServiceAccount string `json:"compute_service_account,omitempty"` 178 } 179 180 // MachineImageImportParams contains all input params for machine image import 181 type MachineImageImportParams struct { 182 *CommonParams 183 184 MachineImageName string `json:"machine_image_name,omitempty"` 185 OvfGcsPath string `json:"ovf_gcs_path,omitempty"` 186 CanIPForward bool `json:"can_ip_forward"` 187 DeletionProtection bool `json:"deletion_protection"` 188 MachineType string `json:"machine_type,omitempty"` 189 NetworkInterface string `json:"network_interface,omitempty"` 190 NetworkTier string `json:"network_tier,omitempty"` 191 PrivateNetworkIP string `json:"private_network_ip,omitempty"` 192 NoExternalIP bool `json:"no_external_ip,omitempty"` 193 NoRestartOnFailure bool `json:"no_restart_on_failure"` 194 OS string `json:"os,omitempty"` 195 ShieldedIntegrityMonitoring bool `json:"shielded_integrity_monitoring"` 196 ShieldedSecureBoot bool `json:"shielded_secure_boot"` 197 ShieldedVtpm bool `json:"shielded_vtpm"` 198 Tags string `json:"tags,omitempty"` 199 HasBootDiskKmsKey bool `json:"has_boot_disk_kms_key"` 200 HasBootDiskKmsKeyring bool `json:"has_boot_disk_kms_keyring"` 201 HasBootDiskKmsLocation bool `json:"has_boot_disk_kms_location"` 202 HasBootDiskKmsProject bool `json:"has_boot_disk_kms_project"` 203 NoGuestEnvironment bool `json:"no_guest_environment"` 204 NodeAffinityLabel string `json:"node_affinity_label,omitempty"` 205 Hostname string `json:"hostname,omitempty"` 206 MachineImageStorageLocation string `json:"machine_image_storage_location,omitempty"` 207 ComputeServiceAccount string `json:"compute_service_account,omitempty"` 208 } 209 210 // CommonParams is only used to organize the code without impacting hierarchy of data 211 type CommonParams struct { 212 ClientID string `json:"client_id,omitempty"` 213 ClientVersion string `json:"client_version,omitempty"` 214 Network string `json:"network,omitempty"` 215 Subnet string `json:"subnet,omitempty"` 216 Zone string `json:"zone,omitempty"` 217 Timeout string `json:"timeout,omitempty"` 218 Project string `json:"project,omitempty"` 219 ObfuscatedProject string `json:"obfuscated_project,omitempty"` 220 Labels string `json:"labels,omitempty"` 221 ScratchBucketGcsPath string `json:"scratch_bucket_gcs_path,omitempty"` 222 Oauth string `json:"oauth,omitempty"` 223 ComputeEndpointOverride string `json:"compute_endpoint_override,omitempty"` 224 DisableGcsLogging bool `json:"disable_gcs_logging"` 225 DisableCloudLogging bool `json:"disable_cloud_logging"` 226 DisableStdoutLogging bool `json:"disable_stdout_logging"` 227 } 228 229 // WindowsUpgradeParams contains all input params for windows upgrade 230 type WindowsUpgradeParams struct { 231 *CommonParams 232 233 SourceOS string `json:"source_os,omitempty"` 234 TargetOS string `json:"target_os,omitempty"` 235 Instance string `json:"instance,omitempty"` 236 CreateMachineBackup bool `json:"create_machine_backup"` 237 AutoRollback bool `json:"auto_rollback"` 238 UseStagingInstallMedia bool `json:"use_staging_install_media"` 239 } 240 241 // InstanceExportParams contains all input params for instance export 242 type InstanceExportParams struct { 243 *CommonParams 244 245 DestinationURI string `json:"destination_uri,omitempty"` 246 InstanceName string `json:"instance_name,omitempty"` 247 OvfFormat string `json:"ovf_format,omitempty"` 248 DiskExportFormat string `json:"disk_export_format,omitempty"` 249 NoExternalIP bool `json:"no_external_ip,omitempty"` 250 OS string `json:"os,omitempty"` 251 } 252 253 // MachineImageExportParams contains all input params for instance export 254 type MachineImageExportParams struct { 255 *CommonParams 256 257 DestinationURI string `json:"destination_uri,omitempty"` 258 MachineImageName string `json:"machine_image_name,omitempty"` 259 OvfFormat string `json:"ovf_format,omitempty"` 260 DiskExportFormat string `json:"disk_export_format,omitempty"` 261 NoExternalIP bool `json:"no_external_ip,omitempty"` 262 OS string `json:"os,omitempty"` 263 } 264 265 // OutputInfo contains output values from the tools execution 266 type OutputInfo struct { 267 // Size of import/export sources (image or file) 268 SourcesSizeGb []int64 `json:"sources_size_gb,omitempty"` 269 // Size of import/export targets (image or file) 270 TargetsSizeGb []int64 `json:"targets_size_gb,omitempty"` 271 // Failure message of the command 272 FailureMessage string `json:"failure_message,omitempty"` 273 // Failure message of the command without privacy info 274 FailureMessageWithoutPrivacyInfo string `json:"failure_message_without_privacy_info,omitempty"` 275 // ImportFileFormat shows what is the actual image format of the imported file 276 ImportFileFormat string `json:"import_file_format,omitempty"` 277 // Serial output from worker instances; only populated 278 // if workflow failed. 279 SerialOutputs []string `json:"serial_outputs,omitempty"` 280 // Inflation type (qemu, API, etc) 281 InflationType string `json:"inflation_type,omitempty"` 282 // Inflation time (seconds) 283 InflationTime []int64 `json:"inflation_time_ms,omitempty"` 284 // Inflation time (seconds) of the shadow disk 285 ShadowInflationTime []int64 `json:"shadow_inflation_time_ms,omitempty"` 286 // Shadow disk match result for shadow disk inflater 287 ShadowDiskMatchResult string `json:"shadow_disk_match_result,omitempty"` 288 // Indicates whether UEFI_COMPATIBLE was added to the image's guestOSFeatures, either due to inspection or user request 289 IsUEFICompatibleImage bool `json:"is_uefi_compatible_image,omitempty"` 290 // Indicates whether the image is auto-detected to be UEFI compatible 291 IsUEFIDetected bool `json:"is_uefi_detected,omitempty"` 292 // Inspection results. Ref to the def of `InspectionResults` for details 293 InspectionResults *pb.InspectionResults `json:"inspection_results,omitempty"` 294 // Inflation fallback reason 295 InflationFallbackReason string `json:"inflation_fallback_reason,omitempty"` 296 } 297 298 func (l *Logger) updateParams(projectPointer *string) { 299 l.mutex.Lock() 300 defer l.mutex.Unlock() 301 302 if projectPointer == nil { 303 return 304 } 305 306 project := *projectPointer 307 obfuscatedProject := Hash(project) 308 309 if l.Params.ImageImportParams != nil { 310 l.Params.ImageImportParams.CommonParams.Project = project 311 l.Params.ImageImportParams.CommonParams.ObfuscatedProject = obfuscatedProject 312 } 313 if l.Params.ImageExportParams != nil { 314 l.Params.ImageExportParams.CommonParams.Project = project 315 l.Params.ImageExportParams.CommonParams.ObfuscatedProject = obfuscatedProject 316 } 317 if l.Params.InstanceImportParams != nil { 318 l.Params.InstanceImportParams.CommonParams.Project = project 319 l.Params.InstanceImportParams.CommonParams.ObfuscatedProject = obfuscatedProject 320 } 321 if l.Params.MachineImageImportParams != nil { 322 l.Params.MachineImageImportParams.CommonParams.Project = project 323 l.Params.MachineImageImportParams.CommonParams.ObfuscatedProject = obfuscatedProject 324 } 325 if l.Params.OnestepImageImportParams != nil { 326 l.Params.OnestepImageImportParams.CommonParams.Project = project 327 l.Params.OnestepImageImportParams.CommonParams.ObfuscatedProject = obfuscatedProject 328 } 329 }