Skip to content

Commit

Permalink
Remove some unused Cortex vendored code and metrics (thanos-io#6440)
Browse files Browse the repository at this point in the history
  • Loading branch information
yeya24 authored Jun 13, 2023
1 parent a0b37fd commit 0651f33
Show file tree
Hide file tree
Showing 11 changed files with 0 additions and 332 deletions.
6 changes: 0 additions & 6 deletions internal/cortex/chunk/cache/fifo_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ import (
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"

"github.com/thanos-io/thanos/internal/cortex/util/flagext"
util_log "github.com/thanos-io/thanos/internal/cortex/util/log"
)

const (
Expand Down Expand Up @@ -96,10 +93,7 @@ type cacheEntry struct {

// NewFifoCache returns a new initialised FifoCache of size.
func NewFifoCache(name string, cfg FifoCacheConfig, reg prometheus.Registerer, logger log.Logger) *FifoCache {
util_log.WarnExperimentalUse("In-memory (FIFO) cache")

if cfg.DeprecatedSize > 0 {
flagext.DeprecatedFlagsUsed.Inc()
level.Warn(logger).Log("msg", "running with DEPRECATED flag fifocache.size, use fifocache.max-size-items or fifocache.max-size-bytes instead", "cache", name)
cfg.MaxSizeItems = cfg.DeprecatedSize
}
Expand Down
2 changes: 0 additions & 2 deletions internal/cortex/chunk/cache/memcached_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/sony/gobreaker"
util_log "github.com/thanos-io/thanos/internal/cortex/util/log"
"github.com/thanos-io/thanos/pkg/discovery/dns"
)

Expand Down Expand Up @@ -146,7 +145,6 @@ func NewMemcachedClient(cfg MemcachedClientConfig, name string, r prometheus.Reg
}

if len(cfg.Addresses) > 0 {
util_log.WarnExperimentalUse("DNS-based memcached service discovery")
newClient.addresses = strings.Split(cfg.Addresses, ",")
}

Expand Down
2 changes: 0 additions & 2 deletions internal/cortex/chunk/cache/redis_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/prometheus/client_golang/prometheus/promauto"
instr "github.com/weaveworks/common/instrument"

util_log "github.com/thanos-io/thanos/internal/cortex/util/log"
"github.com/thanos-io/thanos/internal/cortex/util/spanlogger"
)

Expand All @@ -27,7 +26,6 @@ type RedisCache struct {

// NewRedisCache creates a new RedisCache
func NewRedisCache(name string, redisClient *RedisClient, reg prometheus.Registerer, logger log.Logger) *RedisCache {
util_log.WarnExperimentalUse("Redis cache")
cache := &RedisCache{
name: name,
redis: redisClient,
Expand Down
99 changes: 0 additions & 99 deletions internal/cortex/cortexpb/compat.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ import (

jsoniter "github.com/json-iterator/go"
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/model/exemplar"
"github.com/prometheus/prometheus/model/labels"
"github.com/prometheus/prometheus/model/textparse"

"github.com/thanos-io/thanos/internal/cortex/util"
)

Expand All @@ -32,47 +29,6 @@ func FromLabelAdaptersToLabels(ls []LabelAdapter) labels.Labels {
return *(*labels.Labels)(unsafe.Pointer(&ls))
}

// FromLabelAdaptersToLabelsWithCopy converts []LabelAdapter to labels.Labels.
// Do NOT use unsafe to convert between data types because this function may
// get in input labels whose data structure is reused.
func FromLabelAdaptersToLabelsWithCopy(input []LabelAdapter) labels.Labels {
return CopyLabels(FromLabelAdaptersToLabels(input))
}

// Efficiently copies labels input slice. To be used in cases where input slice
// can be reused, but long-term copy is needed.
func CopyLabels(input []labels.Label) labels.Labels {
result := make(labels.Labels, len(input))

size := 0
for _, l := range input {
size += len(l.Name)
size += len(l.Value)
}

// Copy all strings into the buffer, and use 'yoloString' to convert buffer
// slices to strings.
buf := make([]byte, size)

for i, l := range input {
result[i].Name, buf = copyStringToBuffer(l.Name, buf)
result[i].Value, buf = copyStringToBuffer(l.Value, buf)
}
return result
}

// Copies string to buffer (which must be big enough), and converts buffer slice containing
// the string copy into new string.
func copyStringToBuffer(in string, buf []byte) (string, []byte) {
l := len(in)
c := copy(buf, in)
if c != l {
panic("not copied full string")
}

return yoloString(buf[0:l]), buf[l:]
}

// FromLabelsToLabelAdapters casts labels.Labels to []LabelAdapter.
// It uses unsafe, but as LabelAdapter == labels.Label this should be safe.
// This allows us to use labels.Labels directly in protos.
Expand All @@ -86,12 +42,6 @@ func FromLabelAdaptersToMetric(ls []LabelAdapter) model.Metric {
return util.LabelsToMetric(FromLabelAdaptersToLabels(ls))
}

// FromLabelAdaptersToMetric converts []LabelAdapter to a model.Metric with copy.
// Don't do this on any performance sensitive paths.
func FromLabelAdaptersToMetricWithCopy(ls []LabelAdapter) model.Metric {
return util.LabelsToMetric(FromLabelAdaptersToLabelsWithCopy(ls))
}

// FromMetricsToLabelAdapters converts model.Metric to []LabelAdapter.
// Don't do this on any performance sensitive paths.
// The result is sorted.
Expand All @@ -107,61 +57,12 @@ func FromMetricsToLabelAdapters(metric model.Metric) []LabelAdapter {
return result
}

func FromExemplarsToExemplarProtos(es []exemplar.Exemplar) []Exemplar {
result := make([]Exemplar, 0, len(es))
for _, e := range es {
result = append(result, Exemplar{
Labels: FromLabelsToLabelAdapters(e.Labels),
Value: e.Value,
TimestampMs: e.Ts,
})
}
return result
}

func FromExemplarProtosToExemplars(es []Exemplar) []exemplar.Exemplar {
result := make([]exemplar.Exemplar, 0, len(es))
for _, e := range es {
result = append(result, exemplar.Exemplar{
Labels: FromLabelAdaptersToLabels(e.Labels),
Value: e.Value,
Ts: e.TimestampMs,
})
}
return result
}

type byLabel []LabelAdapter

func (s byLabel) Len() int { return len(s) }
func (s byLabel) Less(i, j int) bool { return strings.Compare(s[i].Name, s[j].Name) < 0 }
func (s byLabel) Swap(i, j int) { s[i], s[j] = s[j], s[i] }

// MetricMetadataMetricTypeToMetricType converts a metric type from our internal client
// to a Prometheus one.
func MetricMetadataMetricTypeToMetricType(mt MetricMetadata_MetricType) textparse.MetricType {
switch mt {
case UNKNOWN:
return textparse.MetricTypeUnknown
case COUNTER:
return textparse.MetricTypeCounter
case GAUGE:
return textparse.MetricTypeGauge
case HISTOGRAM:
return textparse.MetricTypeHistogram
case GAUGEHISTOGRAM:
return textparse.MetricTypeGaugeHistogram
case SUMMARY:
return textparse.MetricTypeSummary
case INFO:
return textparse.MetricTypeInfo
case STATESET:
return textparse.MetricTypeStateset
default:
return textparse.MetricTypeUnknown
}
}

// isTesting is only set from tests to get special behaviour to verify that custom sample encode and decode is used,
// both when using jsonitor or standard json package.
var isTesting = false
Expand Down
4 changes: 0 additions & 4 deletions internal/cortex/cortexpb/cortex.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 0 additions & 29 deletions internal/cortex/cortexpb/timeseries.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,37 +276,8 @@ func PreallocTimeseriesSliceFromPool() []PreallocTimeseries {
return slicePool.Get().([]PreallocTimeseries)
}

// ReuseSlice puts the slice back into a sync.Pool for reuse.
func ReuseSlice(ts []PreallocTimeseries) {
for i := range ts {
ReuseTimeseries(ts[i].TimeSeries)
}

slicePool.Put(ts[:0]) //nolint:staticcheck //see comment on slicePool for more details
}

// TimeseriesFromPool retrieves a pointer to a TimeSeries from a sync.Pool.
// ReuseTimeseries should be called once done, unless ReuseSlice was called on the slice that contains this TimeSeries.
func TimeseriesFromPool() *TimeSeries {
return timeSeriesPool.Get().(*TimeSeries)
}

// ReuseTimeseries puts the timeseries back into a sync.Pool for reuse.
func ReuseTimeseries(ts *TimeSeries) {
// Name and Value may point into a large gRPC buffer, so clear the reference to allow GC
for i := 0; i < len(ts.Labels); i++ {
ts.Labels[i].Name = ""
ts.Labels[i].Value = ""
}
ts.Labels = ts.Labels[:0]
ts.Samples = ts.Samples[:0]
// Name and Value may point into a large gRPC buffer, so clear the reference in each exemplar to allow GC
for i := range ts.Exemplars {
for j := range ts.Exemplars[i].Labels {
ts.Exemplars[i].Labels[j].Name = ""
ts.Exemplars[i].Labels[j].Value = ""
}
}
ts.Exemplars = ts.Exemplars[:0]
timeSeriesPool.Put(ts)
}
4 changes: 0 additions & 4 deletions internal/cortex/querier/queryrange/results_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ import (
"github.com/thanos-io/thanos/internal/cortex/cortexpb"
"github.com/thanos-io/thanos/internal/cortex/querier"
"github.com/thanos-io/thanos/internal/cortex/tenant"
"github.com/thanos-io/thanos/internal/cortex/util/flagext"
util_log "github.com/thanos-io/thanos/internal/cortex/util/log"
"github.com/thanos-io/thanos/internal/cortex/util/spanlogger"
"github.com/thanos-io/thanos/internal/cortex/util/validation"
)
Expand Down Expand Up @@ -62,8 +60,6 @@ func (cfg *ResultsCacheConfig) RegisterFlags(f *flag.FlagSet) {

f.StringVar(&cfg.Compression, "frontend.compression", "", "Use compression in results cache. Supported values are: 'snappy' and '' (disable compression).")
f.BoolVar(&cfg.CacheQueryableSamplesStats, "frontend.cache-queryable-samples-stats", false, "Cache Statistics queryable samples on results cache.")
//lint:ignore faillint Need to pass the global logger like this for warning on deprecated methods
flagext.DeprecatedFlag(f, "frontend.cache-split-interval", "Deprecated: The maximum interval expected for each request, results will be cached per single interval. This behavior is now determined by querier.split-queries-by-interval.", util_log.Logger)
}

func (cfg *ResultsCacheConfig) Validate(qCfg querier.Config) error {
Expand Down
40 changes: 0 additions & 40 deletions internal/cortex/util/flagext/deprecated.go

This file was deleted.

7 changes: 0 additions & 7 deletions internal/cortex/util/flagext/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@ type Registerer interface {
RegisterFlags(*flag.FlagSet)
}

// RegisterFlags registers flags with the provided Registerers
func RegisterFlags(rs ...Registerer) {
for _, r := range rs {
r.RegisterFlags(flag.CommandLine)
}
}

// DefaultValues initiates a set of configs (Registerers) with their defaults.
func DefaultValues(rs ...Registerer) {
fs := flag.NewFlagSet("", flag.PanicOnError)
Expand Down
24 changes: 0 additions & 24 deletions internal/cortex/util/log/experimental.go

This file was deleted.

Loading

0 comments on commit 0651f33

Please sign in to comment.