2019-05-17 09:29:49 +00:00
|
|
|
// Copyright 2019 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 remote
|
|
|
|
|
|
|
|
import (
|
2019-12-12 20:47:23 +00:00
|
|
|
"net/url"
|
2019-05-17 09:29:49 +00:00
|
|
|
"testing"
|
|
|
|
|
2019-12-12 20:47:23 +00:00
|
|
|
common_config "github.com/prometheus/common/config"
|
2020-10-29 09:43:23 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2020-10-22 09:00:08 +00:00
|
|
|
|
2019-05-17 09:29:49 +00:00
|
|
|
"github.com/prometheus/prometheus/config"
|
2022-02-16 21:12:47 +00:00
|
|
|
"github.com/prometheus/prometheus/model/labels"
|
2019-05-17 09:29:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestStorageLifecycle(t *testing.T) {
|
2021-11-19 20:21:45 +00:00
|
|
|
dir := t.TempDir()
|
2019-05-17 09:29:49 +00:00
|
|
|
|
2020-11-19 15:23:03 +00:00
|
|
|
s := NewStorage(nil, nil, nil, dir, defaultFlushDeadline, nil)
|
2019-05-17 09:29:49 +00:00
|
|
|
conf := &config.Config{
|
|
|
|
GlobalConfig: config.DefaultGlobalConfig,
|
|
|
|
RemoteWriteConfigs: []*config.RemoteWriteConfig{
|
2022-06-30 16:20:16 +00:00
|
|
|
// We need to set URL's so that metric creation doesn't panic.
|
|
|
|
baseRemoteWriteConfig("http://test-storage.com"),
|
2019-05-17 09:29:49 +00:00
|
|
|
},
|
|
|
|
RemoteReadConfigs: []*config.RemoteReadConfig{
|
2022-06-30 16:20:16 +00:00
|
|
|
baseRemoteReadConfig("http://test-storage.com"),
|
2019-12-12 20:47:23 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-10-29 09:43:23 +00:00
|
|
|
require.NoError(t, s.ApplyConfig(conf))
|
2019-05-17 09:29:49 +00:00
|
|
|
|
|
|
|
// make sure remote write has a queue.
|
2020-10-29 09:43:23 +00:00
|
|
|
require.Equal(t, 1, len(s.rws.queues))
|
2019-05-17 09:29:49 +00:00
|
|
|
|
|
|
|
// make sure remote write has a queue.
|
2020-10-29 09:43:23 +00:00
|
|
|
require.Equal(t, 1, len(s.queryables))
|
2019-05-17 09:29:49 +00:00
|
|
|
|
2021-11-19 20:21:45 +00:00
|
|
|
err := s.Close()
|
2020-10-29 09:43:23 +00:00
|
|
|
require.NoError(t, err)
|
2019-05-17 09:29:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestUpdateRemoteReadConfigs(t *testing.T) {
|
2021-11-19 20:21:45 +00:00
|
|
|
dir := t.TempDir()
|
2019-05-17 09:29:49 +00:00
|
|
|
|
2020-11-19 15:23:03 +00:00
|
|
|
s := NewStorage(nil, nil, nil, dir, defaultFlushDeadline, nil)
|
2019-05-17 09:29:49 +00:00
|
|
|
|
|
|
|
conf := &config.Config{
|
|
|
|
GlobalConfig: config.GlobalConfig{},
|
|
|
|
}
|
2020-10-29 09:43:23 +00:00
|
|
|
require.NoError(t, s.ApplyConfig(conf))
|
|
|
|
require.Equal(t, 0, len(s.queryables))
|
2019-05-17 09:29:49 +00:00
|
|
|
|
|
|
|
conf.RemoteReadConfigs = []*config.RemoteReadConfig{
|
2022-06-30 16:20:16 +00:00
|
|
|
baseRemoteReadConfig("http://test-storage.com"),
|
2019-05-17 09:29:49 +00:00
|
|
|
}
|
2020-10-29 09:43:23 +00:00
|
|
|
require.NoError(t, s.ApplyConfig(conf))
|
|
|
|
require.Equal(t, 1, len(s.queryables))
|
2019-05-17 09:29:49 +00:00
|
|
|
|
2021-11-19 20:21:45 +00:00
|
|
|
err := s.Close()
|
2020-10-29 09:43:23 +00:00
|
|
|
require.NoError(t, err)
|
2019-05-17 09:29:49 +00:00
|
|
|
}
|
2022-02-16 21:12:47 +00:00
|
|
|
|
|
|
|
func TestFilterExternalLabels(t *testing.T) {
|
|
|
|
dir := t.TempDir()
|
|
|
|
|
|
|
|
s := NewStorage(nil, nil, nil, dir, defaultFlushDeadline, nil)
|
|
|
|
|
|
|
|
conf := &config.Config{
|
|
|
|
GlobalConfig: config.GlobalConfig{
|
|
|
|
ExternalLabels: labels.Labels{labels.Label{Name: "foo", Value: "bar"}},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
require.NoError(t, s.ApplyConfig(conf))
|
|
|
|
require.Equal(t, 0, len(s.queryables))
|
|
|
|
|
|
|
|
conf.RemoteReadConfigs = []*config.RemoteReadConfig{
|
2022-06-30 16:20:16 +00:00
|
|
|
baseRemoteReadConfig("http://test-storage.com"),
|
2022-02-16 21:12:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
require.NoError(t, s.ApplyConfig(conf))
|
|
|
|
require.Equal(t, 1, len(s.queryables))
|
|
|
|
require.Equal(t, 1, len(s.queryables[0].(*sampleAndChunkQueryableClient).externalLabels))
|
|
|
|
|
|
|
|
err := s.Close()
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestIgnoreExternalLabels(t *testing.T) {
|
|
|
|
dir := t.TempDir()
|
|
|
|
|
|
|
|
s := NewStorage(nil, nil, nil, dir, defaultFlushDeadline, nil)
|
|
|
|
|
|
|
|
conf := &config.Config{
|
|
|
|
GlobalConfig: config.GlobalConfig{
|
|
|
|
ExternalLabels: labels.Labels{labels.Label{Name: "foo", Value: "bar"}},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
require.NoError(t, s.ApplyConfig(conf))
|
|
|
|
require.Equal(t, 0, len(s.queryables))
|
|
|
|
|
|
|
|
conf.RemoteReadConfigs = []*config.RemoteReadConfig{
|
2022-06-30 16:20:16 +00:00
|
|
|
baseRemoteReadConfig("http://test-storage.com"),
|
2022-02-16 21:12:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
conf.RemoteReadConfigs[0].FilterExternalLabels = false
|
|
|
|
|
|
|
|
require.NoError(t, s.ApplyConfig(conf))
|
|
|
|
require.Equal(t, 1, len(s.queryables))
|
|
|
|
require.Equal(t, 0, len(s.queryables[0].(*sampleAndChunkQueryableClient).externalLabels))
|
|
|
|
|
|
|
|
err := s.Close()
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
2022-06-30 16:20:16 +00:00
|
|
|
|
|
|
|
// baseRemoteWriteConfig copy values from global Default Write config
|
|
|
|
// to avoid change global state and cross impact test execution
|
|
|
|
func baseRemoteWriteConfig(host string) *config.RemoteWriteConfig {
|
|
|
|
cfg := config.DefaultRemoteWriteConfig
|
|
|
|
cfg.URL = &common_config.URL{
|
|
|
|
URL: &url.URL{
|
|
|
|
Host: host,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
return &cfg
|
|
|
|
}
|
|
|
|
|
|
|
|
// baseRemoteReadConfig copy values from global Default Read config
|
|
|
|
// to avoid change global state and cross impact test execution
|
|
|
|
func baseRemoteReadConfig(host string) *config.RemoteReadConfig {
|
|
|
|
cfg := config.DefaultRemoteReadConfig
|
|
|
|
cfg.URL = &common_config.URL{
|
|
|
|
URL: &url.URL{
|
|
|
|
Host: host,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
return &cfg
|
|
|
|
}
|