Skip to content

Commit

Permalink
confgenerator: add resource_name label using modify fields. (#544)
Browse files Browse the repository at this point in the history
* add resource_name label using hostName value.
* add integration test to verify resource_name.
* Update goldens.
  • Loading branch information
franciscovalentecastro authored May 2, 2022
1 parent ef00525 commit b653dab
Show file tree
Hide file tree
Showing 592 changed files with 6,745 additions and 3,006 deletions.
2 changes: 1 addition & 1 deletion confgenerator/confgenerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func (l *Logging) generateFluentbitComponents(userAgent string, hostInfo *host.I
}
components = append(components, processor.Components(tag, strconv.Itoa(i))...)
}
components = append(components, setLogNameComponents(tag, rID, receiver.Type())...)
components = append(components, setLogNameComponents(tag, rID, receiver.Type(), hostInfo.Hostname)...)

// Logs ingested using the fluent_forward receiver must add the existing_tag
// on the record to the LogName. This is done with a Lua filter.
Expand Down
5 changes: 4 additions & 1 deletion confgenerator/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@ import (
)

// setLogNameComponents generates a series of components that rewrites the tag on log entries tagged `tag` to be `logName`.
func setLogNameComponents(tag, logName, receiverType string) []fluentbit.Component {
func setLogNameComponents(tag, logName, receiverType string, hostName string) []fluentbit.Component {
return LoggingProcessorModifyFields{
Fields: map[string]*ModifyField{
"logName": {
DefaultValue: &logName,
},
`labels."compute.googleapis.com/resource_name"`: {
DefaultValue: &hostName,
},
// `labels."agent.googleapis.com/receiver_type"`: {
// StaticValue: &receiverType,
// },
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

function process(tag, timestamp, record)
local __field_0 = (function()
if record["logging.googleapis.com/labels"] == nil
then
return nil
end
return record["logging.googleapis.com/labels"]["compute.googleapis.com/resource_name"]
end)();
local __field_1 = (function()
return record["logging.googleapis.com/logName"]
end)();
local v = __field_0;
if v == nil then v = "" end;
(function(value)
if record["logging.googleapis.com/labels"] == nil
then
record["logging.googleapis.com/labels"] = {}
end
record["logging.googleapis.com/labels"]["compute.googleapis.com/resource_name"] = value
end)(v)
local v = __field_1;
if v == nil then v = "syslog" end;
(function(value)
record["logging.googleapis.com/logName"] = value
end)(v)
return 2, timestamp, record
end
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
Match default_pipeline.syslog
Name lua
call process
script 10fdedaf5448c4114b7b329139f093fc.lua
script 8f841e1624ad9de1bb98322777b1ac10.lua

[OUTPUT]
Match_Regex ^(default_pipeline\.syslog)$
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

function process(tag, timestamp, record)
local __field_0 = (function()
if record["logging.googleapis.com/labels"] == nil
then
return nil
end
return record["logging.googleapis.com/labels"]["compute.googleapis.com/resource_name"]
end)();
local __field_1 = (function()
return record["logging.googleapis.com/logName"]
end)();
local v = __field_0;
if v == nil then v = "" end;
(function(value)
if record["logging.googleapis.com/labels"] == nil
then
record["logging.googleapis.com/labels"] = {}
end
record["logging.googleapis.com/labels"]["compute.googleapis.com/resource_name"] = value
end)(v)
local v = __field_1;
if v == nil then v = "syslog" end;
(function(value)
record["logging.googleapis.com/logName"] = value
end)(v)
return 2, timestamp, record
end
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
Match default_pipeline.syslog
Name lua
call process
script 10fdedaf5448c4114b7b329139f093fc.lua
script 8f841e1624ad9de1bb98322777b1ac10.lua

[OUTPUT]
Match_Regex ^(default_pipeline\.syslog)$
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

function process(tag, timestamp, record)
local __field_0 = (function()
if record["logging.googleapis.com/labels"] == nil
then
return nil
end
return record["logging.googleapis.com/labels"]["compute.googleapis.com/resource_name"]
end)();
local __field_1 = (function()
return record["logging.googleapis.com/logName"]
end)();
local v = __field_0;
if v == nil then v = "" end;
(function(value)
if record["logging.googleapis.com/labels"] == nil
then
record["logging.googleapis.com/labels"] = {}
end
record["logging.googleapis.com/labels"]["compute.googleapis.com/resource_name"] = value
end)(v)
local v = __field_1;
if v == nil then v = "syslog" end;
(function(value)
record["logging.googleapis.com/logName"] = value
end)(v)
return 2, timestamp, record
end
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
Match default_pipeline.syslog
Name lua
call process
script 10fdedaf5448c4114b7b329139f093fc.lua
script 8f841e1624ad9de1bb98322777b1ac10.lua

[OUTPUT]
Match_Regex ^(default_pipeline\.syslog)$
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

function process(tag, timestamp, record)
local __field_0 = (function()
if record["logging.googleapis.com/labels"] == nil
then
return nil
end
return record["logging.googleapis.com/labels"]["compute.googleapis.com/resource_name"]
end)();
local __field_1 = (function()
return record["logging.googleapis.com/logName"]
end)();
local v = __field_0;
if v == nil then v = "" end;
(function(value)
if record["logging.googleapis.com/labels"] == nil
then
record["logging.googleapis.com/labels"] = {}
end
record["logging.googleapis.com/labels"]["compute.googleapis.com/resource_name"] = value
end)(v)
local v = __field_1;
if v == nil then v = "syslog" end;
(function(value)
record["logging.googleapis.com/logName"] = value
end)(v)
return 2, timestamp, record
end
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
Match default_pipeline.syslog
Name lua
call process
script 10fdedaf5448c4114b7b329139f093fc.lua
script 8f841e1624ad9de1bb98322777b1ac10.lua

[OUTPUT]
Match_Regex ^(default_pipeline\.syslog)$
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

function process(tag, timestamp, record)
local __field_0 = (function()
if record["logging.googleapis.com/labels"] == nil
then
return nil
end
return record["logging.googleapis.com/labels"]["compute.googleapis.com/resource_name"]
end)();
local __field_1 = (function()
return record["logging.googleapis.com/logName"]
end)();
local v = __field_0;
if v == nil then v = "" end;
(function(value)
if record["logging.googleapis.com/labels"] == nil
then
record["logging.googleapis.com/labels"] = {}
end
record["logging.googleapis.com/labels"]["compute.googleapis.com/resource_name"] = value
end)(v)
local v = __field_1;
if v == nil then v = "test_syslog_source_id_tcp" end;
(function(value)
record["logging.googleapis.com/logName"] = value
end)(v)
return 2, timestamp, record
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

function process(tag, timestamp, record)
local __field_0 = (function()
if record["logging.googleapis.com/labels"] == nil
then
return nil
end
return record["logging.googleapis.com/labels"]["compute.googleapis.com/resource_name"]
end)();
local __field_1 = (function()
return record["logging.googleapis.com/logName"]
end)();
local v = __field_0;
if v == nil then v = "" end;
(function(value)
if record["logging.googleapis.com/labels"] == nil
then
record["logging.googleapis.com/labels"] = {}
end
record["logging.googleapis.com/labels"]["compute.googleapis.com/resource_name"] = value
end)(v)
local v = __field_1;
if v == nil then v = "log_source_id2" end;
(function(value)
record["logging.googleapis.com/logName"] = value
end)(v)
return 2, timestamp, record
end

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

function process(tag, timestamp, record)
local __field_0 = (function()
if record["logging.googleapis.com/labels"] == nil
then
return nil
end
return record["logging.googleapis.com/labels"]["compute.googleapis.com/resource_name"]
end)();
local __field_1 = (function()
return record["logging.googleapis.com/logName"]
end)();
local v = __field_0;
if v == nil then v = "" end;
(function(value)
if record["logging.googleapis.com/labels"] == nil
then
record["logging.googleapis.com/labels"] = {}
end
record["logging.googleapis.com/labels"]["compute.googleapis.com/resource_name"] = value
end)(v)
local v = __field_1;
if v == nil then v = "test_syslog_source_id_udp" end;
(function(value)
record["logging.googleapis.com/logName"] = value
end)(v)
return 2, timestamp, record
end

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

function process(tag, timestamp, record)
local __field_0 = (function()
if record["logging.googleapis.com/labels"] == nil
then
return nil
end
return record["logging.googleapis.com/labels"]["compute.googleapis.com/resource_name"]
end)();
local __field_1 = (function()
return record["logging.googleapis.com/logName"]
end)();
local v = __field_0;
if v == nil then v = "" end;
(function(value)
if record["logging.googleapis.com/labels"] == nil
then
record["logging.googleapis.com/labels"] = {}
end
record["logging.googleapis.com/labels"]["compute.googleapis.com/resource_name"] = value
end)(v)
local v = __field_1;
if v == nil then v = "log_source_id1" end;
(function(value)
record["logging.googleapis.com/logName"] = value
end)(v)
return 2, timestamp, record
end
Loading

0 comments on commit b653dab

Please sign in to comment.