Skip to content

Commit

Permalink
Updated code for upload and download
Browse files Browse the repository at this point in the history
  • Loading branch information
kushalShukla-web committed Sep 27, 2024
1 parent f4a2e1f commit 93ab7c4
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 91 deletions.
5 changes: 3 additions & 2 deletions tools/object-storage/obj.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ func main() {
Objstore := app.Command("block-sync", `Using Thanos to store the data`)
Objstore.Flag("path", "Path for The TSDB data in prometheus").Required().StringVar(&s.TsdbPath)
Objstore.Flag("objstore.config-file", "Path for The Config file").Required().StringVar(&s.ObjectConfig)
Objstore.Flag("key", "Path for the Key where to store block data").StringVar(&s.ObjectKey)
Objstore.Command("upload", "Uploading data").Action(s.Upload)
Objstore.Flag("key", "Path for the Key where to store block data").Required().StringVar(&s.ObjectKey)
Objstore.Command("upload", "Uploading data").Action(s.upload)
Objstore.Command("download", "Downloading data").Action(s.download)
kingpin.MustParse(app.Parse(os.Args[1:]))
}
89 changes: 0 additions & 89 deletions tools/object-storage/upload.go

This file was deleted.

77 changes: 77 additions & 0 deletions tools/object-storage/upload_download.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package main

import (
"context"
"fmt"

// "io"
"os"

"github.com/go-kit/log"
"github.com/thanos-io/objstore"
"github.com/thanos-io/objstore/client"
"gopkg.in/alecthomas/kingpin.v2"
)

type Store struct {
TsdbPath string
ObjectKey string
ObjectConfig string
}

func newstore() *Store {
return &Store{
TsdbPath: "",
ObjectKey: "",
ObjectConfig: "",
}
}

func (c *Store) upload(*kingpin.ParseContext) error {
config := c.ObjectConfig
configBytes, err := os.ReadFile(config)
if err != nil {
panic(fmt.Errorf("failed to read config file: %v", err))
}
commitDir := c.ObjectKey

bucket, err := client.NewBucket(log.NewNopLogger(), configBytes, "example")
if err != nil {
panic(err)
}
exists, err := bucket.Exists(context.Background(), "example")
if err != nil {
panic(err)
}
fmt.Println(exists)

err = objstore.UploadDir(context.Background(), log.NewNopLogger(), bucket, c.TsdbPath, commitDir)
if err != nil {
panic(err)
}
return nil
}

func (c *Store) download(*kingpin.ParseContext) error {
config := c.ObjectConfig
configBytes, err := os.ReadFile(config)
if err != nil {
panic(fmt.Errorf("failed to read config file: %v", err))
}
commitDir := c.ObjectKey
bucket, err := client.NewBucket(log.NewNopLogger(), configBytes, "example")
if err != nil {
panic(err)
}
exists, err := bucket.Exists(context.Background(), "example")
if err != nil {
return fmt.Errorf("failed to create bucket: %v", err)
}
fmt.Println(exists)

err = objstore.DownloadDir(context.Background(), log.NewNopLogger(), bucket, "dir/", commitDir, c.TsdbPath)
if err != nil {
return fmt.Errorf("failed to download directory: %v", err)
}
return nil
}

0 comments on commit 93ab7c4

Please sign in to comment.