|
9 | 9 | "math" |
10 | 10 | "net/http" |
11 | 11 | "os" |
12 | | - "path/filepath" |
| 12 | + |
13 | 13 | "strconv" |
14 | 14 | "time" |
15 | 15 |
|
@@ -179,22 +179,36 @@ func loadConfig(path string) (Config, error) { |
179 | 179 |
|
180 | 180 | // uploadToS3 uploads data to the specified S3 bucket with a timestamped key |
181 | 181 | func uploadToS3(s3Svc *s3.S3, bucket string, data []byte) error { |
182 | | - timestamp := time.Now().Format("2006/01/02/15-04-05.000") |
183 | | - key := filepath.Join(timestamp, "data.json") |
184 | | - |
185 | | - input := &s3.PutObjectInput{ |
186 | | - Bucket: aws.String(bucket), |
187 | | - Key: aws.String(key), |
188 | | - Body: bytes.NewReader(data), |
189 | | - } |
190 | | - |
191 | | - _, err := s3Svc.PutObject(input) |
192 | | - if err != nil { |
193 | | - return fmt.Errorf("failed to upload to S3 at key '%s': %w", key, err) |
194 | | - } |
195 | | - |
196 | | - log.Printf("Successfully uploaded data to S3 at key: %s", key) |
197 | | - return nil |
| 182 | + // Generate current time in UTC with microsecond precision |
| 183 | + now := time.Now().UTC() |
| 184 | + timestamp := now.Format("20060102T150405.000000Z") // Format: YYYYMMDDTHHMMSS.microsecondsZ |
| 185 | + |
| 186 | + // Define key structure based on the timestamp |
| 187 | + // Example: 2024/04/27/15/30/45/20240427T153045.123456Z.json |
| 188 | + key := fmt.Sprintf("%04d/%02d/%02d/%s.json", |
| 189 | + now.Year(), |
| 190 | + now.Month(), |
| 191 | + now.Day(), |
| 192 | + timestamp, |
| 193 | + ) |
| 194 | + |
| 195 | + // Prepare the S3 PutObject input |
| 196 | + input := &s3.PutObjectInput{ |
| 197 | + Bucket: aws.String(bucket), |
| 198 | + Key: aws.String(key), |
| 199 | + Body: bytes.NewReader(data), |
| 200 | + // Optionally, set ContentType and other metadata |
| 201 | + ContentType: aws.String("application/json"), |
| 202 | + } |
| 203 | + |
| 204 | + // Upload the object to S3 |
| 205 | + _, err := s3Svc.PutObject(input) |
| 206 | + if err != nil { |
| 207 | + return fmt.Errorf("failed to upload to S3 at key '%s': %w", key, err) |
| 208 | + } |
| 209 | + |
| 210 | + log.Printf("Successfully uploaded data to S3 at key: %s", key) |
| 211 | + return nil |
198 | 212 | } |
199 | 213 |
|
200 | 214 | // processValue handles different types of protobuf values and updates Prometheus metrics |
|
0 commit comments