github.com/muhammadn/cortex@v1.9.1-0.20220510110439-46bb7000d03d/pkg/configs/db/traced.go (about)

     1  package db
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  
     7  	"github.com/cortexproject/cortex/pkg/configs/userconfig"
     8  	util_log "github.com/cortexproject/cortex/pkg/util/log"
     9  
    10  	"github.com/go-kit/log/level"
    11  )
    12  
    13  // traced adds log trace lines on each db call
    14  type traced struct {
    15  	d DB
    16  }
    17  
    18  func (t traced) trace(name string, args ...interface{}) {
    19  	level.Debug(util_log.Logger).Log("msg", fmt.Sprintf("%s: %#v", name, args))
    20  }
    21  
    22  func (t traced) GetConfig(ctx context.Context, userID string) (cfg userconfig.View, err error) {
    23  	defer func() { t.trace("GetConfig", userID, cfg, err) }()
    24  	return t.d.GetConfig(ctx, userID)
    25  }
    26  
    27  func (t traced) SetConfig(ctx context.Context, userID string, cfg userconfig.Config) (err error) {
    28  	defer func() { t.trace("SetConfig", userID, cfg, err) }()
    29  	return t.d.SetConfig(ctx, userID, cfg)
    30  }
    31  
    32  func (t traced) GetAllConfigs(ctx context.Context) (cfgs map[string]userconfig.View, err error) {
    33  	defer func() { t.trace("GetAllConfigs", cfgs, err) }()
    34  	return t.d.GetAllConfigs(ctx)
    35  }
    36  
    37  func (t traced) GetConfigs(ctx context.Context, since userconfig.ID) (cfgs map[string]userconfig.View, err error) {
    38  	defer func() { t.trace("GetConfigs", since, cfgs, err) }()
    39  	return t.d.GetConfigs(ctx, since)
    40  }
    41  
    42  func (t traced) DeactivateConfig(ctx context.Context, userID string) (err error) {
    43  	defer func() { t.trace("DeactivateConfig", userID, err) }()
    44  	return t.d.DeactivateConfig(ctx, userID)
    45  }
    46  
    47  func (t traced) RestoreConfig(ctx context.Context, userID string) (err error) {
    48  	defer func() { t.trace("RestoreConfig", userID, err) }()
    49  	return t.d.RestoreConfig(ctx, userID)
    50  }
    51  
    52  func (t traced) Close() (err error) {
    53  	defer func() { t.trace("Close", err) }()
    54  	return t.d.Close()
    55  }
    56  
    57  func (t traced) GetRulesConfig(ctx context.Context, userID string) (cfg userconfig.VersionedRulesConfig, err error) {
    58  	defer func() { t.trace("GetRulesConfig", userID, cfg, err) }()
    59  	return t.d.GetRulesConfig(ctx, userID)
    60  }
    61  
    62  func (t traced) SetRulesConfig(ctx context.Context, userID string, oldCfg, newCfg userconfig.RulesConfig) (updated bool, err error) {
    63  	defer func() { t.trace("SetRulesConfig", userID, oldCfg, newCfg, updated, err) }()
    64  	return t.d.SetRulesConfig(ctx, userID, oldCfg, newCfg)
    65  }
    66  
    67  func (t traced) GetAllRulesConfigs(ctx context.Context) (cfgs map[string]userconfig.VersionedRulesConfig, err error) {
    68  	defer func() { t.trace("GetAllRulesConfigs", cfgs, err) }()
    69  	return t.d.GetAllRulesConfigs(ctx)
    70  }
    71  
    72  func (t traced) GetRulesConfigs(ctx context.Context, since userconfig.ID) (cfgs map[string]userconfig.VersionedRulesConfig, err error) {
    73  	defer func() { t.trace("GetConfigs", since, cfgs, err) }()
    74  	return t.d.GetRulesConfigs(ctx, since)
    75  }