Skip to content

Commit

Permalink
Object storage Bucket
Browse files Browse the repository at this point in the history
  • Loading branch information
kushalShukla-web committed Sep 24, 2024
1 parent 8db3279 commit c2e16e5
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 1 deletion.
9 changes: 9 additions & 0 deletions infra/infra.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/prometheus/test-infra/pkg/provider/eks"
"github.com/prometheus/test-infra/pkg/provider/gke"
"github.com/prometheus/test-infra/pkg/provider/kind"
"github.com/prometheus/test-infra/pkg/provider/store"
)

func main() {
Expand All @@ -42,6 +43,11 @@ func main() {
Short('v').
StringMapVar(&dr.FlagDeploymentVars)

// Storing Data on Object Store
Objstore := app.Command("block-sync", `Using Thanos to store the data`)
Objstore.Flag("path", "Path for The TSDB data in prometheus").Required().StringVar(&store.S.TsdbPath)
Objstore.Flag("objstore.config-file", "Path for The Config file").Required().StringVar(&store.S.ObjectConfig)

g := gke.New(dr)
k8sGKE := app.Command("gke", `Google container engine provider - https://cloud.google.com/kubernetes-engine/`).
Action(g.SetupDeploymentResources)
Expand Down Expand Up @@ -158,5 +164,8 @@ func main() {
app.Usage(os.Args[1:])
os.Exit(2)
}
fmt.Println(store.S.TsdbPath, "Hello from Tsdbpath")
fmt.Println(store.S.ObjectConfig)
fmt.Println(store.S, "Camerabobo")

}
61 changes: 61 additions & 0 deletions pkg/provider/store/object_store.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright 2024 The Prometheus Authors
// 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 store

import (
"context"

"fmt"
"os"
"path/filepath"

"github.com/thanos-io/objstore"
)

type Store struct {
TsdbPath string
ObjectKey string
ObjectConfig string
}

var S Store

func UploadTSDBFiles(bucket objstore.Bucket, tsdbPath string) error {
err := filepath.Walk(tsdbPath, func(filePath string, info os.FileInfo, err error) error {
if err != nil {
return err
}

if info.IsDir() {
return nil
}

objectKey := filepath.Base(filePath)

file, err := os.Open(filePath)
if err != nil {
return fmt.Errorf("failed to open file %s: %v", filePath, err)
}
defer file.Close()

if err := bucket.Upload(context.Background(), objectKey, file); err != nil {
return fmt.Errorf("failed to upload file %s: %v", objectKey, err)
}

fmt.Printf("Uploaded file: %s\n", objectKey)
return nil
})

return err
}
3 changes: 2 additions & 1 deletion tools/load-generator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,10 @@ func (q *Querier) run(wg *sync.WaitGroup) {
}
}

// understand from here query function
func (q *Querier) query(expr string) {
queryCount.WithLabelValues(q.target, q.name, expr, q.qtype).Inc()
start := time.Now()
start := time.Date(2023, time.September, 15, 10, 30, 0, 0, time.UTC)

req, err := http.NewRequest("GET", q.url, nil)
if err != nil {
Expand Down
52 changes: 52 additions & 0 deletions tools/object-storage/obj.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright 2024 The Prometheus Authors
// 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 main

import (
"context"
"fmt"
"os"

"github.com/go-kit/log"
"github.com/prometheus/test-infra/pkg/provider/store"
"github.com/thanos-io/objstore/client"
)

func main() {
config := store.S.ObjectConfig
fmt.Println(config)
fmt.Println(store.S)
configBytes, err := os.ReadFile(config)
if err != nil {
panic(fmt.Errorf("failed to read config file: %v", err))
}

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 = store.UploadTSDBFiles(bucket, store.S.TsdbPath)

if err != nil {
fmt.Printf("Failed to upload TSDB files: %v\n", err)
} else {
fmt.Println("TSDB files successfully uploaded to object store.")
}
}

0 comments on commit c2e16e5

Please sign in to comment.