Commit 4aa45a3c authored by Bob Van Landuyt's avatar Bob Van Landuyt

Always use UNKNOWN as fallback operation name for

Using `unknown` instead of `anonymous` to avoid confusion with an
unauthenticated user when an operation name was not
provided. Unrecognized operation names remain the same.
parent 1d5bb484
...@@ -14,7 +14,6 @@ module Gitlab ...@@ -14,7 +14,6 @@ module Gitlab
end end
end end
ANONYMOUS = Operation.new("anonymous").freeze
UNKNOWN = Operation.new("unknown").freeze UNKNOWN = Operation.new("unknown").freeze
def self.default def self.default
...@@ -24,7 +23,7 @@ module Gitlab ...@@ -24,7 +23,7 @@ module Gitlab
def initialize(operation_names) def initialize(operation_names)
@operation_hash = operation_names @operation_hash = operation_names
.map { |name| Operation.new(name).freeze } .map { |name| Operation.new(name).freeze }
.concat([ANONYMOUS, UNKNOWN]) .concat([UNKNOWN])
.index_by(&:name) .index_by(&:name)
end end
...@@ -32,7 +31,7 @@ module Gitlab ...@@ -32,7 +31,7 @@ module Gitlab
def from_query(query) def from_query(query)
operation_name = query.selected_operation_name operation_name = query.selected_operation_name
return ANONYMOUS unless operation_name return UNKNOWN unless operation_name
@operation_hash[operation_name] || UNKNOWN @operation_hash[operation_name] || UNKNOWN
end end
......
...@@ -19,7 +19,6 @@ RSpec.describe Gitlab::Graphql::KnownOperations do ...@@ -19,7 +19,6 @@ RSpec.describe Gitlab::Graphql::KnownOperations do
describe "#from_query" do describe "#from_query" do
where(:query_string, :expected) do where(:query_string, :expected) do
"query { helloWorld }" | described_class::ANONYMOUS
"query fuzzyyy { helloWorld }" | described_class::UNKNOWN "query fuzzyyy { helloWorld }" | described_class::UNKNOWN
"query foo { helloWorld }" | described_class::Operation.new("foo") "query foo { helloWorld }" | described_class::Operation.new("foo")
end end
...@@ -35,13 +34,13 @@ RSpec.describe Gitlab::Graphql::KnownOperations do ...@@ -35,13 +34,13 @@ RSpec.describe Gitlab::Graphql::KnownOperations do
describe "#operations" do describe "#operations" do
it "returns array of known operations" do it "returns array of known operations" do
expect(subject.operations.map(&:name)).to match_array(%w(anonymous unknown foo bar)) expect(subject.operations.map(&:name)).to match_array(%w(unknown foo bar))
end end
end end
describe "Operation#to_caller_id" do describe "Operation#to_caller_id" do
where(:query_string, :expected) do where(:query_string, :expected) do
"query { helloWorld }" | "graphql:#{described_class::ANONYMOUS.name}" "query { helloWorld }" | "graphql:#{described_class::UNKNOWN.name}"
"query foo { helloWorld }" | "graphql:foo" "query foo { helloWorld }" | "graphql:foo"
end end
......
...@@ -28,7 +28,7 @@ RSpec.describe Gitlab::Metrics::RailsSlis do ...@@ -28,7 +28,7 @@ RSpec.describe Gitlab::Metrics::RailsSlis do
} }
] ]
possible_graphql_labels = ['graphql:foo', 'graphql:bar', 'graphql:unknown', 'graphql:anonymous'].map do |endpoint_id| possible_graphql_labels = ['graphql:foo', 'graphql:bar', 'graphql:unknown'].map do |endpoint_id|
{ {
endpoint_id: endpoint_id, endpoint_id: endpoint_id,
feature_category: nil, feature_category: nil,
......
...@@ -15,7 +15,7 @@ RSpec.describe 'GraphQL' do ...@@ -15,7 +15,7 @@ RSpec.describe 'GraphQL' do
let(:expected_execute_query_log) do let(:expected_execute_query_log) do
{ {
"correlation_id" => kind_of(String), "correlation_id" => kind_of(String),
"meta.caller_id" => "graphql:anonymous", "meta.caller_id" => "graphql:unknown",
"meta.client_id" => kind_of(String), "meta.client_id" => kind_of(String),
"meta.feature_category" => "not_owned", "meta.feature_category" => "not_owned",
"meta.remote_ip" => kind_of(String), "meta.remote_ip" => kind_of(String),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment