forked from dgiot/dgiot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
emqx.schema
2470 lines (2070 loc) · 77.4 KB
/
emqx.schema
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
%%-*- mode: erlang -*-
%% EMQ X R4.0 config mapping
%%--------------------------------------------------------------------
%% Cluster
%%--------------------------------------------------------------------
%% @doc Cluster name
{mapping, "cluster.name", "ekka.cluster_name", [
{default, emqxcl},
{datatype, atom}
]}.
%% @doc Cluster discovery
{mapping, "cluster.discovery", "ekka.cluster_discovery", [
{default, manual},
{datatype, atom}
]}.
%% @doc Clean down node from the cluster
{mapping, "cluster.autoclean", "ekka.cluster_autoclean", [
{datatype, {duration, ms}}
]}.
%% @doc Cluster autoheal
{mapping, "cluster.autoheal", "ekka.cluster_autoheal", [
{datatype, flag},
{default, off}
]}.
%%--------------------------------------------------------------------
%% Cluster by static node list
{mapping, "cluster.static.seeds", "ekka.cluster_discovery", [
{datatype, string}
]}.
%%--------------------------------------------------------------------
%% Cluster by UDP Multicast
{mapping, "cluster.mcast.addr", "ekka.cluster_discovery", [
{default, "239.192.0.1"},
{datatype, string}
]}.
{mapping, "cluster.mcast.ports", "ekka.cluster_discovery", [
{default, "4369"},
{datatype, string}
]}.
{mapping, "cluster.mcast.iface", "ekka.cluster_discovery", [
{datatype, string},
{default, "0.0.0.0"}
]}.
{mapping, "cluster.mcast.ttl", "ekka.cluster_discovery", [
{datatype, integer},
{default, 255}
]}.
{mapping, "cluster.mcast.loop", "ekka.cluster_discovery", [
{datatype, flag},
{default, on}
]}.
{mapping, "cluster.mcast.sndbuf", "ekka.cluster_discovery", [
{datatype, bytesize},
{default, "16KB"}
]}.
{mapping, "cluster.mcast.recbuf", "ekka.cluster_discovery", [
{datatype, bytesize},
{default, "16KB"}
]}.
{mapping, "cluster.mcast.buffer", "ekka.cluster_discovery", [
{datatype, bytesize},
{default, "32KB"}
]}.
%%--------------------------------------------------------------------
%% Cluster by DNS A Record
{mapping, "cluster.dns.name", "ekka.cluster_discovery", [
{datatype, string}
]}.
%% @doc The erlang distributed protocol
{mapping, "cluster.proto_dist", "ekka.proto_dist", [
{default, "inet_tcp"},
{datatype, {enum, [inet_tcp, inet6_tcp, inet_tls]}},
hidden
]}.
{mapping, "cluster.dns.app", "ekka.cluster_discovery", [
{datatype, string}
]}.
%%--------------------------------------------------------------------
%% Cluster using etcd
{mapping, "cluster.etcd.server", "ekka.cluster_discovery", [
{datatype, string}
]}.
{mapping, "cluster.etcd.prefix", "ekka.cluster_discovery", [
{datatype, string}
]}.
{mapping, "cluster.etcd.node_ttl", "ekka.cluster_discovery", [
{datatype, {duration, ms}},
{default, "1m"}
]}.
{mapping, "cluster.etcd.ssl.keyfile", "ekka.cluster_discovery", [
{datatype, string}
]}.
{mapping, "cluster.etcd.ssl.certfile", "ekka.cluster_discovery", [
{datatype, string}
]}.
{mapping, "cluster.etcd.ssl.cacertfile", "ekka.cluster_discovery", [
{datatype, string}
]}.
%%--------------------------------------------------------------------
%% Cluster on K8s
{mapping, "cluster.k8s.apiserver", "ekka.cluster_discovery", [
{datatype, string}
]}.
{mapping, "cluster.k8s.service_name", "ekka.cluster_discovery", [
{datatype, string}
]}.
{mapping, "cluster.k8s.address_type", "ekka.cluster_discovery", [
{datatype, {enum, [ip, dns, hostname]}}
]}.
{mapping, "cluster.k8s.app_name", "ekka.cluster_discovery", [
{datatype, string}
]}.
{mapping, "cluster.k8s.namespace", "ekka.cluster_discovery", [
{datatype, string}
]}.
{mapping, "cluster.k8s.suffix", "ekka.cluster_discovery", [
{datatype, string},
{default, ""}
]}.
{translation, "ekka.cluster_discovery", fun(Conf) ->
Strategy = cuttlefish:conf_get("cluster.discovery", Conf),
Filter = fun(Opts) -> [{K, V} || {K, V} <- Opts, V =/= undefined] end,
IpPort = fun(S) ->
[Addr, Port] = string:tokens(S, ":"),
{ok, Ip} = inet:parse_address(Addr),
{Ip, Port}
end,
Options = fun(static) ->
[{seeds, [list_to_atom(S) || S <- string:tokens(cuttlefish:conf_get("cluster.static.seeds", Conf, ""), ",")]}];
(mcast) ->
{ok, Addr} = inet:parse_address(cuttlefish:conf_get("cluster.mcast.addr", Conf)),
{ok, Iface} = inet:parse_address(cuttlefish:conf_get("cluster.mcast.iface", Conf)),
Ports = [list_to_integer(S) || S <- string:tokens(cuttlefish:conf_get("cluster.mcast.ports", Conf), ",")],
[{addr, Addr}, {ports, Ports}, {iface, Iface},
{ttl, cuttlefish:conf_get("cluster.mcast.ttl", Conf, 1)},
{loop, cuttlefish:conf_get("cluster.mcast.loop", Conf, true)}];
(dns) ->
[{name, cuttlefish:conf_get("cluster.dns.name", Conf)},
{app, cuttlefish:conf_get("cluster.dns.app", Conf)}];
(etcd) ->
SslOpts = fun(Conf) ->
Options = cuttlefish_variable:filter_by_prefix("cluster.etcd.ssl", Conf),
lists:map(fun({["cluster", "etcd", "ssl", Name], Value}) ->
{list_to_atom(Name), Value}
end, Options)
end,
[{server, string:tokens(cuttlefish:conf_get("cluster.etcd.server", Conf), ",")},
{prefix, cuttlefish:conf_get("cluster.etcd.prefix", Conf, "emqcl")},
{node_ttl, cuttlefish:conf_get("cluster.etcd.node_ttl", Conf, 60)},
{ssl_options, SslOpts(Conf)}];
(k8s) ->
[{apiserver, cuttlefish:conf_get("cluster.k8s.apiserver", Conf)},
{service_name, cuttlefish:conf_get("cluster.k8s.service_name", Conf)},
{address_type, cuttlefish:conf_get("cluster.k8s.address_type", Conf, ip)},
{app_name, cuttlefish:conf_get("cluster.k8s.app_name", Conf)},
{namespace, cuttlefish:conf_get("cluster.k8s.namespace", Conf)},
{suffix, cuttlefish:conf_get("cluster.k8s.suffix", Conf, "")}];
(manual) ->
[ ]
end,
{Strategy, Filter(Options(Strategy))}
end}.
%%--------------------------------------------------------------------
%% Node
%%--------------------------------------------------------------------
%% @doc Node name
{mapping, "node.name", "vm_args.-name", [
{default, "[email protected]"},
{override_env, "NODE_NAME"}
]}.
%% @doc Specify SSL Options in the file if using SSL for erlang distribution
{mapping, "node.ssl_dist_optfile", "vm_args.-ssl_dist_optfile", [
{datatype, string},
hidden
]}.
%% @doc Secret cookie for distributed erlang node
{mapping, "node.cookie", "vm_args.-setcookie", [
{default, "emqxsecretcookie"},
{override_env, "NODE_COOKIE"}
]}.
{mapping, "node.data_dir", "emqx.data_dir", [
{datatype, string}
]}.
%% @doc http://erlang.org/doc/man/heart.html
{mapping, "node.heartbeat", "vm_args.-heart", [
{datatype, flag},
hidden
]}.
{translation, "vm_args.-heart", fun(Conf) ->
case cuttlefish:conf_get("node.heartbeat", Conf) of
true -> "";
false -> cuttlefish:invalid("should be 'on' or comment the line!")
end
end}.
%% @doc More information at: http://erlang.org/doc/man/erl.html
{mapping, "node.async_threads", "vm_args.+A", [
{datatype, integer},
{validators, ["range:0-1024"]}
]}.
%% @doc Erlang Process Limit
{mapping, "node.process_limit", "vm_args.+P", [
{datatype, integer},
hidden
]}.
%% @doc The maximum number of concurrent ports/sockets.
%% Valid range is 1024-134217727
{mapping, "node.max_ports", "vm_args.+Q", [
{datatype, integer},
{validators, ["range4ports"]},
{override_env, "MAX_PORTS"}
]}.
{validator, "range4ports", "must be 1024 to 134217727",
fun(X) -> X >= 1024 andalso X =< 134217727 end}.
%% @doc http://www.erlang.org/doc/man/erl.html#%2bzdbbl
{mapping, "node.dist_buffer_size", "vm_args.+zdbbl", [
{datatype, bytesize},
{commented, "32MB"},
hidden,
{validators, ["zdbbl_range"]}
]}.
{translation, "vm_args.+zdbbl",
fun(Conf) ->
ZDBBL = cuttlefish:conf_get("node.dist_buffer_size", Conf, undefined),
case ZDBBL of
undefined -> undefined;
X when is_integer(X) -> cuttlefish_util:ceiling(X / 1024); %% Bytes to Kilobytes;
_ -> undefined
end
end}.
{validator, "zdbbl_range", "must be between 1KB and 2097151KB",
fun(ZDBBL) ->
%% 2097151KB = 2147482624
ZDBBL >= 1024 andalso ZDBBL =< 2147482624
end
}.
%% @doc Global GC Interval
{mapping, "node.global_gc_interval", "emqx.global_gc_interval", [
{datatype, {duration, s}}
]}.
%% @doc http://www.erlang.org/doc/man/erlang.html#system_flag-2
{mapping, "node.fullsweep_after", "vm_args.-env ERL_FULLSWEEP_AFTER", [
{default, 1000},
{datatype, integer},
hidden,
{validators, ["positive_integer"]}
]}.
{validator, "positive_integer", "must be a positive integer",
fun(X) -> X >= 0 end}.
%% Note: OTP R15 and earlier uses -env ERL_MAX_ETS_TABLES,
%% R16+ uses +e
%% @doc The ETS table limit
{mapping, "node.max_ets_tables",
cuttlefish:otp("R16", "vm_args.+e", "vm_args.-env ERL_MAX_ETS_TABLES"), [
{default, 256000},
{datatype, integer},
hidden
]}.
%% @doc Set the location of crash dumps
{mapping, "node.crash_dump", "vm_args.-env ERL_CRASH_DUMP", [
{default, "{{crash_dump}}"},
{datatype, file},
hidden
]}.
%% @doc http://www.erlang.org/doc/man/kernel_app.html#net_ticktime
{mapping, "node.dist_net_ticktime", "vm_args.-kernel net_ticktime", [
{datatype, integer},
hidden
]}.
%% @doc http://www.erlang.org/doc/man/kernel_app.html
{mapping, "node.dist_listen_min", "kernel.inet_dist_listen_min", [
{commented, 6369},
{datatype, integer},
hidden
]}.
%% @see node.dist_listen_min
{mapping, "node.dist_listen_max", "kernel.inet_dist_listen_max", [
{commented, 6369},
{datatype, integer},
hidden
]}.
{mapping, "node.backtrace_depth", "emqx.backtrace_depth", [
{default, 16},
{datatype, integer}
]}.
%%--------------------------------------------------------------------
%% RPC
%%--------------------------------------------------------------------
%% RPC Mode.
{mapping, "rpc.mode", "emqx.rpc_mode", [
{default, async},
{datatype, {enum, [sync, async]}}
]}.
{mapping, "rpc.async_batch_size", "gen_rpc.max_batch_size", [
{default, 256},
{datatype, integer}
]}.
{mapping, "rpc.port_discovery", "gen_rpc.port_discovery", [
{default, stateless},
{datatype, {enum, [manual, stateless]}}
]}.
%% RPC server port.
{mapping, "rpc.tcp_server_port", "gen_rpc.tcp_server_port", [
{default, 5369},
{datatype, integer}
]}.
%% Number of tcp connections when connecting to RPC server
{mapping, "rpc.tcp_client_num", "gen_rpc.tcp_client_num", [
{default, 0},
{datatype, integer},
{validators, ["range:gt_0_lt_256"]}
]}.
{translation, "gen_rpc.tcp_client_num", fun(Conf) ->
case cuttlefish:conf_get("rpc.tcp_client_num", Conf) of
0 -> 1; %% keep allowing 0 for backward compatibility
V -> V
end
end}.
%% Client connect timeout
{mapping, "rpc.connect_timeout", "gen_rpc.connect_timeout", [
{default, "5s"},
{datatype, {duration, ms}}
]}.
%% Client and Server send timeout
{mapping, "rpc.send_timeout", "gen_rpc.send_timeout", [
{default, 5000},
{datatype, {duration, ms}}
]}.
%% Authentication timeout
{mapping, "rpc.authentication_timeout", "gen_rpc.authentication_timeout", [
{default, 5000},
{datatype, {duration, ms}}
]}.
%% Default receive timeout for call() functions
{mapping, "rpc.call_receive_timeout", "gen_rpc.call_receive_timeout", [
{default, 15000},
{datatype, {duration, ms}}
]}.
%% Socket keepalive configuration
{mapping, "rpc.socket_keepalive_idle", "gen_rpc.socket_keepalive_idle", [
{default, 7200},
{datatype, {duration, s}}
]}.
%% Seconds between probes
{mapping, "rpc.socket_keepalive_interval", "gen_rpc.socket_keepalive_interval", [
{default, 75},
{datatype, {duration, s}}
]}.
%% Probes lost to close the connection
{mapping, "rpc.socket_keepalive_count", "gen_rpc.socket_keepalive_count", [
{default, 9},
{datatype, integer}
]}.
%% Size of TCP send buffer
{mapping, "rpc.socket_sndbuf", "gen_rpc.socket_sndbuf", [
{default, "1MB"},
{datatype, bytesize}
]}.
%% Size of TCP receive buffer
{mapping, "rpc.socket_recbuf", "gen_rpc.socket_recbuf", [
{default, "1MB"},
{datatype, bytesize}
]}.
%% Size of TCP receive buffer
{mapping, "rpc.socket_buffer", "gen_rpc.socket_buffer", [
{default, "1MB"},
{datatype, bytesize}
]}.
{validator, "range:gt_0_lt_256", "must greater than 0 and less than 256",
fun(X) -> X >= 0 andalso X < 256 end
}.
%% Force client to use server listening port, because we do no provide
%% per-node listening port manual mapping from configs.
%% i.e. all nodes in the cluster should agree to the same
%% listening port number.
{translation, "gen_rpc.tcp_client_port", fun(_, _, Conf) ->
cuttlefish:conf_get("rpc.tcp_server_port", Conf)
end}.
%%--------------------------------------------------------------------
%% Log
%%--------------------------------------------------------------------
{mapping, "log.to", "kernel.logger", [
{default, file},
{datatype, {enum, [file, console, both]}}
]}.
{mapping, "log.level", "kernel.logger", [
{default, warning},
{datatype, {enum, [debug, info, notice, warning, error, critical, alert, emergency, all]}}
]}.
{mapping, "log.primary_log_level", "kernel.logger_level", [
{default, warning},
{datatype, {enum, [debug, info, notice, warning, error, critical, alert, emergency, all]}}
]}.
{mapping, "log.dir", "kernel.logger", [
{default, "log"},
{datatype, string}
]}.
{mapping, "log.file", "kernel.logger", [
{default, "emqx.log"},
{datatype, file}
]}.
{mapping, "log.chars_limit", "kernel.logger", [
{default, -1},
{datatype, integer}
]}.
{mapping, "log.supervisor_reports", "kernel.logger", [
{default, error},
{datatype, {enum, [error, progress]}},
hidden
]}.
%% @doc Maximum depth in Erlang term log formatting
%% and message queue inspection.
{mapping, "log.max_depth", "kernel.error_logger_format_depth", [
{default, 100},
{datatype, [{enum, [unlimited]}, integer]}
]}.
%% @doc format logs as JSON objects
{mapping, "log.formatter", "kernel.logger", [
{default, text},
{datatype, {enum, [text, json]}}
]}.
%% @doc format logs in a single line.
{mapping, "log.single_line", "kernel.logger", [
{default, true},
{datatype, {enum, [true, false]}}
]}.
{mapping, "log.rotation", "kernel.logger", [
{default, on},
{datatype, flag}
]}.
{mapping, "log.rotation.size", "kernel.logger", [
{default, "10MB"},
{datatype, bytesize}
]}.
{mapping, "log.size", "kernel.logger", [
{default, infinity},
{datatype, [bytesize, atom]}
]}.
{mapping, "log.rotation.count", "kernel.logger", [
{default, 5},
{datatype, integer}
]}.
{mapping, "log.$level.file", "kernel.logger", [
{datatype, file}
]}.
{mapping, "log.sync_mode_qlen", "kernel.logger", [
{default, 100},
{datatype, integer}
]}.
{mapping, "log.drop_mode_qlen", "kernel.logger", [
{default, 3000},
{datatype, integer}
]}.
{mapping, "log.flush_qlen", "kernel.logger", [
{default, 8000},
{datatype, integer}
]}.
{mapping, "log.overload_kill", "kernel.logger", [
{default, on},
{datatype, flag}
]}.
{mapping, "log.overload_kill_mem_size", "kernel.logger", [
{default, "30MB"},
{datatype, bytesize}
]}.
{mapping, "log.overload_kill_qlen", "kernel.logger", [
{default, 20000},
{datatype, integer}
]}.
{mapping, "log.overload_kill_restart_after", "kernel.logger", [
{default, "5s"},
{datatype, [{duration, ms}, atom]}
]}.
{mapping, "log.burst_limit", "kernel.logger", [
{default, "disabled"},
{datatype, string}
]}.
{mapping, "log.error_logger", "kernel.error_logger", [
{default, silent},
{datatype, {enum, [silent]}},
hidden
]}.
{translation, "kernel.logger_level", fun(_, _, Conf) ->
cuttlefish:conf_get("log.level", Conf)
end}.
{translation, "kernel.logger", fun(Conf) ->
LogTo = cuttlefish:conf_get("log.to", Conf),
LogLevel = cuttlefish:conf_get("log.level", Conf),
LogType = case cuttlefish:conf_get("log.rotation", Conf) of
true -> wrap;
false -> halt
end,
CharsLimit = case cuttlefish:conf_get("log.chars_limit", Conf) of
-1 -> unlimited;
V -> V
end,
SingleLine = cuttlefish:conf_get("log.single_line", Conf),
FmtName = cuttlefish:conf_get("log.formatter", Conf),
Formatter =
case FmtName of
json ->
{emqx_logger_jsonfmt,
#{chars_limit => CharsLimit,
single_line => SingleLine
}};
text ->
{emqx_logger_textfmt,
#{template =>
[time," [",level,"] ",
{clientid,
[{peername,
[clientid,"@",peername," "],
[clientid, " "]}],
[{peername,
[peername," "],
[]}]},
msg,"\n"],
chars_limit => CharsLimit,
single_line => SingleLine
}}
end,
{BustLimitOn, {MaxBurstCount, TimeWindow}} =
case string:tokens(cuttlefish:conf_get("log.burst_limit", Conf), ", ") of
["disabled"] -> {false, {20000, 1000}};
[Count, Window] ->
{true, {list_to_integer(Count),
case cuttlefish_duration:parse(Window, ms) of
Secs when is_integer(Secs) -> Secs;
{error, Reason1} -> error(Reason1)
end}}
end,
FileConf = fun(Filename) ->
BasicConf =
#{type => LogType,
file => filename:join(cuttlefish:conf_get("log.dir", Conf), Filename),
max_no_files => cuttlefish:conf_get("log.rotation.count", Conf),
sync_mode_qlen => cuttlefish:conf_get("log.sync_mode_qlen", Conf),
drop_mode_qlen => cuttlefish:conf_get("log.drop_mode_qlen", Conf),
flush_qlen => cuttlefish:conf_get("log.flush_qlen", Conf),
overload_kill_enable => cuttlefish:conf_get("log.overload_kill", Conf),
overload_kill_qlen => cuttlefish:conf_get("log.overload_kill_qlen", Conf),
overload_kill_mem_size => cuttlefish:conf_get("log.overload_kill_mem_size", Conf),
overload_kill_restart_after => cuttlefish:conf_get("log.overload_kill_restart_after", Conf),
burst_limit_enable => BustLimitOn,
burst_limit_max_count => MaxBurstCount,
burst_limit_window_time => TimeWindow
},
MaxNoBytes = case LogType of
wrap -> cuttlefish:conf_get("log.rotation.size", Conf);
halt -> cuttlefish:conf_get("log.size", Conf)
end,
BasicConf#{max_no_bytes => MaxNoBytes}
end,
Filters = case cuttlefish:conf_get("log.supervisor_reports", Conf) of
error -> [{drop_progress_reports, {fun logger_filters:progress/2, stop}}];
progress -> []
end,
%% For the default logger that outputs to console
DefaultHandler =
if LogTo =:= console orelse LogTo =:= both ->
[{handler, console, logger_std_h,
#{level => LogLevel,
config => #{type => standard_io},
formatter => Formatter,
filters => Filters
}
}];
true ->
[{handler, default, undefined}]
end,
%% For the file logger
FileHandler =
if LogTo =:= file orelse LogTo =:= both ->
[{handler, file, logger_disk_log_h,
#{level => LogLevel,
config => FileConf(cuttlefish:conf_get("log.file", Conf)),
formatter => Formatter,
filesync_repeat_interval => no_repeat,
filters => Filters
}}];
true -> []
end,
%% For creating additional log files for specific log levels.
AdditionalLogFiles =
lists:foldl(
fun({[_, Level, _] = K, Filename}, Acc) when LogTo =:= file; LogTo =:= both ->
case cuttlefish_variable:is_fuzzy_match(K, ["log", "$level", "file"]) of
true -> [{Level, Filename} | Acc];
false -> Acc
end;
({_K, _V}, Acc) ->
Acc
end, [], Conf),
AdditionalHandlers =
[{handler, list_to_atom("file_for_"++Level), logger_disk_log_h,
#{level => list_to_atom(Level),
config => FileConf(Filename),
formatter => Formatter,
filesync_repeat_interval => no_repeat}}
|| {Level, Filename} <- AdditionalLogFiles],
DefaultHandler ++ FileHandler ++ AdditionalHandlers
end}.
%%--------------------------------------------------------------------
%% Authentication/ACL
%%--------------------------------------------------------------------
%% @doc Allow anonymous authentication.
{mapping, "allow_anonymous", "emqx.allow_anonymous", [
{default, false},
{datatype, {enum, [true, false]}}
]}.
%% @doc ACL nomatch.
{mapping, "acl_nomatch", "emqx.acl_nomatch", [
{default, deny},
{datatype, {enum, [allow, deny]}}
]}.
%% @doc Default ACL file.
{mapping, "acl_file", "emqx.acl_file", [
{datatype, string},
hidden
]}.
%% @doc Enable ACL cache for publish.
{mapping, "enable_acl_cache", "emqx.enable_acl_cache", [
{default, on},
{datatype, flag}
]}.
%% @doc ACL cache time-to-live.
{mapping, "acl_cache_ttl", "emqx.acl_cache_ttl", [
{default, "1m"},
{datatype, {duration, ms}}
]}.
%% @doc ACL cache size.
{mapping, "acl_cache_max_size", "emqx.acl_cache_max_size", [
{default, 32},
{datatype, integer},
{validators, ["range:gt_0"]}
]}.
%% @doc Action when acl check reject current operation
{mapping, "acl_deny_action", "emqx.acl_deny_action", [
{default, ignore},
{datatype, {enum, [ignore, disconnect]}}
]}.
%% @doc Flapping detect policy
{mapping, "flapping_detect_policy", "emqx.flapping_detect_policy", [
{datatype, string},
{default, "30,1m,5m"}
]}.
{translation, "emqx.flapping_detect_policy", fun(Conf) ->
Policy = cuttlefish:conf_get("flapping_detect_policy", Conf),
[Threshold, Duration, Interval] = string:tokens(Policy, ", "),
ParseDuration = fun(S, Dur) ->
case cuttlefish_duration:parse(S, Dur) of
I when is_integer(I) -> I;
{error, Reason} -> error(Reason)
end
end,
#{threshold => list_to_integer(Threshold),
duration => ParseDuration(Duration, ms),
banned_interval => ParseDuration(Interval, s)
}
end}.
{validator, "range:gt_0", "must greater than 0",
fun(X) -> X > 0 end
}.
%%--------------------------------------------------------------------
%% MQTT Protocol
%%--------------------------------------------------------------------
%% @doc Max Packet Size Allowed, 1MB by default.
{mapping, "mqtt.max_packet_size", "emqx.max_packet_size", [
{default, "1MB"},
{datatype, bytesize},
{override_env, "MAX_PACKET_SIZE"}
]}.
%% @doc Set the Max ClientId Length Allowed.
{mapping, "mqtt.max_clientid_len", "emqx.max_clientid_len", [
{default, 65535},
{datatype, integer}
]}.
%% @doc Set the Maximum topic levels.
{mapping, "mqtt.max_topic_levels", "emqx.max_topic_levels", [
{default, 0},
{datatype, integer}
]}.
%% @doc Set the Maximum QoS allowed.
{mapping, "mqtt.max_qos_allowed", "emqx.max_qos_allowed", [
{default, 2},
{datatype, integer},
{validators, ["range:0-2"]}
]}.
%% @doc Set the Maximum Topic Alias.
{mapping, "mqtt.max_topic_alias", "emqx.max_topic_alias", [
{default, 65535},
{datatype, integer}
]}.
%% @doc Whether the server supports MQTT retained messages.
{mapping, "mqtt.retain_available", "emqx.retain_available", [
{default, true},
{datatype, {enum, [true, false]}}
]}.
%% @doc Whether the Server supports MQTT Wildcard Subscriptions.
{mapping, "mqtt.wildcard_subscription", "emqx.wildcard_subscription", [
{default, true},
{datatype, {enum, [true, false]}}
]}.
%% @doc Whether the Server supports MQTT Shared Subscriptions.
{mapping, "mqtt.shared_subscription", "emqx.shared_subscription", [
{default, true},
{datatype, {enum, [true, false]}}
]}.
%% @doc Whether to ignore loop delivery of messages.(for mqtt v3.1.1)
{mapping, "mqtt.ignore_loop_deliver", "emqx.ignore_loop_deliver", [
{default, true},
{datatype, {enum, [true, false]}}
]}.
%% @doc Whether to parse the MQTT frame in strict mode
{mapping, "mqtt.strict_mode", "emqx.strict_mode", [
{default, false},
{datatype, {enum, [true, false]}}
]}.
%% @doc Specify the response information returned to the client
{mapping, "mqtt.response_information", "emqx.response_information", [
{datatype, string}
]}.
%%--------------------------------------------------------------------
%% Zones
%%--------------------------------------------------------------------
%% @doc Idle timeout of the MQTT connection.
{mapping, "zone.$name.idle_timeout", "emqx.zones", [
{default, "15s"},
{datatype, {duration, ms}}
]}.
{mapping, "zone.$name.allow_anonymous", "emqx.zones", [
{datatype, {enum, [true, false]}}
]}.
{mapping, "zone.$name.acl_nomatch", "emqx.zones", [
{datatype, {enum, [allow, deny]}}
]}.
%% @doc Enable ACL check.
{mapping, "zone.$name.enable_acl", "emqx.zones", [
{default, off},
{datatype, flag}
]}.
%% @doc Action when acl check reject current operation
{mapping, "zone.$name.acl_deny_action", "emqx.zones", [
{default, ignore},
{datatype, {enum, [ignore, disconnect]}}
]}.
%% @doc Enable Ban.
{mapping, "zone.$name.enable_ban", "emqx.zones", [
{default, off},
{datatype, flag}
]}.
%% @doc Enable per connection statistics.
{mapping, "zone.$name.enable_stats", "emqx.zones", [
{default, off},
{datatype, flag}
]}.
%% @doc Publish limit of the MQTT connections.
{mapping, "zone.$name.publish_limit", "emqx.zones", [
{datatype, string}
]}.
%% @doc Max Packet Size Allowed, 64K by default.
{mapping, "zone.$name.max_packet_size", "emqx.zones", [
{datatype, bytesize}
]}.
%% @doc Set the Max ClientId Length Allowed.
{mapping, "zone.$name.max_clientid_len", "emqx.zones", [
{datatype, integer}
]}.
%% @doc Set the Maximum topic levels.
{mapping, "zone.$name.max_topic_levels", "emqx.zones", [
{datatype, integer}
]}.
%% @doc Set the Maximum QoS allowed.
{mapping, "zone.$name.max_qos_allowed", "emqx.zones", [
{datatype, integer},
{validators, ["range:0-2"]}
]}.
%% @doc Set the Maximum topic alias.
{mapping, "zone.$name.max_topic_alias", "emqx.zones", [
{datatype, integer}
]}.
%% @doc Whether the server supports retained messages.
{mapping, "zone.$name.retain_available", "emqx.zones", [
{datatype, {enum, [true, false]}}
]}.
%% @doc Whether the Server supports Wildcard Subscriptions.
{mapping, "zone.$name.wildcard_subscription", "emqx.zones", [
{datatype, {enum, [true, false]}}
]}.
%% @doc Whether the Server supports Shared Subscriptions.
{mapping, "zone.$name.shared_subscription", "emqx.zones", [
{datatype, {enum, [true, false]}}
]}.
%% @doc Server Keepalive
{mapping, "zone.$name.server_keepalive", "emqx.zones", [
{datatype, integer}
]}.
%% @doc Keepalive backoff
{mapping, "zone.$name.keepalive_backoff", "emqx.zones", [
{default, 0.75},
{datatype, float}
]}.
%% @doc Max Number of Subscriptions Allowed.
{mapping, "zone.$name.max_subscriptions", "emqx.zones", [
{default, 0},
{datatype, integer}
]}.
%% @doc Upgrade QoS according to subscription?
{mapping, "zone.$name.upgrade_qos", "emqx.zones", [
{default, off},
{datatype, flag}
]}.
%% @doc Max number of QoS 1 and 2 messages that can be “inflight” at one time.
%% 0 is equivalent to maximum allowed
{mapping, "zone.$name.max_inflight", "emqx.zones", [
{default, 0},
{datatype, integer},
{validators, ["range:1-65535"]}
]}.
%% @doc Retry interval for redelivering QoS1/2 messages.
{mapping, "zone.$name.retry_interval", "emqx.zones", [
{default, "30s"},
{datatype, {duration, s}}
]}.
%% @doc Max Packets that Awaiting PUBREL, 0 means no limit
{mapping, "zone.$name.max_awaiting_rel", "emqx.zones", [
{default, 0},
{datatype, integer}
]}.
%% @doc Awaiting PUBREL timeout
{mapping, "zone.$name.await_rel_timeout", "emqx.zones", [
{default, "300s"},
{datatype, {duration, s}}
]}.
%% @doc Ignore loop delivery of messages
{mapping, "zone.$name.ignore_loop_deliver", "emqx.zones", [
{datatype, {enum, [true, false]}}
]}.
%% @doc Session Expiry Interval
{mapping, "zone.$name.session_expiry_interval", "emqx.zones", [
{default, "2h"},
{datatype, {duration, s}}