Validate timestamp and nil fields in resources.lua

ElasticSearch has constrains of value type for existing fields.
So, we shouldn't send a string or invalid datetime information
into fields which have been already marked as datetime.
Validation and transformation invalid data is implemented in
this CR.

Change-Id: I8c91edc6e41d1a12fa792b2891d926e31d3171e6
diff --git a/heka/files/lua/common/resources.lua b/heka/files/lua/common/resources.lua
index e33264e..dc18329 100644
--- a/heka/files/lua/common/resources.lua
+++ b/heka/files/lua/common/resources.lua
@@ -31,8 +31,6 @@
     return patt.Uuid:match(uuid)
 end
 
-local metadata_fields = {}
-
 local ResourcesDecoder = {}
 ResourcesDecoder.__index = ResourcesDecoder
 
@@ -70,11 +68,26 @@
 function add_resource_to_payload(sample, payload)
     local counter_name, _ = string.gsub(sample.counter_name, "%.", "\\")
 
+    local metadata = sample.resource_metadata
+    local local_metadata = {}
+
+    if type(metadata) == 'table' then
+        for name, value in ipairs(metadata) do
+            local transform = transform_functions[name]
+            if value ~= '' and value ~= nil then
+                if transform ~= nil then
+                    value = transform(value)
+                end
+                local_metadata[name] = value
+            end
+        end
+    end
+
     local resource_data = {
-        timestamp = sample.timestamp,
+        timestamp = utils.format_datetime(sample.timestamp),
         resource_id = sample.resource_id,
         source = sample.source or "",
-        metadata = sample.resource_metadata,
+        metadata = local_metadata,
         user_id = sample.user_id,
         project_id = sample.project_id,
         meter = {