| 106 | } |
| 107 | |
| 108 | func appendMetrics(root string, artifact *Artifact) error { |
| 109 | entry := struct { |
| 110 | GeneratedAt string `json:"generated_at"` |
| 111 | Branch string `json:"branch"` |
| 112 | BaseRef string `json:"base_ref"` |
| 113 | PrefixHash string `json:"prefix_hash"` |
| 114 | DeltaHash string `json:"delta_hash"` |
| 115 | CombinedHash string `json:"combined_hash"` |
| 116 | Metrics CacheMetrics `json:"metrics"` |
| 117 | }{ |
| 118 | GeneratedAt: artifact.GeneratedAt.Format("2006-01-02T15:04:05Z07:00"), |
| 119 | Branch: artifact.Branch, |
| 120 | BaseRef: artifact.BaseRef, |
| 121 | PrefixHash: artifact.PrefixHash, |
| 122 | DeltaHash: artifact.DeltaHash, |
| 123 | CombinedHash: artifact.CombinedHash, |
| 124 | Metrics: artifact.Metrics, |
| 125 | } |
| 126 | |
| 127 | data, err := json.Marshal(entry) |
| 128 | if err != nil { |
| 129 | return err |
| 130 | } |
| 131 | |
| 132 | f, err := os.OpenFile(MetricsPath(root), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) |
| 133 | if err != nil { |
| 134 | return err |
| 135 | } |
| 136 | defer f.Close() |
| 137 | |
| 138 | if _, err := f.Write(append(data, '\n')); err != nil { |
| 139 | return err |
| 140 | } |
| 141 | return capMetricsLog(root, maxMetricsLines) |
| 142 | } |
| 143 | |
| 144 | func normalizeArtifact(artifact *Artifact) { |
| 145 | ensureSchemaVersion(artifact) |