From c90ccfee15a1038567f40a9a0f4eb09b4a49ceb6 Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Mon, 17 Feb 2020 18:30:55 +0100 Subject: [PATCH] enable datadog apm tracing. #420 --- Gemfile | 1 + Gemfile.lock | 3 +++ config/initializers/datadog-tracer.rb | 5 ++++ spec/graphql/types/query_type_spec.rb | 35 +++++++++++++++++++++++++++ 4 files changed, 44 insertions(+) create mode 100644 config/initializers/datadog-tracer.rb diff --git a/Gemfile b/Gemfile index e93041609..a95460e45 100644 --- a/Gemfile +++ b/Gemfile @@ -5,6 +5,7 @@ source "https://rubygems.org" gem "rails", "~> 5.2.0" gem "bootsnap", "~> 1.4", ">= 1.4.4", require: false gem "mysql2", "~> 0.4.4" +gem 'ddtrace', '~> 0.32.0' gem "dotenv" gem "rake", "~> 12.0" gem "oj", ">= 2.8.3" diff --git a/Gemfile.lock b/Gemfile.lock index 0d433d5f4..3e7a402d9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -179,6 +179,8 @@ GEM addressable dalli (2.7.10) database_cleaner (1.8.2) + ddtrace (0.32.0) + msgpack debug_inspector (0.0.3) diff-lcs (1.3) diffy (3.3.0) @@ -580,6 +582,7 @@ DEPENDENCIES crawler_detect dalli (~> 2.7, >= 2.7.6) database_cleaner + ddtrace (~> 0.32.0) diffy (~> 3.2, >= 3.2.1) dotenv elasticsearch (~> 7.1.0) diff --git a/config/initializers/datadog-tracer.rb b/config/initializers/datadog-tracer.rb new file mode 100644 index 000000000..50ec6b73f --- /dev/null +++ b/config/initializers/datadog-tracer.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +Datadog.configure do |c| + c.use :rails, service_name: "client-api" +end diff --git a/spec/graphql/types/query_type_spec.rb b/spec/graphql/types/query_type_spec.rb index 9bf5ce276..f003eb2b0 100644 --- a/spec/graphql/types/query_type_spec.rb +++ b/spec/graphql/types/query_type_spec.rb @@ -39,4 +39,39 @@ expect(response.dig("data", "datasets", "nodes", 0, "id")).to eq(datasets.first.identifier) end end + + describe "query for citationCount", elasticsearch: true do + let(:client) { create(:client) } + let(:doi) { create(:doi, client: client, aasm_state: "findable") } + let(:source_doi) { create(:doi, client: client, aasm_state: "findable") } + let(:source_doi2) { create(:doi, client: client, aasm_state: "findable") } + let!(:citation_event) { create(:event_for_datacite_crossref, subj_id: "https://doi.org/#{doi.doi}", obj_id: "https://doi.org/#{source_doi.doi}", relation_type_id: "is-referenced-by", occurred_at: "2015-06-13T16:14:19Z") } + let!(:citation_event2) { create(:event_for_datacite_crossref, subj_id: "https://doi.org/#{doi.doi}", obj_id: "https://doi.org/#{source_doi2.doi}", relation_type_id: "is-referenced-by", occurred_at: "2016-06-13T16:14:19Z") } + + before do + Doi.import + Event.import + sleep 1 + end + + let(:query) do + %(query { + datasets { + totalCount + nodes { + id + citationCount + } + } + }) + end + + it "returns all datasets" do + response = LupoSchema.execute(query).as_json + + expect(response.dig("data", "datasets", "totalCount")).to eq(3) + expect(response.dig("data", "datasets", "nodes").length).to eq(3) + expect(response.dig("data", "datasets", "nodes", 0, "citationCount")).to eq(2) + end + end end