Skip to content

Commit

Permalink
fix: type mismatch in TidbMonitor remoteTimeout (#5734)
Browse files Browse the repository at this point in the history
* change remoteTimeout type in pingcap.com_tidbmonitors.yaml

* fix remoteTimeout tests
  • Loading branch information
IMMORTALxJO authored Dec 10, 2024
1 parent a5bce17 commit f56e7d9
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 23 deletions.
2 changes: 1 addition & 1 deletion docs/api-references/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -14251,7 +14251,7 @@ Only valid in Prometheus versions 2.15.0 and newer.</p>
<td>
<code>remoteTimeout</code></br>
<em>
github.com/prometheus/common/model.Duration
string
</em>
</td>
<td>
Expand Down
4 changes: 2 additions & 2 deletions manifests/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51296,8 +51296,8 @@ spec:
type: integer
type: object
remoteTimeout:
format: int64
type: integer
pattern: ^\d+[smhd]$
type: string
tlsConfig:
properties:
ca:
Expand Down
4 changes: 2 additions & 2 deletions manifests/crd/v1/pingcap.com_tidbmonitors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1891,8 +1891,8 @@ spec:
type: integer
type: object
remoteTimeout:
format: int64
type: integer
pattern: ^\d+[smhd]$
type: string
tlsConfig:
properties:
ca:
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/pingcap/v1alpha1/openapi_generated.go

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

3 changes: 2 additions & 1 deletion pkg/apis/pingcap/v1alpha1/tidbmonitor_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,9 @@ type RemoteWriteSpec struct {
// Only valid in Prometheus versions 2.15.0 and newer.
// +optional
Name string `json:"name,omitempty"`
// +kubebuilder:validation:Pattern=`^\d+[smhd]$`
// +optional
RemoteTimeout *model.Duration `json:"remoteTimeout,omitempty"`
RemoteTimeout string `json:"remoteTimeout,omitempty"`
// The list of remote write relabel configurations.
// +optional
WriteRelabelConfigs []RelabelConfig `json:"writeRelabelConfigs,omitempty"`
Expand Down
5 changes: 0 additions & 5 deletions pkg/apis/pingcap/v1alpha1/zz_generated.deepcopy.go

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

4 changes: 2 additions & 2 deletions pkg/monitor/monitor/monitor_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,13 @@ func TestTidbMonitorSyncCreate(t *testing.T) {
g.Expect(err).NotTo(HaveOccurred())

url := "http://127.0.0.1/a/b/c"
remoteTimeout := model.Duration(30 * time.Second)
remoteTimeout := "30s"
testTime := 10 * time.Second
monitor.Spec.Prometheus.RemoteWrite = []*v1alpha1.RemoteWriteSpec{
{
URL: url,
Name: "test",
RemoteTimeout: &remoteTimeout,
RemoteTimeout: remoteTimeout,
WriteRelabelConfigs: []v1alpha1.RelabelConfig{
{
SourceLabels: []model.LabelName{"test1", "test2"},
Expand Down
6 changes: 2 additions & 4 deletions pkg/monitor/monitor/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"sort"
"strconv"
"strings"
"time"

semver "github.com/Masterminds/semver"
"github.com/pingcap/tidb-operator/pkg/apis/label"
Expand Down Expand Up @@ -1487,9 +1486,8 @@ func generateRemoteWrite(monitor *v1alpha1.TidbMonitor, store *Store) (yaml.MapI
}
for i, spec := range monitor.Spec.Prometheus.RemoteWrite {
//defaults
if spec.RemoteTimeout == nil {
duration := model.Duration(30 * time.Second)
spec.RemoteTimeout = &duration
if spec.RemoteTimeout == "" {
spec.RemoteTimeout = "30s"
}

cfg := yaml.MapSlice{
Expand Down
8 changes: 4 additions & 4 deletions pkg/monitor/monitor/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestGenerateRemoteWrite(t *testing.T) {
max_backoff: 10s
`
url := "http://127.0.0.1/a/b/c"
remoteTimeout := model.Duration(30 * time.Second)
remoteTimeout := "30s"
testTime := 10 * time.Second
monitor := v1alpha1.TidbMonitor{
Spec: v1alpha1.TidbMonitorSpec{
Expand All @@ -65,7 +65,7 @@ func TestGenerateRemoteWrite(t *testing.T) {
{
URL: url,
Name: "test",
RemoteTimeout: &remoteTimeout,
RemoteTimeout: remoteTimeout,
WriteRelabelConfigs: []v1alpha1.RelabelConfig{
{
SourceLabels: []model.LabelName{"test1", "test2"},
Expand Down Expand Up @@ -161,7 +161,7 @@ func TestGenerateRemoteWriteWithHighVersion(t *testing.T) {
send_interval: 10s
`
url := "http://127.0.0.1/a/b/c"
remoteTimeout := model.Duration(30 * time.Second)
remoteTimeout := "30s"
testTime := 10 * time.Second
monitor := v1alpha1.TidbMonitor{
Spec: v1alpha1.TidbMonitorSpec{
Expand All @@ -170,7 +170,7 @@ func TestGenerateRemoteWriteWithHighVersion(t *testing.T) {
{
URL: url,
Name: "test",
RemoteTimeout: &remoteTimeout,
RemoteTimeout: remoteTimeout,
WriteRelabelConfigs: []v1alpha1.RelabelConfig{
{
SourceLabels: []model.LabelName{"test1", "test2"},
Expand Down

0 comments on commit f56e7d9

Please sign in to comment.