-
Notifications
You must be signed in to change notification settings - Fork 15
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
f8eec02
commit a69a099
Showing
8 changed files
with
513 additions
and
102 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
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
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,72 @@ | ||
// Copyright 2024 The Accumulate Authors | ||
// | ||
// Use of this source code is governed by an MIT-style | ||
// license that can be found in the LICENSE file or at | ||
// https://opensource.org/licenses/MIT. | ||
|
||
package run | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"sync" | ||
"time" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/prometheus/prometheus/scrape" | ||
"github.com/prometheus/prometheus/storage/remote" | ||
"gitlab.com/accumulatenetwork/accumulate/pkg/errors" | ||
"golang.org/x/exp/slog" | ||
) | ||
|
||
func (p *PushMetrics) start(inst *Instance) error { | ||
if p == nil || p.Url == "" { | ||
return nil | ||
} | ||
|
||
setDefaultVal(&p.WalDirectory, filepath.Join(os.TempDir(), "prom-push-wal")) | ||
setDefaultVal(&p.ScrapeInterval, time.Minute) | ||
setDefaultVal(&p.RemoteFlushDeadline, time.Minute) | ||
|
||
// NOTE: Local querying (read-write storage instead of write-only storage) | ||
// would require a local TSDB | ||
|
||
logger := log4prom{*inst.logger.With("module", "metrics")} | ||
scrapeMgr := new(deferred[*scrape.Manager]) | ||
storage := remote.NewWriteStorage(logger, prometheus.DefaultRegisterer, p.WalDirectory, p.RemoteFlushDeadline, scrapeMgr) | ||
|
||
_ = storage | ||
return nil | ||
} | ||
|
||
type log4prom struct { | ||
slog slog.Logger | ||
} | ||
|
||
func (l log4prom) Log(keyvals ...interface{}) error { | ||
l.slog.Info("", keyvals...) | ||
return nil | ||
} | ||
|
||
type deferred[T any] struct { | ||
mu sync.RWMutex | ||
val T | ||
ready bool | ||
} | ||
|
||
func (d *deferred[T]) Set(v T) { | ||
d.mu.Lock() | ||
defer d.mu.Unlock() | ||
d.val, d.ready = v, true | ||
} | ||
|
||
func (d *deferred[T]) Get() (T, error) { | ||
d.mu.RLock() | ||
defer d.mu.RUnlock() | ||
if !d.ready { | ||
var z T | ||
return z, errors.NotReady | ||
} | ||
return d.val, nil | ||
|
||
} |
Oops, something went wrong.