-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8db3279
commit c2e16e5
Showing
4 changed files
with
124 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.") | ||
} | ||
} |