-
Notifications
You must be signed in to change notification settings - Fork 43
Allow configuring control_plane_storage_buffer #8099
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
Open
jmpesp
wants to merge
3
commits into
oxidecomputer:main
Choose a base branch
from
jmpesp:configurable_control_plane_storage_buffer
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,23 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
use super::impl_enum_type; | ||
use nexus_db_schema::schema::setting; | ||
|
||
impl_enum_type!( | ||
SettingNameEnum: | ||
|
||
#[derive(Copy, Clone, Debug, AsExpression, FromSqlRow, PartialEq)] | ||
pub enum SettingName; | ||
|
||
// Enum values | ||
ControlPlaneStorageBuffer => b"control_plane_storage_buffer" | ||
); | ||
|
||
#[derive(Queryable, Insertable, Debug, Selectable, Clone)] | ||
#[diesel(table_name = setting)] | ||
pub struct Setting { | ||
pub name: SettingName, | ||
pub int_value: Option<i64>, | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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,97 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
//! [`DataStore`] methods on [`Setting`]s. | ||
|
||
// Settings are dynamically controlled values for Nexus | ||
|
||
use super::DataStore; | ||
use crate::authz; | ||
use crate::context::OpContext; | ||
use crate::db::datastore::ErrorHandler; | ||
use crate::db::datastore::public_error_from_diesel; | ||
use async_bb8_diesel::AsyncRunQueryDsl; | ||
use diesel::prelude::*; | ||
use nexus_db_lookup::DbConnection; | ||
use nexus_db_model::Setting; | ||
use nexus_db_model::SettingName; | ||
use omicron_common::api::external::ByteCount; | ||
use omicron_common::api::external::Error; | ||
|
||
impl DataStore { | ||
pub(crate) async fn set_control_plane_storage_buffer_gib_impl( | ||
opctx: &OpContext, | ||
conn: &async_bb8_diesel::Connection<DbConnection>, | ||
gibibytes: u32, | ||
) -> Result<(), Error> { | ||
opctx.authorize(authz::Action::Modify, &authz::FLEET).await?; | ||
|
||
use nexus_db_schema::schema::setting::dsl; | ||
|
||
let name = SettingName::ControlPlaneStorageBuffer; | ||
let value: i64 = ByteCount::from_gibibytes_u32(gibibytes).into(); | ||
|
||
let maybe_existing = | ||
Self::get_control_plane_storage_buffer_impl(opctx, conn).await?; | ||
|
||
if maybe_existing.is_some() { | ||
diesel::update(dsl::setting) | ||
.filter(dsl::name.eq(name)) | ||
.set(dsl::int_value.eq(value)) | ||
.execute_async(conn) | ||
.await | ||
.map(|_| ()) | ||
.map_err(|e| public_error_from_diesel(e, ErrorHandler::Server)) | ||
} else { | ||
let setting = Setting { name, int_value: Some(value) }; | ||
|
||
diesel::insert_into(dsl::setting) | ||
.values(setting) | ||
.execute_async(conn) | ||
.await | ||
.map(|_| ()) | ||
.map_err(|e| public_error_from_diesel(e, ErrorHandler::Server)) | ||
} | ||
} | ||
|
||
pub(crate) async fn get_control_plane_storage_buffer_impl( | ||
opctx: &OpContext, | ||
conn: &async_bb8_diesel::Connection<DbConnection>, | ||
) -> Result<Option<ByteCount>, Error> { | ||
opctx.authorize(authz::Action::Modify, &authz::FLEET).await?; | ||
|
||
use nexus_db_schema::schema::setting::dsl; | ||
|
||
let name = SettingName::ControlPlaneStorageBuffer; | ||
|
||
let result = dsl::setting | ||
.filter(dsl::name.eq(name)) | ||
.select(Setting::as_select()) | ||
.first_async(conn) | ||
.await | ||
.optional() | ||
.map_err(|e| public_error_from_diesel(e, ErrorHandler::Server))?; | ||
|
||
Ok(match result { | ||
Some(setting) => { | ||
// A row exists with this setting's name | ||
match setting.int_value { | ||
Some(value) => Some(ByteCount::try_from(value).unwrap()), | ||
|
||
None => None, | ||
} | ||
} | ||
|
||
None => None, | ||
}) | ||
} | ||
|
||
pub async fn get_control_plane_storage_buffer( | ||
&self, | ||
opctx: &OpContext, | ||
) -> Result<Option<ByteCount>, Error> { | ||
let conn = self.pool_connection_authorized(opctx).await?; | ||
Self::get_control_plane_storage_buffer_impl(opctx, &conn).await | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
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.
🚀