-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
[vtadmin-web] Display shard state on Tablets view + extract tablet utilities #7999
Merged
ajm188
merged 2 commits into
vitessio:master
from
tinyspeck:sarabee-vtadmin-web-tablet-utils
Apr 30, 2021
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* Copyright 2021 The Vitess 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. | ||
*/ | ||
|
||
import { Pip, PipState } from './Pip'; | ||
|
||
interface Props { | ||
// If shard status is still pending, a neutral pip is used. | ||
// The distinction between "is loading" and "is_master_serving is undefined" | ||
// is useful, as it's common for the shard `shard.is_master_serving` to be | ||
// excluded from API responses for non-serving shards (instead of being | ||
// explicitly false.) | ||
isLoading?: boolean | null | undefined; | ||
isServing?: boolean | null | undefined; | ||
} | ||
|
||
export const ShardServingPip = ({ isLoading, isServing }: Props) => { | ||
let state: PipState = isServing ? 'success' : 'danger'; | ||
return <Pip state={isLoading ? null : state} />; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* Copyright 2021 The Vitess 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. | ||
*/ | ||
import { invertBy } from 'lodash-es'; | ||
import { topodata, vtadmin as pb } from '../proto/vtadmin'; | ||
|
||
/** | ||
* TABLET_TYPES maps numeric tablet types back to human readable strings. | ||
* Note that topodata.TabletType allows duplicate values: specifically, | ||
* both RDONLY (new name) and BATCH (old name) share the same numeric value. | ||
* So, we make the assumption that if there are duplicate keys, we will | ||
* always take the first value. | ||
*/ | ||
export const TABLET_TYPES = Object.entries(invertBy(topodata.TabletType)).reduce((acc, [k, vs]) => { | ||
acc[k] = vs[0]; | ||
return acc; | ||
}, {} as { [k: string]: string }); | ||
|
||
/** | ||
* formatAlias formats a tablet.alias object as a single string, The Vitess Way™. | ||
*/ | ||
export const formatAlias = <T extends pb.ITablet>(t: T) => | ||
t.tablet?.alias?.cell && t.tablet?.alias?.uid ? `${t.tablet.alias.cell}-${t.tablet.alias.uid}` : null; | ||
|
||
export const formatType = (t: pb.Tablet) => t.tablet?.type && TABLET_TYPES[t.tablet?.type]; | ||
|
||
export const formatDisplayType = (t: pb.Tablet) => { | ||
const tt = formatType(t); | ||
return tt === 'MASTER' ? 'PRIMARY' : tt; | ||
}; | ||
|
||
export const SERVING_STATES = Object.keys(pb.Tablet.ServingState); | ||
|
||
export const formatState = (t: pb.Tablet) => t.state && SERVING_STATES[t.state]; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it will make your life easier (or more pleasant!) I'm pretty sure we can change the JSON marshaling in the http adapter to not omit fields with zero values
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh that's good to know! Definitely not a blocker but seems useful for boolean + numeric values... perhaps one day I will change it, but in the meantime it doesn't really matter much. I made a card anyway: https://github.com/vitessio/vitess/projects/12#card-60142070 😎
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(That said, this made me think of a small change I want to make, so I'll do that real quick.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
......... okay, so I did the change and it turns out I like it way less, so I think this is fine to merge as-is. Once this unit test passes anyway, haha.