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