Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
picodata
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
core
picodata
Commits
dd483d7b
Commit
dd483d7b
authored
1 year ago
by
Georgy Moshkin
Browse files
Options
Downloads
Patches
Plain Diff
feat: config.yaml: move instance.log* parameters to a instance.log subsection
parent
f7806c72
No related branches found
No related tags found
1 merge request
!907
Gmoshkin/config.yaml more box cfg parameters
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/config.rs
+51
-8
51 additions, 8 deletions
src/config.rs
src/tarantool.rs
+3
-1
3 additions, 1 deletion
src/tarantool.rs
test/int/test_config_file.py
+59
-2
59 additions, 2 deletions
test/int/test_config_file.py
with
113 additions
and
11 deletions
src/config.rs
+
51
−
8
View file @
dd483d7b
...
@@ -219,11 +219,11 @@ Using configuration file '{args_path}'.");
...
@@ -219,11 +219,11 @@ Using configuration file '{args_path}'.");
}
}
if
let
Some
(
log_level
)
=
args
.log_level
{
if
let
Some
(
log_level
)
=
args
.log_level
{
self
.instance.log
_
level
=
Some
(
log_level
);
self
.instance.log
.
level
=
Some
(
log_level
);
}
}
if
let
Some
(
log_destination
)
=
args
.log
{
if
let
Some
(
log_destination
)
=
args
.log
{
self
.instance.log
=
Some
(
log_destination
);
self
.instance.log
.destination
=
Some
(
log_destination
);
}
}
if
let
Some
(
audit_destination
)
=
args
.audit
{
if
let
Some
(
audit_destination
)
=
args
.audit
{
...
@@ -614,9 +614,6 @@ pub struct InstanceConfig {
...
@@ -614,9 +614,6 @@ pub struct InstanceConfig {
pub
deprecated_script
:
Option
<
String
>
,
pub
deprecated_script
:
Option
<
String
>
,
pub
audit
:
Option
<
String
>
,
pub
audit
:
Option
<
String
>
,
pub
log_level
:
Option
<
args
::
LogLevel
>
,
pub
log
:
Option
<
String
>
,
pub
log_format
:
Option
<
String
>
,
// box.cfg.background currently doesn't work with our supervisor/child implementation
// box.cfg.background currently doesn't work with our supervisor/child implementation
// pub background: Option<bool>,
// pub background: Option<bool>,
...
@@ -628,6 +625,10 @@ pub struct InstanceConfig {
...
@@ -628,6 +625,10 @@ pub struct InstanceConfig {
pub
memtx_memory
:
Option
<
u64
>
,
pub
memtx_memory
:
Option
<
u64
>
,
#[serde(default)]
#[introspection(nested)]
pub
log
:
LogSection
,
/// Special catch-all field which will be filled by serde with all unknown
/// Special catch-all field which will be filled by serde with all unknown
/// fields from the yaml file.
/// fields from the yaml file.
#[serde(flatten)]
#[serde(flatten)]
...
@@ -706,7 +707,7 @@ impl InstanceConfig {
...
@@ -706,7 +707,7 @@ impl InstanceConfig {
#[inline]
#[inline]
pub
fn
log_level
(
&
self
)
->
SayLevel
{
pub
fn
log_level
(
&
self
)
->
SayLevel
{
if
let
Some
(
level
)
=
self
.log
_
level
{
if
let
Some
(
level
)
=
self
.log
.
level
{
level
.into
()
level
.into
()
}
else
{
}
else
{
SayLevel
::
Info
SayLevel
::
Info
...
@@ -724,6 +725,48 @@ impl InstanceConfig {
...
@@ -724,6 +725,48 @@ impl InstanceConfig {
}
}
}
}
////////////////////////////////////////////////////////////////////////////////
// LogSection
////////////////////////////////////////////////////////////////////////////////
#[derive(
PartialEq,
Default,
Debug,
Clone,
serde::Deserialize,
serde::Serialize,
tlua::Push,
tlua::PushInto,
Introspection,
)]
#[serde(deny_unknown_fields)]
pub
struct
LogSection
{
pub
level
:
Option
<
args
::
LogLevel
>
,
/// By default, Picodata sends the log to the standard error stream
/// (stderr). If `log.destination` is specified, Picodata can send the log to a:
/// - file
/// - pipe
/// - system logger
pub
destination
:
Option
<
String
>
,
pub
format
:
Option
<
LogFormat
>
,
}
tarantool
::
define_str_enum!
{
#[derive(Default)]
pub
enum
LogFormat
{
#[default]
Plain
=
"plain"
,
Json
=
"json"
,
}
}
////////////////////////////////////////////////////////////////////////////////
// deserialize_map_forbid_duplicate_keys
////////////////////////////////////////////////////////////////////////////////
pub
fn
deserialize_map_forbid_duplicate_keys
<
'de
,
D
,
K
,
V
>
(
pub
fn
deserialize_map_forbid_duplicate_keys
<
'de
,
D
,
K
,
V
>
(
des
:
D
,
des
:
D
,
)
->
Result
<
HashMap
<
K
,
V
>
,
D
::
Error
>
)
->
Result
<
HashMap
<
K
,
V
>
,
D
::
Error
>
...
@@ -1299,13 +1342,13 @@ instance:
...
@@ -1299,13 +1342,13 @@ instance:
);
);
let
mut
config
=
PicodataConfig
::
read_yaml_contents
(
&
yaml
)
.unwrap
();
let
mut
config
=
PicodataConfig
::
read_yaml_contents
(
&
yaml
)
.unwrap
();
let
args
=
args
::
Run
::
try_parse_from
([
"run"
,
let
args
=
args
::
Run
::
try_parse_from
([
"run"
,
"-c"
,
" instance.log
_
level =debug "
,
"-c"
,
" instance.log
.
level =debug "
,
"--config-parameter"
,
"instance. memtx_memory= 0xdeadbeef"
,
"--config-parameter"
,
"instance. memtx_memory= 0xdeadbeef"
,
])
.unwrap
();
])
.unwrap
();
config
.set_from_args
(
args
)
.unwrap
();
config
.set_from_args
(
args
)
.unwrap
();
assert_eq!
(
config
.instance.tier
.unwrap
(),
"ABC"
);
assert_eq!
(
config
.instance.tier
.unwrap
(),
"ABC"
);
assert_eq!
(
config
.cluster.cluster_id
.unwrap
(),
"DEF"
);
assert_eq!
(
config
.cluster.cluster_id
.unwrap
(),
"DEF"
);
assert_eq!
(
config
.instance.log
_
level
.unwrap
(),
args
::
LogLevel
::
Debug
);
assert_eq!
(
config
.instance.log
.
level
.unwrap
(),
args
::
LogLevel
::
Debug
);
assert_eq!
(
config
.instance.memtx_memory
.unwrap
(),
0xdead_beef
);
assert_eq!
(
config
.instance.memtx_memory
.unwrap
(),
0xdead_beef
);
assert_eq!
(
config
.instance.audit
.unwrap
(),
"audit.txt"
);
assert_eq!
(
config
.instance.audit
.unwrap
(),
"audit.txt"
);
assert_eq!
(
config
.instance.data_dir
.unwrap
(),
"."
);
assert_eq!
(
config
.instance.data_dir
.unwrap
(),
"."
);
...
...
This diff is collapsed.
Click to expand it.
src/tarantool.rs
+
3
−
1
View file @
dd483d7b
...
@@ -208,7 +208,7 @@ impl Cfg {
...
@@ -208,7 +208,7 @@ impl Cfg {
}
}
pub
fn
set_core_parameters
(
&
mut
self
,
config
:
&
PicodataConfig
)
->
Result
<
(),
Error
>
{
pub
fn
set_core_parameters
(
&
mut
self
,
config
:
&
PicodataConfig
)
->
Result
<
(),
Error
>
{
self
.log
=
config
.instance.log
.clone
();
self
.log
=
config
.instance.log.
destination
.
clone
();
self
.log_level
=
Some
(
config
.instance
.log_level
()
as
_
);
self
.log_level
=
Some
(
config
.instance
.log_level
()
as
_
);
self
.wal_dir
=
config
.instance
.data_dir
();
self
.wal_dir
=
config
.instance
.data_dir
();
...
@@ -221,6 +221,8 @@ impl Cfg {
...
@@ -221,6 +221,8 @@ impl Cfg {
#[rustfmt::skip]
#[rustfmt::skip]
const
MAPPING
:
&
[(
&
str
,
&
str
)]
=
&
[
const
MAPPING
:
&
[(
&
str
,
&
str
)]
=
&
[
// Other instance.log.* parameters are set explicitly above
(
"log_format"
,
"instance.log.format"
),
];
];
for
(
box_field
,
picodata_field
)
in
MAPPING
{
for
(
box_field
,
picodata_field
)
in
MAPPING
{
let
value
=
config
let
value
=
config
...
...
This diff is collapsed.
Click to expand it.
test/int/test_config_file.py
+
59
−
2
View file @
dd483d7b
...
@@ -46,7 +46,8 @@ instance:
...
@@ -46,7 +46,8 @@ instance:
replicaset_id: my-replicaset
replicaset_id: my-replicaset
tier: deluxe
tier: deluxe
audit:
{
data_dir
}
/audit.log
audit:
{
data_dir
}
/audit.log
log_level: verbose
log:
level: verbose
"""
"""
)
)
instance
=
Instance
(
instance
=
Instance
(
...
@@ -87,7 +88,7 @@ instance:
...
@@ -87,7 +88,7 @@ instance:
config_file
=
instance
.
config_path
,
config_file
=
instance
.
config_path
,
data_dir
=
data_dir
,
data_dir
=
data_dir
,
listen
=
dict
(
host
=
host
,
port
=
str
(
port
)),
listen
=
dict
(
host
=
host
,
port
=
str
(
port
)),
log
_
level
=
"
verbose
"
,
log
=
dict
(
level
=
"
verbose
"
)
,
peers
=
[
dict
(
host
=
host
,
port
=
str
(
port
))],
peers
=
[
dict
(
host
=
host
,
port
=
str
(
port
))],
unknown_parameters
=
[],
unknown_parameters
=
[],
),
),
...
@@ -244,3 +245,59 @@ error: option `--init-replication-factor` cannot be used with `--config` simulta
...
@@ -244,3 +245,59 @@ error: option `--init-replication-factor` cannot be used with `--config` simulta
i1
.
fail_to_start
()
i1
.
fail_to_start
()
assert
crawler
.
matched
assert
crawler
.
matched
def
test_config_file_box_cfg_parameters
(
cluster
:
Cluster
):
#
# Check default values
#
cluster
.
set_config_file
(
yaml
=
"""
# just the required part
cluster:
cluster_id: test
tiers:
default:
"""
)
i1
=
cluster
.
add_instance
(
wait_online
=
False
)
i1
.
start
()
i1
.
wait_online
()
box_cfg
=
i1
.
eval
(
"
return box.cfg
"
)
assert
box_cfg
.
get
(
"
log
"
)
is
None
# type: ignore
assert
box_cfg
[
"
log_level
"
]
==
6
# means verbose -- set by our testing harness
assert
box_cfg
[
"
log_format
"
]
==
"
plain
"
#
# Check explicitly set values
#
cluster
.
config_path
=
None
cluster
.
set_config_file
(
yaml
=
"""
cluster:
cluster_id: test
tiers:
default:
instance:
log:
destination: file:/proc/self/fd/2 # this is how you say `stderr` explicitly
level: debug
format: json
"""
)
# XXX: Just pretend this value comes from the config,
# even though this will override any value from the config
i1
.
env
[
"
PICODATA_LOG_LEVEL
"
]
=
"
debug
"
i1
.
restart
(
remove_data
=
True
)
i1
.
wait_online
()
box_cfg
=
i1
.
eval
(
"
return box.cfg
"
)
assert
box_cfg
[
"
log
"
]
==
"
file:/proc/self/fd/2
"
assert
box_cfg
[
"
log_level
"
]
==
7
# means debug
assert
box_cfg
[
"
log_format
"
]
==
"
json
"
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment