func()

in apps/mysql.go [153:226]


func (p LoggingProcessorMysqlError) Components(ctx context.Context, tag string, uid string) []fluentbit.Component {
	c := confgenerator.LoggingProcessorParseRegexComplex{
		Parsers: []confgenerator.RegexParser{
			{
				// MySql >=5.7 documented: https://dev.mysql.com/doc/refman/8.0/en/error-log-format.html
				// Sample Line: 2020-08-06T14:25:02.936146Z 0 [Warning] [MY-010068] [Server] CA certificate /var/mysql/sslinfo/cacert.pem is self signed.
				// Sample Line: 2020-08-06T14:25:03.109022Z 5 [Note] Event Scheduler: scheduler thread started with id 5
				Regex: fmt.Sprintf(
					`^(?<time>%s)\s+(?<tid>\d+)\s+\[(?<level>[^\]]+)](?:\s+\[(?<errorCode>[^\]]+)])?(?:\s+\[(?<subsystem>[^\]]+)])?\s+(?<message>.*)$`,
					timeRegexMySQLNew,
				),
				Parser: confgenerator.ParserShared{
					TimeKey:    "time",
					TimeFormat: timeFormatMySQLNew,
					Types: map[string]string{
						"tid": "integer",
					},
				},
			},
			{
				// Mysql <5.7, MariaDB <10.1.4, documented: https://mariadb.com/kb/en/error-log/#format
				// Sample Line: 160615 16:53:08 [Note] InnoDB: The InnoDB memory heap is disabled
				// TODO - time is in system time, not UTC, is there a way to resolve this in fluent bit?
				Regex: fmt.Sprintf(
					`^(?<time>%s)\s+\[(?<level>[^\]]+)]\s+(?<message>.*)$`,
					timeRegexOld,
				),
				Parser: confgenerator.ParserShared{
					TimeKey:    "time",
					TimeFormat: timeFormatOld,
				},
			},
			{
				// MariaDB >=10.1.5, documented: https://mariadb.com/kb/en/error-log/#format
				// Sample Line: 2016-06-15  1:53:33 139651251140544 [Note] InnoDB: The InnoDB memory heap is disabled
				Regex: fmt.Sprintf(
					`^(?<time>%s)(?:\s+(?<tid>\d+))?(?:\s+\[(?<level>[^\]]+)])?\s+(?<message>.*)$`,
					timeRegexMariaDBNew,
				),
				Parser: confgenerator.ParserShared{
					TimeKey:    "time",
					TimeFormat: timeFormatMariaDBNew,
					Types: map[string]string{
						"tid": "integer",
					},
				},
			},
		},
	}.Components(ctx, tag, uid)

	c = append(c,
		confgenerator.LoggingProcessorModifyFields{
			Fields: map[string]*confgenerator.ModifyField{
				"severity": {
					CopyFrom: "jsonPayload.level",
					MapValues: map[string]string{
						"ERROR":   "ERROR",
						"Error":   "ERROR",
						"WARNING": "WARNING",
						"Warning": "WARNING",
						"SYSTEM":  "INFO",
						"System":  "INFO",
						"NOTE":    "NOTICE",
						"Note":    "NOTICE",
					},
					MapValuesExclusive: true,
				},
				InstrumentationSourceLabel: instrumentationSourceValue(p.Type()),
			},
		}.Components(ctx, tag, uid)...,
	)

	return c
}