-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Polish the code and add plugins (#4)
- Loading branch information
1 parent
4f3e927
commit d38f200
Showing
27 changed files
with
639 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# 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. | ||
|
||
module Skywalking | ||
module Plugins | ||
class Elasticsearch < PluginsManager::SWPlugin | ||
def plugin_valid? | ||
defined?(::Elasticsearch) | ||
end | ||
|
||
def install | ||
inst_target = if defined?(::Elastic::Transport::Client) | ||
::Elastic::Transport::Client | ||
elsif defined?(::Elasticsearch::Transport::Client) | ||
::Elasticsearch::Transport::Client | ||
end | ||
|
||
inst_target.class_eval do | ||
def perform_request_with_skywalking(method, path, *args, &block) | ||
peer_info = transport.hosts.first | ||
db_statement = [{ params: args&.[](0) }] | ||
unless args[1].nil? || args[1].empty? | ||
db_statement << { body: args[1] } | ||
end | ||
|
||
Tracing::ContextManager.new_exit_span( | ||
operation: "Elasticsearch/#{method}/#{path}", | ||
peer: "#{peer_info[:protocol]}://#{peer_info[:host]}:#{peer_info[:port]}", | ||
component: Tracing::Component::Elasticsearch | ||
) do |span| | ||
span&.tag(Tracing::TagDbType.new("Elasticsearch")) | ||
span&.tag(Tracing::TagDbStatement.new(db_statement)) | ||
span&.layer = Tracing::Layer::Database | ||
|
||
zuper_perform_request(method, path, *args, &block) | ||
rescue | ||
span&.error_occurred = true | ||
end | ||
end | ||
|
||
alias_method :zuper_perform_request, :perform_request | ||
alias_method :perform_request, :perform_request_with_skywalking | ||
end | ||
end | ||
|
||
register :elasticsearch | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# 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. | ||
|
||
module Skywalking | ||
module Plugins | ||
module MemcachedIntercept | ||
def self.included(klass) | ||
supported_method = | ||
[:add, :append, :delete, :cas, :incr, :increment, :prepend, :replace, :set, :get, :fetch] | ||
.select do |method_name| | ||
klass.method_defined?(method_name) || klass.private_method_defined?(method_name) | ||
end | ||
|
||
supported_method.each do |method_name| | ||
zuper_method = :"zuper_#{method_name}" | ||
method_with_skywalking = :"#{method_name}_with_skywalking" | ||
|
||
klass.class_eval do | ||
define_method(method_with_skywalking) do |*args, &block| | ||
cache_key = args[0].to_s if args.length && !args[0].is_a?(Array) | ||
Tracing::ContextManager.new_exit_span( | ||
operation: "Memcached/#{method_name}", | ||
peer: @normalized_servers.join(','), | ||
component: Tracing::Component::Memcached | ||
) do |span| | ||
span&.layer = Tracing::Layer::Cache | ||
span&.tag(Tracing::TagCacheType.new("Memcached")) | ||
span&.tag(Tracing::TagCacheKey.new(cache_key)) | ||
|
||
resp = __send__(zuper_method, *args, &block) | ||
if method_name == :get && args.length && args[0].instance_of?(String) | ||
span&.tag(Tracing::TagCacheMiss.new(resp.nil?)) | ||
end | ||
|
||
resp | ||
rescue | ||
span&.error_occurred = true | ||
end | ||
end | ||
|
||
alias_method zuper_method, method_name | ||
alias_method method_name, method_with_skywalking | ||
end | ||
end | ||
end | ||
end | ||
|
||
class Memcached < PluginsManager::SWPlugin | ||
def plugin_valid? | ||
defined?(::Dalli::Client) | ||
end | ||
|
||
def install | ||
::Dalli::Client.class_eval do | ||
include Skywalking::Plugins::MemcachedIntercept | ||
end | ||
end | ||
|
||
register :memcached | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.