-
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.
Signed-off-by: Kushal Shukla <kushalshukla110@gmail.com>
- Loading branch information
1 parent
c9d5111
commit 5840472
Showing
5 changed files
with
117 additions
and
106 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
FROM quay.io/prometheus/busybox:latest | ||
LABEL maintainer="The Prometheus Authors <prometheus-developers@googlegroups.com>" | ||
|
||
COPY blockSyncer /bin/blocksyncer | ||
COPY block-sync /bin/blocksyncer | ||
|
||
ENTRYPOINT ["/bin/blocksyncer"] |
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
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,87 @@ | ||
// 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" | ||
"log/slog" | ||
"os" | ||
|
||
"github.com/go-kit/log" | ||
"github.com/thanos-io/objstore" | ||
"github.com/thanos-io/objstore/client" | ||
) | ||
|
||
type Store struct { | ||
bucket objstore.Bucket | ||
tsdbpath string | ||
objectkey string | ||
objectconfig string | ||
bucketlogger *slog.Logger | ||
} | ||
|
||
func newStore(tsdbPath, objectConfig, objectKey string, logger *slog.Logger) (*Store, error) { | ||
configBytes, err := os.ReadFile(objectConfig) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to read config file: %w", err) | ||
} | ||
|
||
bucket, err := client.NewBucket(log.NewNopLogger(), configBytes, "block-sync") | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to create bucket existence:%w", err) | ||
} | ||
return &Store{ | ||
bucket: bucket, | ||
tsdbpath: tsdbPath, | ||
objectkey: objectKey, | ||
objectconfig: objectConfig, | ||
bucketlogger: logger, | ||
}, nil | ||
|
||
} | ||
|
||
func (c *Store) upload(ctx context.Context) error { | ||
exists, err := c.bucket.Exists(ctx, c.objectkey) | ||
if err != nil { | ||
return fmt.Errorf("failed to check new bucket:%w", err) | ||
} | ||
c.bucketlogger.Info("Bucket checked Successfully", "Bucket name", exists) | ||
|
||
err = objstore.UploadDir(ctx, log.NewNopLogger(), c.bucket, c.tsdbpath, c.objectkey) | ||
if err != nil { | ||
c.bucketlogger.Error("Failed to upload directory", "path", c.tsdbpath, "error", err) | ||
return fmt.Errorf("failed to upload directory from path %s to bucket: %v", c.tsdbpath, err) | ||
} | ||
|
||
c.bucketlogger.Info("Successfully uploaded directory", "path", c.tsdbpath, "bucket", c.bucket.Name()) | ||
return nil | ||
} | ||
|
||
func (c *Store) download(ctx context.Context) error { | ||
exists, err := c.bucket.Exists(ctx, c.objectkey) | ||
if err != nil { | ||
return fmt.Errorf("failed to check new bucket:%w", err) | ||
} | ||
c.bucketlogger.Info("Bucket checked Successfully", "Bucket name", exists) | ||
|
||
err = objstore.DownloadDir(ctx, log.NewNopLogger(), c.bucket, "dir/", c.objectkey, c.tsdbpath) | ||
if err != nil { | ||
c.bucketlogger.Error("Failed to download directory", "path", c.tsdbpath, "error", err) | ||
return fmt.Errorf("failed to download directory from path %s to bucket: %v", c.tsdbpath, err) | ||
} | ||
|
||
c.bucketlogger.Info("Successfully downloaded directory", "path", c.tsdbpath, "bucket", c.bucket.Name()) | ||
return nil | ||
} |
This file was deleted.
Oops, something went wrong.