2019-05-17 02:29:49 -07: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 (
|
|
|
|
"io/ioutil"
|
2019-12-12 12:47:23 -08:00
|
|
|
"net/url"
|
2019-05-17 02:29:49 -07:00
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
2019-12-12 12:47:23 -08:00
|
|
|
common_config "github.com/prometheus/common/config"
|
2020-10-29 02:43:23 -07:00
|
|
|
"github.com/stretchr/testify/require"
|
2020-10-22 02:00:08 -07:00
|
|
|
|
2019-05-17 02:29:49 -07:00
|
|
|
"github.com/prometheus/prometheus/config"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestStorageLifecycle(t *testing.T) {
|
|
|
|
dir, err := ioutil.TempDir("", "TestStorageLifecycle")
|
2020-10-29 02:43:23 -07:00
|
|
|
require.NoError(t, err)
|
2019-05-17 02:29:49 -07:00
|
|
|
defer os.RemoveAll(dir)
|
|
|
|
|
2020-02-03 13:47:03 -08:00
|
|
|
s := NewStorage(nil, nil, nil, dir, defaultFlushDeadline)
|
2019-05-17 02:29:49 -07:00
|
|
|
conf := &config.Config{
|
|
|
|
GlobalConfig: config.DefaultGlobalConfig,
|
|
|
|
RemoteWriteConfigs: []*config.RemoteWriteConfig{
|
|
|
|
&config.DefaultRemoteWriteConfig,
|
|
|
|
},
|
|
|
|
RemoteReadConfigs: []*config.RemoteReadConfig{
|
|
|
|
&config.DefaultRemoteReadConfig,
|
|
|
|
},
|
|
|
|
}
|
2019-12-12 12:47:23 -08:00
|
|
|
// We need to set URL's so that metric creation doesn't panic.
|
|
|
|
conf.RemoteWriteConfigs[0].URL = &common_config.URL{
|
|
|
|
URL: &url.URL{
|
|
|
|
Host: "http://test-storage.com",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
conf.RemoteReadConfigs[0].URL = &common_config.URL{
|
|
|
|
URL: &url.URL{
|
|
|
|
Host: "http://test-storage.com",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-10-29 02:43:23 -07:00
|
|
|
require.NoError(t, s.ApplyConfig(conf))
|
2019-05-17 02:29:49 -07:00
|
|
|
|
|
|
|
// make sure remote write has a queue.
|
2020-10-29 02:43:23 -07:00
|
|
|
require.Equal(t, 1, len(s.rws.queues))
|
2019-05-17 02:29:49 -07:00
|
|
|
|
|
|
|
// make sure remote write has a queue.
|
2020-10-29 02:43:23 -07:00
|
|
|
require.Equal(t, 1, len(s.queryables))
|
2019-05-17 02:29:49 -07:00
|
|
|
|
|
|
|
err = s.Close()
|
2020-10-29 02:43:23 -07:00
|
|
|
require.NoError(t, err)
|
2019-05-17 02:29:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestUpdateRemoteReadConfigs(t *testing.T) {
|
|
|
|
dir, err := ioutil.TempDir("", "TestUpdateRemoteReadConfigs")
|
2020-10-29 02:43:23 -07:00
|
|
|
require.NoError(t, err)
|
2019-05-17 02:29:49 -07:00
|
|
|
defer os.RemoveAll(dir)
|
|
|
|
|
2020-02-03 13:47:03 -08:00
|
|
|
s := NewStorage(nil, nil, nil, dir, defaultFlushDeadline)
|
2019-05-17 02:29:49 -07:00
|
|
|
|
|
|
|
conf := &config.Config{
|
|
|
|
GlobalConfig: config.GlobalConfig{},
|
|
|
|
}
|
2020-10-29 02:43:23 -07:00
|
|
|
require.NoError(t, s.ApplyConfig(conf))
|
|
|
|
require.Equal(t, 0, len(s.queryables))
|
2019-05-17 02:29:49 -07:00
|
|
|
|
|
|
|
conf.RemoteReadConfigs = []*config.RemoteReadConfig{
|
|
|
|
&config.DefaultRemoteReadConfig,
|
|
|
|
}
|
2020-10-29 02:43:23 -07:00
|
|
|
require.NoError(t, s.ApplyConfig(conf))
|
|
|
|
require.Equal(t, 1, len(s.queryables))
|
2019-05-17 02:29:49 -07:00
|
|
|
|
|
|
|
err = s.Close()
|
2020-10-29 02:43:23 -07:00
|
|
|
require.NoError(t, err)
|
2019-05-17 02:29:49 -07:00
|
|
|
}
|