Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NH-66480: remove packagecloud and downgrade graphql version #48

Merged
merged 10 commits into from
Jan 22, 2024
Merged
2 changes: 2 additions & 0 deletions .github/codeql/codeql-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
paths-ignore:
- 'test/**/*.rb'
49 changes: 49 additions & 0 deletions .github/workflows/build_for_github_package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Copyright (c) 2023 SolarWinds, LLC.
# All rights reserved.

name: Ruby Gem to Github Package

on:
workflow_dispatch:

jobs:
build:
name: Build + Publish to Github Package
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up Ruby 2.7 and bundle
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7

- name: Install gems
run: |
echo 'gem: --no-document' >> ~/.gemrc
bundle install

- name: Install swig 4.0.2
run: |
apt udate && apt install -y --no-install-recommends bison
curl -SL https://github.com/swig/swig/archive/refs/tags/v4.0.2.tar.gz | tar xzC /tmp
cd /tmp/swig-4.0.2
./autogen.sh && ./configure && make && sudo make install
cd -

- name: Grab current version
id: version
run: |
echo "gem_version=`ruby -e 'require "./lib/solarwinds_apm/version"; puts SolarWindsAPM::Version::STRING'`" >> $GITHUB_OUTPUT

- name: Build gem and publish to github package
id: gemstep
run: |
mkdir ~/.gem
echo -e "---\n:github: Bearer $GITHUB_SECRET_TOKEN" >> ~/.gem/credentials
chmod 0600 ~/.gem/credentials
bundle exec rake build_gem_for_github_package[${{ steps.version.outputs.gem_version }}]
bundle exec rake push_gem_to_github_package[${{ steps.version.outputs.gem_version }}]
env:
GITHUB_SECRET_TOKEN: ${{ secrets.GITHUB_TOKEN }}
59 changes: 0 additions & 59 deletions .github/workflows/build_for_packagecloud.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ jobs:
uses: actions/checkout@v3

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
queries: security-extended,security-and-quality
config-file: ./.github/codeql/codeql-config.yml

- name: Autobuild
uses: github/codeql-action/autobuild@v2
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/docker-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3

- name: Log in to the Container Registry
uses: docker/login-action@v2
Expand All @@ -42,7 +42,7 @@ jobs:

- name: Extract metadata (tags, labels) for Docker (both ARM and AMD64)
id: meta
uses: docker/metadata-action@v4
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}_${{ matrix.os }} # e.g. apm_ruby_ubuntu
flavor: |
Expand Down
21 changes: 17 additions & 4 deletions .github/workflows/scripts/_helper_run_install_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,22 @@ rbenv local $RUBY_VERSION
if [ "$MODE" = "RubyGem" ]; then
echo "RubyGem"
gem install solarwinds_apm -v "$SOLARWINDS_APM_VERSION"
elif [ "$MODE" = "packagecloud" ]; then
echo "packagecloud"
gem install solarwinds_apm -v "$SOLARWINDS_APM_VERSION" --source https://packagecloud.io/solarwinds/solarwinds-apm-ruby/
ruby ./home/.github/workflows/scripts/test_install.rb
elif [ "$MODE" = "GitHub" ]; then
echo "GitHub"
VERSION_LOWER_CASE=$(echo "$SOLARWINDS_APM_VERSION" | tr '[:upper:]' '[:lower:]')
echo "source 'https://rubygems.org'" >> Gemfile
echo "source 'https://rubygems.pkg.github.com/solarwinds' do" >> Gemfile
echo " gem 'solarwinds_apm', '${VERSION_LOWER_CASE}'" >> Gemfile
echo "end" >> Gemfile
gem install bundler
bundle install
bundle exec ruby ./home/.github/workflows/scripts/test_install.rb
fi

ruby ./home/.github/workflows/scripts/test_install.rb
if [ $? -ne 0 ]; then
echo "Problem encountered"
exit 1
fi

exit 0
12 changes: 6 additions & 6 deletions .github/workflows/verify_install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ on:
inputs:
install-registry:
required: true
description: 'Registry used for install tests, e.g. RubyGem, packagecloud'
description: 'Registry used for install tests, e.g. RubyGem, GitHub'
type: choice
default: 'RubyGem'
options:
- RubyGem
- packagecloud
- GitHub

