-
Notifications
You must be signed in to change notification settings - Fork 453
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[read_commitlog] Add summary (#4060)
- Loading branch information
Showing
3 changed files
with
207 additions
and
29 deletions.
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 |
---|---|---|
|
@@ -7,12 +7,28 @@ | |
$ git clone [email protected]:m3db/m3.git | ||
$ make read_commitlog | ||
$ ./bin/read_commitlog | ||
Usage: read_commitlog [-p value] [-f value] | ||
-p, --path=value | ||
Commitlog file path [e.g. /var/lib/m3db/commitlogs/commitlog-0-161023.db] | ||
Usage: read_commitlog [-a value] [-f value] [-p value] [-s value] [-t value] [parameters ...] | ||
-a, --action=value | ||
Action [print,summary]. Defaults to 'print' | ||
-f, --id-filter=value | ||
ID Contains Filter [e.g. xyz] | ||
ID Contains Filter (optional) | ||
-p, --path=value file path [e.g. | ||
/var/lib/m3db/commitlogs/commitlog-0-161023.db] | ||
-s, --id-size-filter=value | ||
ID Size (bytes) Filter (optional) | ||
-t, --top=value Print out only top N IDs | ||
# example usage | ||
# read_commitlog -p /var/lib/m3db/commitlogs/commitlog-0-161023.db -f 'metric-name' > /tmp/sample-data.out | ||
# Examples. | ||
# get all datapoints for a given metric | ||
$ read_commitlog -p /var/lib/m3db/commitlogs/commitlog-0-161023.db -f 'metric-name' | ||
# get summary about commit log file | ||
$ read_commitlog -p /var/lib/m3db/commitlogs/commitlog-0-161023.db -a summary | ||
# get summary about commit log file including top 100 largest and most frequent IDs | ||
$ read_commitlog -p /var/lib/m3db/commitlogs/commitlog-0-161023.db -a summary -t 100 | ||
# get summary about commit log file including only IDs above 1000 bytes | ||
$ read_commitlog -p /var/lib/m3db/commitlogs/commitlog-0-161023.db -a summary -s 1000 | ||
``` |
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,74 @@ | ||
// Copyright (c) 2022 Uber Technologies, Inc. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
package main | ||
|
||
import ( | ||
"errors" | ||
"io" | ||
"log" | ||
"strings" | ||
|
||
"github.com/m3db/m3/src/dbnode/persist/fs/commitlog" | ||
) | ||
|
||
type filteringReader struct { | ||
reader commitlog.Reader | ||
idFilter *string | ||
idSizeFilter *int | ||
} | ||
|
||
func newFilteringReader(path string, idFilter *string, idSizeFilter *int) (*filteringReader, error) { | ||
opts := commitlog.NewReaderOptions(commitlog.NewOptions(), false) | ||
reader := commitlog.NewReader(opts) | ||
if _, err := reader.Open(path); err != nil { | ||
return nil, err | ||
} | ||
return &filteringReader{reader: reader, idFilter: idFilter, idSizeFilter: idSizeFilter}, nil | ||
} | ||
|
||
func (c *filteringReader) Read() (commitlog.LogEntry, bool, error) { | ||
for { | ||
entry, err := c.reader.Read() | ||
if errors.Is(err, io.EOF) { | ||
break | ||
} | ||
if err != nil { | ||
return commitlog.LogEntry{}, false, err | ||
} | ||
series := entry.Series | ||
if *c.idFilter != "" && !strings.Contains(series.ID.String(), *c.idFilter) { | ||
continue | ||
} | ||
if *c.idSizeFilter != 0 && len(series.ID.Bytes()) < *c.idSizeFilter { | ||
continue | ||
} | ||
return entry, true, nil | ||
} | ||
return commitlog.LogEntry{}, false, nil | ||
} | ||
|
||
func (c *filteringReader) Close() { | ||
if c != nil && c.reader != nil { | ||
if err := c.reader.Close(); err != nil { | ||
log.Fatalf("unable to close reader: %v", err) | ||
} | ||
} | ||
} |
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