Skip to content

Commit 449f162

Browse files
authored
Merge pull request #4688 from alltilla/loki-timestamp-option-string-param
loki: enable setting the timestamp() option with quoted strings
2 parents 9919708 + aa549f1 commit 449f162

File tree

6 files changed

+25
-19
lines changed

6 files changed

+25
-19
lines changed

modules/grpc/loki/loki-dest.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,11 @@ loki_dd_add_label(LogDriver *d, const gchar *name, LogTemplate *value)
196196
self->cpp->add_label(name, value);
197197
}
198198

199-
void
200-
loki_dd_set_timestamp(LogDriver *d, LogMessageTimeStamp t)
199+
gboolean
200+
loki_dd_set_timestamp(LogDriver *d, const gchar *t)
201201
{
202202
LokiDestDriver *self = (LokiDestDriver *) d;
203-
self->cpp->set_timestamp(t);
203+
return self->cpp->set_timestamp(t);
204204
}
205205

206206
void

modules/grpc/loki/loki-dest.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ LogDriver *loki_dd_new(GlobalConfig *cfg);
3838
void loki_dd_set_url(LogDriver *d, const gchar *url);
3939
void loki_dd_set_message_template_ref(LogDriver *d, LogTemplate *message);
4040
void loki_dd_add_label(LogDriver *d, const gchar *name, LogTemplate *value);
41-
void loki_dd_set_timestamp(LogDriver *d, LogMessageTimeStamp t);
41+
gboolean loki_dd_set_timestamp(LogDriver *d, const gchar *t);
4242

4343
GrpcClientCredentialsBuilderW *loki_dd_get_credentials_builder(LogDriver *s);
4444

modules/grpc/loki/loki-dest.hpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,17 @@ class DestinationDriver final
9898
this->message = msg;
9999
}
100100

101-
void set_timestamp(LogMessageTimeStamp t)
101+
bool set_timestamp(const char *t)
102102
{
103-
this->timestamp = t;
103+
if (strcasecmp(t, "current") == 0)
104+
this->timestamp = LM_TS_PROCESSED;
105+
else if (strcasecmp(t, "received") == 0)
106+
this->timestamp = LM_TS_RECVD;
107+
else if (strcasecmp(t, "msg") == 0)
108+
this->timestamp = LM_TS_STAMP;
109+
else
110+
return false;
111+
return true;
104112
}
105113

106114
void set_keepalive_time(int t)

modules/grpc/loki/loki-grammar.ym

+5-10
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ GrpcClientCredentialsBuilderW *last_grpc_client_credentials_builder;
5353
%token KW_URL
5454
%token KW_LABELS
5555
%token KW_TIMESTAMP
56-
%token KW_CURRENT
57-
%token KW_RECEIVED
58-
%token KW_MSG
5956

6057
%token KW_AUTH
6158
%token KW_INSECURE
@@ -97,7 +94,11 @@ loki_dest_option
9794
: KW_URL '(' string ')' { loki_dd_set_url(last_driver, $3); free($3); }
9895
| KW_KEEP_ALIVE '(' loki_keepalive_options ')'
9996
| KW_LABELS '(' loki_labels ')'
100-
| KW_TIMESTAMP '(' loki_timestamp_enum ')'
97+
| KW_TIMESTAMP '(' string ')'
98+
{
99+
CHECK_ERROR(loki_dd_set_timestamp(last_driver, $3), @1, "Failed to set timestamp(). Valid values are: \"current\", \"received\", \"msg\"");
100+
free($3);
101+
}
101102
| KW_TEMPLATE '(' template_name_or_content ')' { loki_dd_set_message_template_ref(last_driver, $3); }
102103
| KW_AUTH { last_grpc_client_credentials_builder = loki_dd_get_credentials_builder(last_driver); } '(' grpc_client_credentials_option ')'
103104
| threaded_dest_driver_general_option
@@ -120,12 +121,6 @@ loki_label
120121
}
121122
;
122123

123-
loki_timestamp_enum
124-
: KW_CURRENT { loki_dd_set_timestamp(last_driver, LM_TS_PROCESSED); }
125-
| KW_RECEIVED { loki_dd_set_timestamp(last_driver, LM_TS_RECVD); }
126-
| KW_MSG { loki_dd_set_timestamp(last_driver, LM_TS_STAMP); }
127-
;
128-
129124
loki_keepalive_options
130125
: loki_keepalive_option loki_keepalive_options
131126
|

modules/grpc/loki/loki-parser.c

-3
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ static CfgLexerKeyword loki_keywords[] =
3434
{ "url", KW_URL },
3535
{ "labels", KW_LABELS },
3636
{ "timestamp", KW_TIMESTAMP },
37-
{ "current", KW_CURRENT },
38-
{ "received", KW_RECEIVED },
39-
{ "msg", KW_MSG },
4037
{ "keep_alive", KW_KEEP_ALIVE },
4138
{ "time", KW_TIME },
4239
{ "timeout", KW_TIMEOUT },

news/other-4688.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
`loki()`: The `timestamp()` option now supports quoted strings.
2+
3+
The valid values are the following, with or without quotes, case insensitive:
4+
* "current"
5+
* "received"
6+
* "msg"

0 commit comments

Comments
 (0)