solarwinds-version:
required: true
Expand Down Expand Up @@ -46,7 +46,7 @@ jobs:
-e SW_APM_SERVICE_KEY=${{ secrets.SW_APM_SERVICE_KEY_PROD }} \
-e SW_APM_COLLECTOR=${{ secrets.SW_APM_COLLECTOR_PROD }} \
-e SOLARWINDS_APM_VERSION=${{ github.event.inputs.solarwinds-version }} \
-e PACKAGECLOUD_TOKEN=${{ secrets.PACKAGECLOUD_TOKEN }} \
-e BUNDLE_RUBYGEMS__PKG__GITHUB__COM=${{ secrets.GITHUB_TOKEN }} \
-e MODE=${{ github.event.inputs.install-registry }} \
-e RUBY_VERSION=${{ matrix.ruby_version }} \
-v $(pwd):/home \
Expand Down Expand Up @@ -84,7 +84,7 @@ jobs:
-e SW_APM_SERVICE_KEY=${{ secrets.SW_APM_SERVICE_KEY_PROD }} \
-e SW_APM_COLLECTOR=${{ secrets.SW_APM_COLLECTOR_PROD }} \
-e SOLARWINDS_APM_VERSION=${{ github.event.inputs.solarwinds-version }} \
-e PACKAGECLOUD_TOKEN=${{ secrets.PACKAGECLOUD_TOKEN }} \
-e BUNDLE_RUBYGEMS__PKG__GITHUB__COM=${{ secrets.GITHUB_TOKEN }} \
-e MODE=${{ github.event.inputs.install-registry }} \
-e RUBY_VERSION=${{ matrix.ruby_version }} \
-v $(pwd):/home \
Expand All @@ -111,7 +111,7 @@ jobs:
-e SW_APM_SERVICE_KEY=${{ secrets.SW_APM_SERVICE_KEY_PROD }} \
-e SW_APM_COLLECTOR=${{ secrets.SW_APM_COLLECTOR_PROD }} \
-e SOLARWINDS_APM_VERSION=${{ github.event.inputs.solarwinds-version }} \
-e PACKAGECLOUD_TOKEN=${{ secrets.PACKAGECLOUD_TOKEN }} \
-e BUNDLE_RUBYGEMS__PKG__GITHUB__COM=${{ secrets.GITHUB_TOKEN }} \
-e MODE=${{ github.event.inputs.install-registry }} \
-v $(pwd):/home \
--rm redhat/ubi8 \
Expand All @@ -138,7 +138,7 @@ jobs:
-e SW_APM_SERVICE_KEY=${{ secrets.SW_APM_SERVICE_KEY_PROD }} \
-e SW_APM_COLLECTOR=${{ secrets.SW_APM_COLLECTOR_PROD }} \
-e SOLARWINDS_APM_VERSION=${{ github.event.inputs.solarwinds-version }} \
-e PACKAGECLOUD_TOKEN=${{ secrets.PACKAGECLOUD_TOKEN }} \
-e BUNDLE_RUBYGEMS__PKG__GITHUB__COM=${{ secrets.GITHUB_TOKEN }} \
-e MODE=${{ github.event.inputs.install-registry }} \
-v $(pwd):/home \
--rm redhat/ubi8 \
Expand Down
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ group :development, :test do
gem 'byebug', '>= 8.0.0'
gem 'irb', '>= 1.0.0' # if RUBY_VERSION >= '2.6.0'
gem 'memory_profiler'
gem 'package_cloud'
end

gemspec
45 changes: 23 additions & 22 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -393,36 +393,37 @@ task :build_gem do
puts "\n=== Finished ===\n"
end

desc "Build gem and push to packagecloud. Run as bundle exec rake build_gem_push_to_packagecloud[<version>]"
task :build_gem_push_to_packagecloud, [:version] do |t, args|
def find_or_build_gem(version)
abort('No version specified.') if version.to_s.empty?

require 'package_cloud'

puts "\n=== Ready to push solarwinds_apm #{args[:version]} ===\n"

abort("Require PACKAGECLOUD_TOKEN\n See here: https://packagecloud.io/docs ") if ENV["PACKAGECLOUD_TOKEN"]&.empty? || ENV["PACKAGECLOUD_TOKEN"].nil?
abort("No version specified.") if args[:version]&.empty? || args[:version].nil?

gems = Dir["builds/solarwinds_apm-#{args[:version]}.gem"]
gems = Dir["builds/solarwinds_apm-#{version}.gem"]
gem_to_push = nil
if gems.size == 0
Rake::Task["build_gem"].execute
if gems.empty?
Rake::Task['build_gem'].execute
gem_to_push = `ls -dt1 builds/solarwinds_apm-[^pre]*.gem | head -1`
else
gem_to_push = gems.first
end

puts "\n=== Gem will be pushed #{gem_to_push} ===\n"
gem_to_push_version = gem_to_push&.match(/-\d*.\d*.\d*/).to_s.gsub("-","")
gem_to_push_version = gem_to_push&.match(/-\d*.\d*.\d*.\d*pre/).to_s.gsub("-","") if args[:version].include? "pre"
puts "\n=== gem_to_push_version: #{gem_to_push_version} ===\n"

abort("Couldn't find the required gem file.") if gem_to_push.nil? || gem_to_push_version != args[:version]

