Skip to content

Commit b467f87

Browse files
fix: missing agent_id in ReportHeader (#2)
Co-authored-by: Heikel <HBOU@equinor.com>
1 parent 1a6f9ad commit b467f87

File tree

4 files changed

+140
-12
lines changed

4 files changed

+140
-12
lines changed

proto/reports.proto

Lines changed: 129 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ syntax = "proto3";
66

77
import "google/protobuf/timestamp.proto";
88

9+
10+
911
package Report;
1012

1113
message Trace {
@@ -198,6 +200,26 @@ message Trace {
198200
}
199201
}
200202

203+
// The cost of the operation
204+
message Limits {
205+
// The result of the operation.
206+
string result = 1;
207+
// The strategy used in cost calculations.
208+
string strategy = 2;
209+
// The estimated cost as calculated via the strategy specified in strategy
210+
uint64 cost_estimated = 3;
211+
// The actual cost using the strategy specified in strategy
212+
uint64 cost_actual = 4;
213+
// The depth of the query
214+
uint64 depth = 5;
215+
// The height of the query
216+
uint64 height = 6;
217+
// The number of aliases in the query
218+
uint64 alias_count = 7;
219+
// The number of root fields in the query
220+
uint64 root_field_count = 8;
221+
}
222+
201223
// Wallclock time when the trace began.
202224
google.protobuf.Timestamp start_time = 4; // required
203225
// Wallclock time when the trace ended.
@@ -285,6 +307,9 @@ message Trace {
285307
// 0 is treated as 1 for backwards compatibility.
286308
double field_execution_weight = 31;
287309

310+
// The limits information of the query.
311+
Limits limits = 32;
312+
288313

289314
// removed: Node parse = 12; Node validate = 13;
290315
// Id128 server_id = 1; Id128 client_id = 2;
@@ -320,6 +345,9 @@ message ReportHeader {
320345
// attached to a schema in the backend.
321346
string executable_schema_id = 11;
322347

348+
// The unique reporting agent that generated this report.
349+
string agent_id = 13;
350+
323351
reserved 3; // removed string service = 3;
324352
}
325353

@@ -371,6 +399,29 @@ message QueryLatencyStats {
371399
reserved 1, 6, 9, 10;
372400
}
373401

402+
// Stats on the query that can be populated by the gateway or router.
403+
message LimitsStats {
404+
// The strategy used in cost calculations.
405+
string strategy = 1;
406+
// The estimated cost as calculated via the strategy specified in stats context
407+
// The reason that this is a histogram rather than fixed cost is that it can be affected by paging variables.
408+
repeated sint64 cost_estimated = 2 ;
409+
// The maximum estimated cost of the query
410+
uint64 max_cost_estimated = 3;
411+
// The actual cost using the strategy specified in stats context
412+
repeated sint64 cost_actual = 4 ;
413+
// The maximum estimated cost of the query
414+
uint64 max_cost_actual = 5;
415+
// The total depth of the query
416+
uint64 depth = 6;
417+
// The height of the query
418+
uint64 height = 7;
419+
// The number of aliases in the query
420+
uint64 alias_count = 8;
421+
// The number of root fields in the query
422+
uint64 root_field_count = 9;
423+
}
424+
374425
// The context around a block of stats and traces indicating from which client the operation was executed and its
375426
// operation type. Operation type and subtype are only used by Apollo Router.
376427
message StatsContext {
@@ -379,6 +430,12 @@ message StatsContext {
379430
string client_version = 3;
380431
string operation_type = 4;
381432
string operation_subtype = 5;
433+
// The result of the operation. Either OK or the error code that caused the operation to fail.
434+
// This will not contain all errors from a query, only the primary reason the operation failed. e.g. a limits failure or an auth failure.
435+
string result = 6;
436+
// Client awareness contexts
437+
string client_library_name = 7;
438+
string client_library_version = 8;
382439
}
383440

384441
message ContextualizedQueryLatencyStats {
@@ -426,12 +483,27 @@ message FieldStat {
426483
reserved 1, 2, 7, 8;
427484
}
428485

486+
// As FieldStat only gets returned for FTV1 payloads this is a separate message that can be used to collect stats in the router or gateway obtained directly from the request schema and response.
487+
message LocalFieldStat {
488+
string return_type = 1; // required; eg "String!" for User.email:String!
489+
// Histogram of returned array sizes
490+
repeated sint64 array_size = 2 ;
491+
}
492+
429493
message TypeStat {
430494
// Key is (eg) "email" for User.email:String!
431495
map<string, FieldStat> per_field_stat = 3;
496+
432497
reserved 1, 2;
433498
}
434499

500+
message LocalTypeStat {
501+
// Key is (eg) "email" for User.email:String!
502+
// Unlike FieldStat, this is populated outside of FTV1 requests.
503+
map<string, LocalFieldStat> local_per_field_stat = 1;
504+
}
505+
506+
435507
message ReferencedFieldsForType {
436508
// Contains (eg) "email" for User.email:String!
437509
repeated string field_names = 1;
@@ -482,25 +554,77 @@ message Report {
482554
// operations. If this is false, each operation is described in precisely
483555
// one of those two fields.
484556
bool traces_pre_aggregated = 7;
557+
558+
// This indicates whether or not extended references are enabled, which are within the stats with context and contain
559+
// input type and enum value references. We need this flag so we can tell if the option is enabled even when there are
560+
// no extended references to report.
561+
bool extended_references_enabled = 9;
562+
563+
// A list of features enabled by router at the time this report was generated.
564+
// It is expected to be included only by Apollo Router, not by any other reporting agent.
565+
repeated string router_features_enabled = 10;
485566
}
486567

568+
487569
message ContextualizedStats {
488570
StatsContext context = 1;
489571
QueryLatencyStats query_latency_stats = 2;
490572
// Key is type name. This structure provides data for the count and latency of individual
491573
// field executions and thus only reflects operations for which field-level tracing occurred.
492574
map<string, TypeStat> per_type_stat = 3;
493575

576+
// Extended references including input types and enum values.
577+
ExtendedReferences extended_references = 6;
578+
579+
// Per type stats that are obtained directly by the router or gateway rather than FTV1.
580+
map<string, LocalTypeStat> local_per_type_stat = 7;
581+
582+
// Stats that contain limits information for the query.
583+
LimitsStats limits_stats = 8;
584+
585+
// Total number of operations processed during this period for this context. This includes all operations, even if they are sampled
586+
// and not included in the query latency stats.
587+
uint64 operation_count = 9;
588+
494589
reserved 4, 5;
495590
}
496591

497592
message QueryMetadata {
498-
// The operation name. For now this is a required field if QueryMetadata is present.
593+
// The operation name. For operations with a PQ ID as the stats report key, either name or signature must be present in the metadata.
499594
string name = 1;
500-
// the operation signature. For now this is a required field if QueryMetadata is present.
595+
// the operation signature. For operations with a PQ ID as the stats report key, either name or signature must be present in the metadata.
501596
string signature = 2;
502597
// (Optional) Persisted query ID that was used to request this operation.
503598
string pq_id = 3;
599+
600+
}
601+
602+
message ExtendedReferences {
603+
map<string, InputTypeStats> input_types = 1;
604+
605+
// Map of enum name to stats about that enum.
606+
map<string, EnumStats> enum_values = 2;
607+
}
608+
609+
message InputTypeStats {
610+
// Map of input object type to the stats about the fields within that object.
611+
map<string, InputFieldStats> field_names = 1;
612+
}
613+
614+
message InputFieldStats {
615+
// The total number of operations that reference the input object field.
616+
uint64 refs = 1;
617+
618+
// The number of operations that reference the input object field as a null value.
619+
uint64 null_refs = 2;
620+
621+
// The number of operations that don't reference this input object field (the field is missing or undefined).
622+
uint64 missing = 3;
623+
}
624+
625+
message EnumStats {
626+
// Map of enum value name to the number of referencing operations.
627+
map<string, uint64> enum_values = 1;
504628
}
505629

506630
// A sequence of traces and stats. If Report.traces_pre_aggregated (at the top
@@ -518,12 +642,11 @@ message TracesAndStats {
518642
// (as FieldStats will include the concrete object type for fields referenced
519643
// via an interface type).
520644
map<string, ReferencedFieldsForType> referenced_fields_by_type = 4;
521-
// This field is used to validate that the algorithm used to construct `stats_with_context`
522-
// matches similar algorithms in Apollo's servers. It is otherwise ignored and should not
523-
// be included in reports.
524-
repeated Trace internal_traces_contributing_to_stats = 3 ;
525645

526646
// This is an optional field that is used to provide more context to the key of this object within the
527647
// traces_per_query map. If it's omitted, we assume the key is a standard operation name and signature key.
528648
QueryMetadata query_metadata = 5;
649+
650+
reserved 3;
529651
}
652+

src/lib.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ mod proto;
3030
pub mod register;
3131
mod report_aggregator;
3232

33-
mod runtime;
3433
mod packages;
34+
mod runtime;
3535

3636
use futures::SinkExt;
37+
use packages::serde_json;
3738
use protobuf::{well_known_types::timestamp::Timestamp, EnumOrUnknown, MessageField};
3839
use report_aggregator::ReportAggregator;
3940
use runtime::spawn;
40-
use packages::serde_json;
4141

4242
#[macro_use]
4343
extern crate tracing;
@@ -126,13 +126,15 @@ impl ApolloTracing {
126126
graph_id: String,
127127
variant: String,
128128
service_version: String,
129+
agent_id: String,
129130
) -> ApolloTracing {
130131
let report = ReportAggregator::initialize(
131132
authorization_token,
132133
hostname,
133134
graph_id,
134135
variant,
135136
service_version,
137+
agent_id,
136138
);
137139

138140
ApolloTracing {
@@ -186,8 +188,10 @@ impl Extension for ApolloTracingExtension {
186188
.filter(|(_, operation)| operation.node.ty == OperationType::Query)
187189
.any(|(_, operation)| operation.node.selection_set.node.items.iter().any(|selection| matches!(&selection.node, Selection::Field(field) if field.node.name.node == "__schema")));
188190
if !is_schema {
189-
let result: String =
190-
ctx.stringify_execute_doc(&document, &Variables::from_json(serde_json::from_str("{}").unwrap()));
191+
let result: String = ctx.stringify_execute_doc(
192+
&document,
193+
&Variables::from_json(serde_json::from_str("{}").unwrap()),
194+
);
191195
let name = document
192196
.operations
193197
.iter()

src/proto.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#[allow(unknown_lints)]
55
#[allow(unused_attributes)]
66
#[cfg_attr(rustfmt, rustfmt::skip)]
7-
#[allow(box_pointers)]
87
#[allow(dead_code)]
98
#[allow(missing_docs)]
109
#[allow(non_camel_case_types)]

src/report_aggregator/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use futures::{
77
use protobuf::Message;
88

99
use crate::{
10-
proto::reports::{Report, ReportHeader, Trace, TracesAndStats},
1110
packages::uname,
11+
proto::reports::{Report, ReportHeader, Trace, TracesAndStats},
1212
runtime::{abort, spawn, Instant, JoinHandle},
1313
};
1414

@@ -33,10 +33,12 @@ impl ReportAggregator {
3333
graph_id: String,
3434
variant: String,
3535
service_version: String,
36+
agent_id: String,
3637
) -> Self {
3738
let (tx, mut rx) = mpsc::channel::<(String, Trace)>(BUFFER_SLOTS);
3839

3940
let reported_header = ReportHeader {
41+
agent_id,
4042
uname: uname::uname()
4143
.ok()
4244
.unwrap_or_else(|| "No uname provided".to_string()),

0 commit comments

Comments
 (0)