File: options.go

package info (click to toggle)
mtail 3.2.24-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,384 kB
  • sloc: yacc: 647; makefile: 226; sh: 78; lisp: 77; awk: 17
file content (119 lines) | stat: -rw-r--r-- 3,046 bytes parent folder | download
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
// Copyright 2021 Google Inc. All Rights Reserved.
// This file is available under the Apache license.

package runtime

import (
	"time"

	"github.com/jaqx0r/mtail/internal/runtime/compiler"
	"github.com/jaqx0r/mtail/internal/runtime/vm"
	"github.com/prometheus/client_golang/prometheus"
)

// Option configures a new program Runtime.
type Option func(*Runtime) error

// OverrideLocation sets the timezone location for the VM.
func OverrideLocation(loc *time.Location) Option {
	return func(r *Runtime) error {
		r.overrideLocation = loc
		return nil
	}
}

// CompileOnly sets the Runtime to compile programs only, without executing them.
func CompileOnly() Option {
	return func(r *Runtime) error {
		r.compileOnly = true
		return ErrorsAbort()(r)
	}
}

// ErrorsAbort sets the Runtime to abort the Runtime on compile errors.
func ErrorsAbort() Option {
	return func(r *Runtime) error {
		r.errorsAbort = true
		return nil
	}
}

// DumpAst emits the AST after program compilation.
func DumpAst() Option {
	return func(r *Runtime) error {
		r.cOpts = append(r.cOpts, compiler.EmitAst())
		return nil
	}
}

// DumpAstTypes emits the AST after type checking.
func DumpAstTypes() Option {
	return func(r *Runtime) error {
		r.cOpts = append(r.cOpts, compiler.EmitAstTypes())
		return nil
	}
}

// DumpBytecode instructs the loader to print the compiled bytecode after code generation.
func DumpBytecode() Option {
	return func(r *Runtime) error {
		r.dumpBytecode = true
		return nil
	}
}

// SyslogUseCurrentYear instructs the VM to annotate yearless timestamps with the current year.
func SyslogUseCurrentYear() Option {
	return func(r *Runtime) error {
		r.syslogUseCurrentYear = true
		return nil
	}
}

// MaxRegexpLength sets the maximum length an mtail regular expression can have, in terms of characters.
func MaxRegexpLength(maxRegexpLength int) Option {
	return func(r *Runtime) error {
		r.cOpts = append(r.cOpts, compiler.MaxRegexpLength(maxRegexpLength))
		return nil
	}
}

// MaxRecursionDepth sets the maximum depth the abstract syntax tree built during lexation can have.
func MaxRecursionDepth(maxRecursionDepth int) Option {
	return func(r *Runtime) error {
		r.cOpts = append(r.cOpts, compiler.MaxRecursionDepth(maxRecursionDepth))
		return nil
	}
}

// OmitMetricSource instructs the Runtime to not annotate metrics with their program source when added to the metric store.
func OmitMetricSource() Option {
	return func(r *Runtime) error {
		r.omitMetricSource = true
		return nil
	}
}

// PrometheusRegisterer passes in a registry for setting up exported metrics.
func PrometheusRegisterer(reg prometheus.Registerer) Option {
	return func(r *Runtime) error {
		r.reg = reg
		r.reg.MustRegister(vm.LineProcessingDurations)
		return nil
	}
}

// LogRuntimeErrors instructs the VM to emit runtime errors into the log.
func LogRuntimeErrors() Option {
	return func(r *Runtime) error {
		r.logRuntimeErrors = true
		return nil
	}
}

func TraceExecution() Option {
	return func(r *Runtime) error {
		r.trace = true
		return nil
	}
}