cli = PackageCloud::CLI::Entry.new
cli.push("solarwinds/solarwinds-apm-ruby", gem_to_push.strip())
puts "\n=== Gem will be pushed #{gem_to_push} ==="
gem_to_push_version = gem_to_push&.match(/-\d*.\d*.\d*/).to_s.delete!('-')
gem_to_push_version = gem_to_push&.match(/-\d*.\d*.\d*.prev[0-9]*/).to_s.delete!('-') if version.include? 'prev'

puts "\n=== Finished ===\n"
abort('Could not find the required gem file.') if gem_to_push.nil? || gem_to_push_version != version

gem_to_push
end

# need set the credentials under ~/.gem/credentials
# for download, easiest way is to set BUNDLE_RUBYGEMS__PKG__GITHUB__COM
# but there are other auth methods. see more on https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-rubygems-registry
desc 'Push to github package. Run as bundle exec rake build_gem_push_to_github_package[<version>]'
task :push_gem_to_github_package, [:version] do |_, args|
exit 1 unless system('gem', 'push', '--key', 'github', '--host', 'https://rubygems.pkg.github.com/solarwinds', "builds/solarwinds_apm-#{args[:version]}.gem")
puts "\n=== Finished ===\n"
end

desc 'Build gem for github package'
task :build_gem_for_github_package, [:version] do |_, args|
find_or_build_gem(args[:version])
end
3 changes: 1 addition & 2 deletions gemfiles/libraries.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ gem 'faraday', '~> 1.0'
if RUBY_VERSION < '2.7'
gem 'graphql', '< 1.13.0'
else
gem 'graphql'
gem 'graphql', '2.1.1'
end
gem 'httpclient'
gem 'logging'
Expand All @@ -61,7 +61,6 @@ gem 'typhoeus'
# Database adapter gems needed by sequel
gem 'mysql2'
gem 'pg'
gem 'package_cloud'

eval(File.read(File.join(File.dirname(__FILE__), 'test_gems.gemfile')))

Expand Down
2 changes: 1 addition & 1 deletion gemfiles/noop.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ source "https://rubygems.org"
if RUBY_VERSION < '2.6'
gem 'graphql', '< 1.13.0'
else
gem 'graphql'
gem 'graphql', '< 2.1.1'
end

eval(File.read(File.join(File.dirname(__FILE__), 'test_gems.gemfile')))
Expand Down
1 change: 0 additions & 1 deletion gemfiles/redis.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ gem 'typhoeus'
# Database adapter gems needed by sequel
gem 'mysql2'
gem 'pg'
gem 'package_cloud'

eval(File.read(File.join(File.dirname(__FILE__), 'test_gems.gemfile')))

Expand Down
2 changes: 1 addition & 1 deletion lib/solarwinds_apm/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def self.[]=(key, value)
def self.method_missing(sym, *args)
class_var_name = "@@#{sym}"

if sym.to_s =~ /(.+)=$/
if sym.to_s =~ /\A(.{1,20})=\z/
self[$1] = args.first
else
# Try part of the @@config hash first
Expand Down
6 changes: 5 additions & 1 deletion lib/solarwinds_apm/inst/graphql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class SolarWindsAPMTracing < GraphQL::Tracing::PlatformTracing
# These GraphQL events will show up as 'graphql.prep' spans
PREP_KEYS = ['lex', 'parse', 'validate', 'analyze_query', 'analyze_multiplex'].freeze
EXEC_KEYS = ['execute_multiplex', 'execute_query', 'execute_query_lazy'].freeze
MAX_QUERY_LENGTH = 1000

self.platform_keys = {
'lex' => 'lex',
Expand Down Expand Up @@ -150,7 +151,10 @@ def graphql_multiplex(data)

def sanitize(query)
return unless query

if query.length > MAX_QUERY_LENGTH
SolarWindsAPM.logger.warn '[solarwinds_apm/graphql] query is too long for sanitizing. Return empty query string.'
return ''
end
# remove arguments
query.gsub(/"[^"]*"/, '"?"') # strings
.gsub(/-?[0-9]*\.?[0-9]+e?[0-9]*/, '?') # ints + floats
Expand Down
23 changes: 0 additions & 23 deletions lib/solarwinds_apm/loading.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,6 @@
require 'digest/sha1'

module SolarWindsAPM
module Util
##
# This module was used solely for the deprecated RUM ID calculation
# but may be useful in the future.
#
module Base64URL
module_function

def encode(bin)
c = [bin].pack('m0').gsub(/\=+\Z/, '').tr('+/', '-_').rstrip
m = c.size % 4
c += '=' * (4 - m) if m != 0
c
end

def decode(bin)
m = bin.size % 4
bin += '=' * (4 - m) if m != 0
bin.tr('-_', '+/').unpack('m0').first
end
end
end

##
# This module houses all of the loading functionality for the solarwinds_apm em.

Expand Down
Loading