Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove some unused Cortex vendored code and metrics #6440

Merged
merged 3 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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