Skip to content

Commit 9d23241

Browse files
committed
update timestamps
1 parent 4a5b652 commit 9d23241

File tree

1 file changed

+31
-17
lines changed

1 file changed

+31
-17
lines changed

main.go

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"math"
1010
"net/http"
1111
"os"
12-
"path/filepath"
12+
1313
"strconv"
1414
"time"
1515

@@ -179,22 +179,36 @@ func loadConfig(path string) (Config, error) {
179179

180180
// uploadToS3 uploads data to the specified S3 bucket with a timestamped key
181181
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
198212
}
199213

200214
// processValue handles different types of protobuf values and updates Prometheus metrics

0 commit comments

Comments
 (0)