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

Experimental command for the plugin to show the state of exclusions #1133

Merged
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
2 changes: 2 additions & 0 deletions api/v1beta2/foundationdb_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ type FoundationDBStatusProcessInfo struct {
type FoundationDBStatusProcessRoleInfo struct {
// Role defines the role a process currently has
Role string `json:"role,omitempty"`
// StoredBytes defines the number of bytes that are currently stored for this process.
StoredBytes int `json:"stored_bytes,omitempty"`
}

// FoundationDBStatusDataStatistics provides information about the data in
Expand Down
13 changes: 2 additions & 11 deletions fdbclient/admin_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func (client *cliAdminClient) GetStatus() (*fdbv1beta2.FoundationDBStatus, error
return nil, err
}
client.log.V(1).Info("Fetched status JSON", "contents", contents)
contents, err = removeWarningsInJSON(contents)
contents, err = internal.RemoveWarningsInJSON(contents)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -628,7 +628,7 @@ func (client *cliAdminClient) GetBackupStatus() (*fdbv1beta2.FoundationDBLiveBac
}

status := &fdbv1beta2.FoundationDBLiveBackupStatus{}
statusString, err = removeWarningsInJSON(statusString)
statusString, err = internal.RemoveWarningsInJSON(statusString)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -685,15 +685,6 @@ func (client *cliAdminClient) Close() error {
return nil
}

func removeWarningsInJSON(jsonString string) (string, error) {
idx := strings.Index(jsonString, "{")
if idx == -1 {
return "", fmt.Errorf("the JSON string doesn't contain a starting '{'")
}

return strings.TrimSpace(jsonString[idx:]), nil
}

// GetCoordinatorSet gets the current coordinators from the status
func (client *cliAdminClient) GetCoordinatorSet() (map[string]struct{}, error) {
status, err := client.GetStatus()
Expand Down
50 changes: 0 additions & 50 deletions fdbclient/admin_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
package fdbclient

import (
"fmt"
"net"

fdbv1beta2 "github.com/FoundationDB/fdb-kubernetes-operator/api/v1beta2"
Expand Down Expand Up @@ -102,55 +101,6 @@ var _ = Describe("admin_client_test", func() {
})
})

When("Removing warnings in JSON", func() {
type testCase struct {
input string
expected string
expectedErr error
}

DescribeTable("Test remove warnings in JSON string",
func(tc testCase) {
result, err := removeWarningsInJSON(tc.input)
// We need the if statement to make ginkgo happy:
// Refusing to compare <nil> to <nil>.
// Be explicit and use BeNil() instead.
// This is to avoid mistakes where both sides of an assertion are erroneously uninitialized.
// ¯\_(ツ)_/¯
if tc.expectedErr == nil {
Expect(err).To(BeNil())
} else {
Expect(err).To(Equal(tc.expectedErr))
}
Expect(result).To(Equal(tc.expected))
},
Entry("Valid JSON without warning",
testCase{
input: "{}",
expected: "{}",
expectedErr: nil,
},
),
Entry("Valid JSON with warning",
testCase{
input: `
# Warning Slow response

{}`,
expected: "{}",
expectedErr: nil,
},
),
Entry("Invalid JSON",
testCase{
input: "}",
expected: "",
expectedErr: fmt.Errorf("the JSON string doesn't contain a starting '{'"),
},
),
)
})

When("getting the excluded and remaining processes", func() {
addr1 := fdbv1beta2.NewProcessAddress(net.ParseIP("127.0.0.1"), "", 0, nil)
addr2 := fdbv1beta2.NewProcessAddress(net.ParseIP("127.0.0.2"), "", 0, nil)
Expand Down
37 changes: 37 additions & 0 deletions internal/fdb_status_helper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* fdb_status_helper.go
*
* This source file is part of the FoundationDB open source project
*
* Copyright 2022 Apple Inc. and the FoundationDB project 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 internal

import (
"fmt"
"strings"
)

// RemoveWarningsInJSON removes any warning messages that might appear in the status output from the fdbcli and returns
// the JSON output without the warning message.
func RemoveWarningsInJSON(jsonString string) (string, error) {
idx := strings.Index(jsonString, "{")
if idx == -1 {
return "", fmt.Errorf("the JSON string doesn't contain a starting '{'")
}

return strings.TrimSpace(jsonString[idx:]), nil
}
80 changes: 80 additions & 0 deletions internal/fdb_status_helper_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* fdb_status_helper_test.go
*
* This source file is part of the FoundationDB open source project
*
* Copyright 2022 Apple Inc. and the FoundationDB project 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 internal

import (
"fmt"

. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/extensions/table"
. "github.com/onsi/gomega"
)

var _ = Describe("fdb_status_helper_test", func() {
When("Removing warnings in JSON", func() {
type testCase struct {
input string
expected string
expectedErr error
}

DescribeTable("Test remove warnings in JSON string",
func(tc testCase) {
result, err := RemoveWarningsInJSON(tc.input)
// We need the if statement to make ginkgo happy:
// Refusing to compare <nil> to <nil>.
// Be explicit and use BeNil() instead.
// This is to avoid mistakes where both sides of an assertion are erroneously uninitialized.
// ¯\_(ツ)_/¯
if tc.expectedErr == nil {
Expect(err).To(BeNil())
} else {
Expect(err).To(Equal(tc.expectedErr))
}
Expect(result).To(Equal(tc.expected))
},
Entry("Valid JSON without warning",
testCase{
input: "{}",
expected: "{}",
expectedErr: nil,
},
),
Entry("Valid JSON with warning",
testCase{
input: `
# Warning Slow response

{}`,
expected: "{}",
expectedErr: nil,
},
),
Entry("Invalid JSON",
testCase{
input: "}",
expected: "",
expectedErr: fmt.Errorf("the JSON string doesn't contain a starting '{'"),
},
),
)
})
})
Loading