Copilot commented on code in PR #7083: URL: https://github.com/apache/opendal/pull/7083#discussion_r2639415238
########## core/layers/hotpath/src/lib.rs: ########## @@ -0,0 +1,193 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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. + +use hotpath::MeasurementGuard; +use opendal_core::raw::*; +use opendal_core::*; + +const LABEL_CREATE_DIR: &str = "opendal.create_dir"; +const LABEL_READ: &str = "opendal.read"; +const LABEL_WRITE: &str = "opendal.write"; +const LABEL_COPY: &str = "opendal.copy"; +const LABEL_RENAME: &str = "opendal.rename"; +const LABEL_STAT: &str = "opendal.stat"; +const LABEL_DELETE: &str = "opendal.delete"; +const LABEL_LIST: &str = "opendal.list"; +const LABEL_PRESIGN: &str = "opendal.presign"; + +const LABEL_READER_READ: &str = "opendal.reader.read"; +const LABEL_WRITER_WRITE: &str = "opendal.writer.write"; +const LABEL_WRITER_CLOSE: &str = "opendal.writer.close"; +const LABEL_WRITER_ABORT: &str = "opendal.writer.abort"; +const LABEL_LISTER_NEXT: &str = "opendal.lister.next"; +const LABEL_DELETER_DELETE: &str = "opendal.deleter.delete"; +const LABEL_DELETER_CLOSE: &str = "opendal.deleter.close"; + +/// Add [hotpath](https://docs.rs/hotpath/) profiling for every operation. +/// +/// # Notes +/// +/// When `hotpath` profiling is enabled, initialize a guard via +/// [`hotpath::FunctionsGuardBuilder`] or `#[hotpath::main]` before running +/// operations. Otherwise, hotpath will panic on the first measurement. +/// +/// # Examples +/// +/// ```no_run +/// # use opendal_core::services; +/// # use opendal_core::Operator; +/// # use opendal_core::Result; +/// # use opendal_layer_hotpath::HotpathLayer; +/// # +/// # #[tokio::main] +/// # async fn main() -> Result<()> { +/// let _guard = hotpath::FunctionsGuardBuilder::new("opendal").build(); +/// let op = Operator::new(services::Memory::default())? +/// .layer(HotpathLayer) +/// .finish(); +/// op.write("test", "hello").await?; +/// # Ok(()) +/// # } +/// ``` +pub struct HotpathLayer; + +impl<A: Access> Layer<A> for HotpathLayer { + type LayeredAccess = HotpathAccessor<A>; + + fn layer(&self, inner: A) -> Self::LayeredAccess { + HotpathAccessor { inner } + } +} + +#[derive(Debug)] +pub struct HotpathAccessor<A> { + inner: A, +} + +impl<A: Access> LayeredAccess for HotpathAccessor<A> { + type Inner = A; + type Reader = HotpathWrapper<A::Reader>; + type Writer = HotpathWrapper<A::Writer>; + type Lister = HotpathWrapper<A::Lister>; + type Deleter = HotpathWrapper<A::Deleter>; + + fn inner(&self) -> &Self::Inner { + &self.inner + } + + async fn create_dir(&self, path: &str, args: OpCreateDir) -> Result<RpCreateDir> { + let _guard = MeasurementGuard::build(LABEL_CREATE_DIR, false, true); + self.inner.create_dir(path, args).await + } + + async fn read(&self, path: &str, args: OpRead) -> Result<(RpRead, Self::Reader)> { + let _guard = MeasurementGuard::build(LABEL_READ, false, true); + let (rp, reader) = self.inner.read(path, args).await?; + Ok((rp, HotpathWrapper::new(reader))) + } + + async fn write(&self, path: &str, args: OpWrite) -> Result<(RpWrite, Self::Writer)> { + let _guard = MeasurementGuard::build(LABEL_WRITE, false, true); + let (rp, writer) = self.inner.write(path, args).await?; + Ok((rp, HotpathWrapper::new(writer))) + } + + async fn copy(&self, from: &str, to: &str, args: OpCopy) -> Result<RpCopy> { + let _guard = MeasurementGuard::build(LABEL_COPY, false, true); + self.inner().copy(from, to, args).await + } + + async fn rename(&self, from: &str, to: &str, args: OpRename) -> Result<RpRename> { + let _guard = MeasurementGuard::build(LABEL_RENAME, false, true); + self.inner().rename(from, to, args).await Review Comment: Inconsistent field access pattern. This uses `self.inner()` (method call) while other operations in this implementation use `self.inner` (direct field access). For consistency with lines 94, 99, 105, 121, 126, 132, and 138, this should be changed to direct field access. ```suggestion self.inner.copy(from, to, args).await } async fn rename(&self, from: &str, to: &str, args: OpRename) -> Result<RpRename> { let _guard = MeasurementGuard::build(LABEL_RENAME, false, true); self.inner.rename(from, to, args).await ``` ########## core/layers/hotpath/src/lib.rs: ########## @@ -0,0 +1,193 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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. + +use hotpath::MeasurementGuard; +use opendal_core::raw::*; +use opendal_core::*; + +const LABEL_CREATE_DIR: &str = "opendal.create_dir"; +const LABEL_READ: &str = "opendal.read"; +const LABEL_WRITE: &str = "opendal.write"; +const LABEL_COPY: &str = "opendal.copy"; +const LABEL_RENAME: &str = "opendal.rename"; +const LABEL_STAT: &str = "opendal.stat"; +const LABEL_DELETE: &str = "opendal.delete"; +const LABEL_LIST: &str = "opendal.list"; +const LABEL_PRESIGN: &str = "opendal.presign"; + +const LABEL_READER_READ: &str = "opendal.reader.read"; +const LABEL_WRITER_WRITE: &str = "opendal.writer.write"; +const LABEL_WRITER_CLOSE: &str = "opendal.writer.close"; +const LABEL_WRITER_ABORT: &str = "opendal.writer.abort"; +const LABEL_LISTER_NEXT: &str = "opendal.lister.next"; +const LABEL_DELETER_DELETE: &str = "opendal.deleter.delete"; +const LABEL_DELETER_CLOSE: &str = "opendal.deleter.close"; + +/// Add [hotpath](https://docs.rs/hotpath/) profiling for every operation. +/// +/// # Notes +/// +/// When `hotpath` profiling is enabled, initialize a guard via +/// [`hotpath::FunctionsGuardBuilder`] or `#[hotpath::main]` before running +/// operations. Otherwise, hotpath will panic on the first measurement. +/// +/// # Examples +/// +/// ```no_run +/// # use opendal_core::services; +/// # use opendal_core::Operator; +/// # use opendal_core::Result; +/// # use opendal_layer_hotpath::HotpathLayer; +/// # +/// # #[tokio::main] +/// # async fn main() -> Result<()> { +/// let _guard = hotpath::FunctionsGuardBuilder::new("opendal").build(); +/// let op = Operator::new(services::Memory::default())? +/// .layer(HotpathLayer) +/// .finish(); +/// op.write("test", "hello").await?; +/// # Ok(()) +/// # } +/// ``` +pub struct HotpathLayer; + +impl<A: Access> Layer<A> for HotpathLayer { + type LayeredAccess = HotpathAccessor<A>; + + fn layer(&self, inner: A) -> Self::LayeredAccess { + HotpathAccessor { inner } + } +} + +#[derive(Debug)] +pub struct HotpathAccessor<A> { + inner: A, +} + +impl<A: Access> LayeredAccess for HotpathAccessor<A> { + type Inner = A; + type Reader = HotpathWrapper<A::Reader>; + type Writer = HotpathWrapper<A::Writer>; + type Lister = HotpathWrapper<A::Lister>; + type Deleter = HotpathWrapper<A::Deleter>; + + fn inner(&self) -> &Self::Inner { + &self.inner + } + + async fn create_dir(&self, path: &str, args: OpCreateDir) -> Result<RpCreateDir> { + let _guard = MeasurementGuard::build(LABEL_CREATE_DIR, false, true); + self.inner.create_dir(path, args).await + } + + async fn read(&self, path: &str, args: OpRead) -> Result<(RpRead, Self::Reader)> { + let _guard = MeasurementGuard::build(LABEL_READ, false, true); + let (rp, reader) = self.inner.read(path, args).await?; + Ok((rp, HotpathWrapper::new(reader))) + } + + async fn write(&self, path: &str, args: OpWrite) -> Result<(RpWrite, Self::Writer)> { + let _guard = MeasurementGuard::build(LABEL_WRITE, false, true); + let (rp, writer) = self.inner.write(path, args).await?; + Ok((rp, HotpathWrapper::new(writer))) + } + + async fn copy(&self, from: &str, to: &str, args: OpCopy) -> Result<RpCopy> { + let _guard = MeasurementGuard::build(LABEL_COPY, false, true); + self.inner().copy(from, to, args).await + } + + async fn rename(&self, from: &str, to: &str, args: OpRename) -> Result<RpRename> { + let _guard = MeasurementGuard::build(LABEL_RENAME, false, true); + self.inner().rename(from, to, args).await Review Comment: Inconsistent field access pattern. This uses `self.inner()` (method call) while other operations in this implementation use `self.inner` (direct field access). For consistency with lines 94, 99, 105, 121, 126, 132, and 138, this should be changed to direct field access. ```suggestion self.inner.copy(from, to, args).await } async fn rename(&self, from: &str, to: &str, args: OpRename) -> Result<RpRename> { let _guard = MeasurementGuard::build(LABEL_RENAME, false, true); self.inner.rename(from, to, args).await ``` ########## core/layers/hotpath/Cargo.toml: ########## @@ -0,0 +1,38 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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] +description = "Apache OpenDAL hotpath layer" +name = "opendal-layer-hotpath" + +authors = { workspace = true } +edition = { workspace = true } +homepage = { workspace = true } +license = { workspace = true } +repository = { workspace = true } +rust-version = { workspace = true } +version = { workspace = true } + +[package.metadata.docs.rs] +all-features = true + +[dependencies] +hotpath = { version = "0.9.1", features = ["hotpath"] } Review Comment: The `features = ["hotpath"]` configuration appears to be specifying a feature with the same name as the crate itself. This is unusual and likely incorrect. The hotpath crate documentation should be consulted to verify the correct feature flag needed, or this should be removed if the default features are sufficient. ```suggestion hotpath = "0.9.1" ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
