|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +# Cloud Foundry Java Buildpack |
| 4 | +# Copyright 2013-2018 the original author or authors. |
| 5 | +# |
| 6 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +# you may not use this file except in compliance with the License. |
| 8 | +# You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, software |
| 13 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +# See the License for the specific language governing permissions and |
| 16 | +# limitations under the License. |
| 17 | + |
| 18 | +require 'fileutils' |
| 19 | +require 'java_buildpack/component/versioned_dependency_component' |
| 20 | +require 'java_buildpack/framework' |
| 21 | + |
| 22 | +module JavaBuildpack |
| 23 | + module Framework |
| 24 | + |
| 25 | + # Encapsulates the functionality for enabling Sky walking APM support. |
| 26 | + class SkyWalkingAgent < JavaBuildpack::Component::VersionedDependencyComponent |
| 27 | + |
| 28 | + # (see JavaBuildpack::Component::BaseComponent#compile) |
| 29 | + def compile |
| 30 | + download_tar(true, @droplet.sandbox, 'sky_walking_agent') |
| 31 | + @droplet.copy_resources |
| 32 | + end |
| 33 | + |
| 34 | + # (see JavaBuildpack::Component::BaseComponent#release) |
| 35 | + def release |
| 36 | + credentials = @application.services.find_service(FILTER, 'servers')['credentials'] |
| 37 | + java_opts = @droplet.java_opts |
| 38 | + java_opts.add_javaagent(@droplet.sandbox + 'skywalking-agent.jar') |
| 39 | + |
| 40 | + application_name java_opts, credentials |
| 41 | + sample_n_per_3_secs java_opts, credentials |
| 42 | + span_limit_per_segment java_opts, credentials |
| 43 | + ignore_suffix java_opts, credentials |
| 44 | + open_debugging_class java_opts, credentials |
| 45 | + servers java_opts, credentials |
| 46 | + logging_level java_opts, credentials |
| 47 | + end |
| 48 | + |
| 49 | + protected |
| 50 | + |
| 51 | + # (see JavaBuildpack::Component::VersionedDependencyComponent#supports?) |
| 52 | + def supports? |
| 53 | + @application.services.one_service? FILTER, 'servers' |
| 54 | + end |
| 55 | + |
| 56 | + private |
| 57 | + |
| 58 | + FILTER = /sky[-]?walking/ |
| 59 | + |
| 60 | + private_constant :FILTER |
| 61 | + |
| 62 | + def servers(java_opts, credentials) |
| 63 | + servers = credentials['servers'] |
| 64 | + raise "'servers' credential must be set" unless servers |
| 65 | + java_opts.add_system_property 'skywalking.collector.servers', servers |
| 66 | + end |
| 67 | + |
| 68 | + def application_name(java_opts, credentials) |
| 69 | + name = credentials['application-name'] || @configuration['default_application_name'] || |
| 70 | + @application.details['application_name'] |
| 71 | + java_opts.add_system_property('skywalking.agent.application_code', name.to_s) |
| 72 | + end |
| 73 | + |
| 74 | + def sample_n_per_3_secs(java_opts, credentials) |
| 75 | + sample_n_per_3_secs = credentials['sample-n-per-3-secs'] |
| 76 | + java_opts.add_system_property 'skywalking.agent.sample_n_per_3_secs', sample_n_per_3_secs if sample_n_per_3_secs |
| 77 | + end |
| 78 | + |
| 79 | + def span_limit_per_segment(java_opts, credentials) |
| 80 | + span_lmt_per_seg = credentials['span-limit-per-segment'] |
| 81 | + java_opts.add_system_property 'skywalking.agent.span_limit_per_segment', span_lmt_per_seg if span_lmt_per_seg |
| 82 | + end |
| 83 | + |
| 84 | + def ignore_suffix(java_opts, credentials) |
| 85 | + ignore_suffix = credentials['ignore-suffix'] |
| 86 | + java_opts.add_system_property 'skywalking.agent.ignore_suffix', ignore_suffix if ignore_suffix |
| 87 | + end |
| 88 | + |
| 89 | + def open_debugging_class(java_opts, credentials) |
| 90 | + is_debug_class = credentials['is-open-debugging-class'] |
| 91 | + java_opts.add_system_property 'skywalking.agent.is_open_debugging_class', is_debug_class if is_debug_class |
| 92 | + end |
| 93 | + |
| 94 | + def logging_level(java_opts, credentials) |
| 95 | + logging_level = credentials['logging-level'] |
| 96 | + java_opts.add_system_property 'skywalking.logging.level', logging_level if logging_level |
| 97 | + end |
| 98 | + |
| 99 | + end |
| 100 | + |
| 101 | + end |
| 102 | +end |
0 commit comments