Skip to content

Commit

Permalink
Merge pull request syslog-ng#4688 from alltilla/loki-timestamp-option…
Browse files Browse the repository at this point in the history
…-string-param

loki: enable setting the timestamp() option with quoted strings
  • Loading branch information
OverOrion authored Oct 27, 2023
2 parents 9919708 + aa549f1 commit 449f162
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 19 deletions.
6 changes: 3 additions & 3 deletions modules/grpc/loki/loki-dest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,11 @@ loki_dd_add_label(LogDriver *d, const gchar *name, LogTemplate *value)
self->cpp->add_label(name, value);
}

void
loki_dd_set_timestamp(LogDriver *d, LogMessageTimeStamp t)
gboolean
loki_dd_set_timestamp(LogDriver *d, const gchar *t)
{
LokiDestDriver *self = (LokiDestDriver *) d;
self->cpp->set_timestamp(t);
return self->cpp->set_timestamp(t);
}

void
Expand Down
2 changes: 1 addition & 1 deletion modules/grpc/loki/loki-dest.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ LogDriver *loki_dd_new(GlobalConfig *cfg);
void loki_dd_set_url(LogDriver *d, const gchar *url);
void loki_dd_set_message_template_ref(LogDriver *d, LogTemplate *message);
void loki_dd_add_label(LogDriver *d, const gchar *name, LogTemplate *value);
void loki_dd_set_timestamp(LogDriver *d, LogMessageTimeStamp t);
gboolean loki_dd_set_timestamp(LogDriver *d, const gchar *t);

GrpcClientCredentialsBuilderW *loki_dd_get_credentials_builder(LogDriver *s);

Expand Down
12 changes: 10 additions & 2 deletions modules/grpc/loki/loki-dest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,17 @@ class DestinationDriver final
this->message = msg;
}

void set_timestamp(LogMessageTimeStamp t)
bool set_timestamp(const char *t)
{
this->timestamp = t;
if (strcasecmp(t, "current") == 0)
this->timestamp = LM_TS_PROCESSED;
else if (strcasecmp(t, "received") == 0)
this->timestamp = LM_TS_RECVD;
else if (strcasecmp(t, "msg") == 0)
this->timestamp = LM_TS_STAMP;
else
return false;
return true;
}

void set_keepalive_time(int t)
Expand Down
15 changes: 5 additions & 10 deletions modules/grpc/loki/loki-grammar.ym
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ GrpcClientCredentialsBuilderW *last_grpc_client_credentials_builder;
%token KW_URL
%token KW_LABELS
%token KW_TIMESTAMP
%token KW_CURRENT
%token KW_RECEIVED
%token KW_MSG

%token KW_AUTH
%token KW_INSECURE
Expand Down Expand Up @@ -97,7 +94,11 @@ loki_dest_option
: KW_URL '(' string ')' { loki_dd_set_url(last_driver, $3); free($3); }
| KW_KEEP_ALIVE '(' loki_keepalive_options ')'
| KW_LABELS '(' loki_labels ')'
| KW_TIMESTAMP '(' loki_timestamp_enum ')'
| KW_TIMESTAMP '(' string ')'
{
CHECK_ERROR(loki_dd_set_timestamp(last_driver, $3), @1, "Failed to set timestamp(). Valid values are: \"current\", \"received\", \"msg\"");
free($3);
}
| KW_TEMPLATE '(' template_name_or_content ')' { loki_dd_set_message_template_ref(last_driver, $3); }
| KW_AUTH { last_grpc_client_credentials_builder = loki_dd_get_credentials_builder(last_driver); } '(' grpc_client_credentials_option ')'
| threaded_dest_driver_general_option
Expand All @@ -120,12 +121,6 @@ loki_label
}
;

loki_timestamp_enum
: KW_CURRENT { loki_dd_set_timestamp(last_driver, LM_TS_PROCESSED); }
| KW_RECEIVED { loki_dd_set_timestamp(last_driver, LM_TS_RECVD); }
| KW_MSG { loki_dd_set_timestamp(last_driver, LM_TS_STAMP); }
;

loki_keepalive_options
: loki_keepalive_option loki_keepalive_options
|
Expand Down
3 changes: 0 additions & 3 deletions modules/grpc/loki/loki-parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ static CfgLexerKeyword loki_keywords[] =
{ "url", KW_URL },
{ "labels", KW_LABELS },
{ "timestamp", KW_TIMESTAMP },
{ "current", KW_CURRENT },
{ "received", KW_RECEIVED },
{ "msg", KW_MSG },
{ "keep_alive", KW_KEEP_ALIVE },
{ "time", KW_TIME },
{ "timeout", KW_TIMEOUT },
Expand Down
6 changes: 6 additions & 0 deletions news/other-4688.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
`loki()`: The `timestamp()` option now supports quoted strings.

The valid values are the following, with or without quotes, case insensitive:
* "current"
* "received"
* "msg"

0 comments on commit 449f162

Please sign in to comment.