-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: update config schema/examples for file_stores
Specifically, Config.Rdb_dest.file_stores. This code is untested but compiles up to the point that something outside the config tries to access the old files_path field. issue #4
- Loading branch information
Showing
7 changed files
with
97 additions
and
8 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
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
(library | ||
(name config) | ||
(libraries atdgen batteries)) | ||
(libraries atdgen batteries re re.perl)) |
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,9 @@ | ||
|
||
|
||
type max_usage = string option wrap | ||
<ocaml module="Rdb_dest.File_store.Max_usage"> | ||
|
||
type t = | ||
{ path : string | ||
; max_usage : max_usage | ||
<ocaml valid="Rdb_dest.File_store.Max_usage.validate"> } |
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 |
---|---|---|
@@ -1,7 +1,8 @@ | ||
|
||
type log_level <ocaml from="Log_level" t="t"> = abstract | ||
type file_store <ocaml from="File_store" t="t"> = abstract | ||
|
||
type t = | ||
{ files_path : string | ||
{ file_stores : file_store list | ||
; log_level : log_level | ||
; log_namespace : string } |
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,60 @@ | ||
|
||
|
||
module File_store = struct | ||
module Max_usage = struct | ||
type t = int option | ||
|
||
let valid_pattern = "^([1-9]\\d*)([kmgt])?$" |> Re.Perl.compile_pat | ||
|
||
let clean s = | ||
let separators = "[_, ]+" |> Re.Perl.compile_pat in | ||
s | ||
|> Re.replace_string separators ~by:"" | ||
|> String.lowercase_ascii | ||
|
||
let validate s = | ||
match s with | ||
| None -> true | ||
| Some s -> | ||
s |> clean |> Re.execp valid_pattern | ||
|
||
let wrap s = | ||
if not (validate s) then failwith "Invalid byte string." | ||
else | ||
|
||
match s with | ||
| None -> | ||
None | ||
|
||
| Some s -> begin | ||
let matches = s |> clean |> Re.exec valid_pattern in | ||
match matches |> Re.Group.all with | ||
| [| _; amount; "" |] -> | ||
Some (amount |> int_of_string) | ||
|
||
| [| _; amount; suffix |] -> begin | ||
let amount = amount |> int_of_string in | ||
match suffix with | ||
| "k" -> Some (amount * 1024) | ||
| "m" -> Some (amount * 1024 * 1024) | ||
| "g" -> Some (amount * 1024 * 1024 * 1024) | ||
| "t" -> Some (amount * 1024 * 1024 * 1024 * 1024) | ||
| suffix -> | ||
Printf.sprintf "Unknown suffix '%s'" suffix | ||
|> failwith | ||
end | ||
|
||
| _ -> | ||
failwith "Unexpected array structure returned from Re.Group.all" | ||
end | ||
|
||
let unwrap t = | ||
match t with | ||
| None -> | ||
None | ||
|
||
| Some b -> | ||
Some (b |> string_of_int) | ||
|
||
end | ||
end |
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