-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[metrics] Add io-metrics for paimon in Flink #5550
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
zhuanshenbsj1
wants to merge
8
commits into
apache:master
Choose a base branch
from
zhuanshenbsj1:metrics
base: master
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
8 commits
Select commit
Hold shift + click to select a range
56ad764
io metrics
zhuanshenbsj1 dbc85be
adjust
zhuanshenbsj1 efba2d1
add uts
zhuanshenbsj1 3492665
fix ut errors
zhuanshenbsj1 3f9df52
update metrics
zhuanshenbsj1 cb6f130
add reset for lazystore
zhuanshenbsj1 dea2c5c
update comments
zhuanshenbsj1 73a49d4
add utils && optimize uts
zhuanshenbsj1 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
110 changes: 110 additions & 0 deletions
110
paimon-common/src/main/java/org/apache/paimon/fs/MetricsFileIO.java
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,110 @@ | ||
/* | ||
* 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 org.apache.paimon.fs; | ||
|
||
import org.apache.paimon.annotation.VisibleForTesting; | ||
import org.apache.paimon.catalog.CatalogContext; | ||
import org.apache.paimon.fs.metrics.IOMetrics; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* MetricsFileIO is a wrapper class for the {@link FileIO}. | ||
* | ||
* <p>It allows users to monitor and track file I/O operations. | ||
*/ | ||
public class MetricsFileIO implements FileIO { | ||
|
||
protected final FileIO fileIO; | ||
protected IOMetrics ioMetrics = null; | ||
|
||
public MetricsFileIO(FileIO fileIO) { | ||
this.fileIO = fileIO; | ||
} | ||
|
||
public MetricsFileIO withMetrics(IOMetrics ioMetrics) { | ||
this.ioMetrics = ioMetrics; | ||
return this; | ||
} | ||
|
||
public FileIO getFileIOInternal() { | ||
FileIO currentFileIO = fileIO; | ||
while (currentFileIO instanceof MetricsFileIO) { | ||
currentFileIO = ((MetricsFileIO) currentFileIO).fileIO; | ||
} | ||
return currentFileIO; | ||
} | ||
|
||
@VisibleForTesting | ||
public Boolean isMetricsEnabled() { | ||
return ioMetrics != null; | ||
} | ||
|
||
@Override | ||
public boolean isObjectStore() { | ||
return fileIO.isObjectStore(); | ||
} | ||
|
||
@Override | ||
public void configure(CatalogContext context) { | ||
fileIO.configure(context); | ||
} | ||
|
||
@Override | ||
public SeekableInputStream newInputStream(Path path) throws IOException { | ||
SeekableInputStream inputStream = fileIO.newInputStream(path); | ||
return new SeekableInputStreamIOWrapper(inputStream, this.ioMetrics); | ||
} | ||
|
||
@Override | ||
public PositionOutputStream newOutputStream(Path path, boolean overwrite) throws IOException { | ||
PositionOutputStream outputStream = fileIO.newOutputStream(path, overwrite); | ||
return new PositionOutputStreamIOWrapper(outputStream, this.ioMetrics); | ||
} | ||
|
||
@Override | ||
public FileStatus getFileStatus(Path path) throws IOException { | ||
return fileIO.getFileStatus(path); | ||
} | ||
|
||
@Override | ||
public FileStatus[] listStatus(Path path) throws IOException { | ||
return fileIO.listStatus(path); | ||
} | ||
|
||
@Override | ||
public boolean exists(Path path) throws IOException { | ||
return fileIO.exists(path); | ||
} | ||
|
||
@Override | ||
public boolean delete(Path path, boolean recursive) throws IOException { | ||
return fileIO.delete(path, recursive); | ||
} | ||
|
||
@Override | ||
public boolean mkdirs(Path path) throws IOException { | ||
return fileIO.mkdirs(path); | ||
} | ||
|
||
@Override | ||
public boolean rename(Path src, Path dst) throws IOException { | ||
return fileIO.rename(src, dst); | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
paimon-common/src/main/java/org/apache/paimon/fs/PositionOutputStreamIOWrapper.java
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,83 @@ | ||
/* | ||
* 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 org.apache.paimon.fs; | ||
|
||
import org.apache.paimon.fs.metrics.IOMetrics; | ||
|
||
import java.io.IOException; | ||
|
||
/** Wrap a {@link PositionOutputStream}. */ | ||
public class PositionOutputStreamIOWrapper extends PositionOutputStream { | ||
|
||
protected final PositionOutputStream out; | ||
private IOMetrics metrics; | ||
|
||
public PositionOutputStreamIOWrapper(PositionOutputStream out, IOMetrics metrics) { | ||
this.out = out; | ||
this.metrics = metrics; | ||
} | ||
|
||
@Override | ||
public long getPos() throws IOException { | ||
return out.getPos(); | ||
} | ||
|
||
@Override | ||
public void write(int b) throws IOException { | ||
try { | ||
out.write(b); | ||
} finally { | ||
if (metrics != null) { | ||
metrics.recordWriteEvent(1); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void write(byte[] b) throws IOException { | ||
try { | ||
out.write(b); | ||
} finally { | ||
if (metrics != null) { | ||
metrics.recordWriteEvent(b.length); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void write(byte[] b, int off, int len) throws IOException { | ||
try { | ||
out.write(b, off, len); | ||
} finally { | ||
if (metrics != null) { | ||
metrics.recordWriteEvent(len); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void flush() throws IOException { | ||
out.flush(); | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
out.close(); | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
paimon-common/src/main/java/org/apache/paimon/fs/SeekableInputStreamIOWrapper.java
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,96 @@ | ||
/* | ||
* 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 org.apache.paimon.fs; | ||
|
||
import org.apache.paimon.fs.metrics.IOMetrics; | ||
|
||
import java.io.IOException; | ||
|
||
/** Wrap a {@link SeekableInputStream}. */ | ||
public class SeekableInputStreamIOWrapper extends SeekableInputStream implements VectoredReadable { | ||
|
||
protected final SeekableInputStream in; | ||
private IOMetrics metrics; | ||
|
||
public SeekableInputStreamIOWrapper(SeekableInputStream in, IOMetrics metrics) { | ||
this.in = in; | ||
this.metrics = metrics; | ||
} | ||
|
||
@Override | ||
public void seek(long desired) throws IOException { | ||
in.seek(desired); | ||
} | ||
|
||
@Override | ||
public long getPos() throws IOException { | ||
return in.getPos(); | ||
} | ||
|
||
@Override | ||
public int read() throws IOException { | ||
int bytesRead = 0; | ||
try { | ||
bytesRead = in.read(); | ||
} finally { | ||
if (metrics != null && bytesRead != -1) { | ||
metrics.recordReadEvent(bytesRead); | ||
} | ||
} | ||
return bytesRead; | ||
} | ||
|
||
@Override | ||
public int read(byte[] b, int off, int len) throws IOException { | ||
int bytesRead = 0; | ||
try { | ||
bytesRead = in.read(b, off, len); | ||
} finally { | ||
if (metrics != null && bytesRead != -1) { | ||
metrics.recordReadEvent(bytesRead); | ||
} | ||
} | ||
return bytesRead; | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
in.close(); | ||
} | ||
|
||
@Override | ||
public int pread(long position, byte[] buffer, int offset, int length) throws IOException { | ||
int bytesRead = 0; | ||
try { | ||
if (in instanceof VectoredReadable) { | ||
bytesRead = ((VectoredReadable) in).pread(position, buffer, offset, length); | ||
} else { | ||
long originalPos = in.getPos(); | ||
in.seek(position); | ||
bytesRead = in.read(buffer, offset, length); | ||
in.seek(originalPos); | ||
} | ||
} finally { | ||
if (metrics != null && bytesRead != -1) { | ||
metrics.recordReadEvent(bytesRead); | ||
} | ||
} | ||
return bytesRead; | ||
} | ||
} |
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.
Please remove this dep
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.
I moved some metrics classes from paimon-core to paimon-common project, and the class DescriptiveStatisticsHistogram depends on this.