bisakhmondal commented on a change in pull request #5372:
URL: https://github.com/apache/apisix/pull/5372#discussion_r743555528



##########
File path: apisix/plugins/datadog.lua
##########
@@ -0,0 +1,269 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one or more
+-- contributor license agreements.  See the NOTICE file distributed with
+-- this work for additional information regarding copyright ownership.
+-- The ASF licenses this file to You under the Apache License, Version 2.0
+-- (the "License"); you may not use this file except in compliance with
+-- the License.  You may obtain a copy of the License at
+--
+--     http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+
+local core = require("apisix.core")
+local plugin = require("apisix.plugin")
+local batch_processor = require("apisix.utils.batch-processor")
+local fetch_log = require("apisix.utils.log-util").get_full_log
+local ngx = ngx
+local udp = ngx.socket.udp
+local format = string.format
+local concat = table.concat
+local buffers = {}
+local ipairs = ipairs
+local tostring = tostring
+local stale_timer_running = false
+local timer_at = ngx.timer.at
+
+local plugin_name = "datadog"
+local defaults = {
+    host = "127.0.0.1",
+    port = 8125,
+    namespace = "apisix",
+    constant_tags = {"source:apisix"}
+}
+
+local schema = {
+    type = "object",
+    properties = {
+        buffer_duration = {type = "integer", minimum = 1, default = 60},
+        inactive_timeout = {type = "integer", minimum = 1, default = 5},
+        batch_max_size = {type = "integer", minimum = 1, default = 5000},
+        max_retry_count = {type = "integer", minimum = 1, default = 1},
+    }
+}
+
+local metadata_schema = {
+    type = "object",
+    properties = {
+        host = {type = "string", default= defaults.host},
+        port = {type = "integer", minimum = 0, default = defaults.port},
+        namespace = {type = "string", default = defaults.namespace},
+        constant_tags = {
+            type = "array",
+            items = {type = "string"},
+            default = defaults.constant_tags
+        }
+    },
+}
+
+local _M = {
+    version = 0.1,
+    priority = 495,
+    name = plugin_name,
+    schema = schema,
+    metadata_schema = metadata_schema,
+}
+
+function _M.check_schema(conf, schema_type)
+    if schema_type == core.schema.TYPE_METADATA then
+        return core.schema.check(metadata_schema, conf)
+    end
+    return core.schema.check(schema, conf)
+end
+
+local function generate_tag(conf, const_tags)
+    local tags
+    if const_tags and #const_tags > 0 then
+        tags = core.table.deepcopy(const_tags)
+    else
+        tags = {}
+    end
+
+    if conf.route_id and conf.route_id ~= "" then
+        core.table.insert(tags, "route_id:" .. conf.route_id)
+    end
+
+    if conf.service_id and conf.service_id ~= "" then
+        core.table.insert(tags, "service_id:" .. conf.service_id)
+    end
+
+    if conf.consumer and conf.consumer ~= "" then
+        core.table.insert(tags, "consumer:" .. conf.consumer)
+    end
+    if conf.balancer_ip ~= "" then
+        core.table.insert(tags, "balancer_ip:" .. conf.balancer_ip)
+    end
+    if conf.response.status then
+        core.table.insert(tags, "response_status:" .. conf.response.status)
+    end
+
+    if tags ~= "" then
+        tags = "|#" .. concat(tags, ',')
+    end
+
+    return tags
+end

Review comment:
       todo
   ```suggestion
       if #tags > 0 then
           return "|#" .. concat(tags, ',')
       end
   
       return ""
   end
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@apisix.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to