-
Notifications
You must be signed in to change notification settings - Fork 2.7k
feat: implement GetDependencies method for api_v3 QueryService #7634
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
Open
Harsh-6291
wants to merge
6
commits into
jaegertracing:main
Choose a base branch
from
Harsh-6291:feat/add-getdependencies-v3api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b32c492
feat: implement GetDependencies method for api_v3 QueryService
Harsh-6291 d25dc2b
Merge branch 'main' into feat/add-getdependencies-v3api
Harsh-6291 b2ef5b7
Merge branch 'main' into feat/add-getdependencies-v3api
Harsh-6291 5e27923
Merge branch 'main' into feat/add-getdependencies-v3api
Harsh-6291 eb2034d
Merge branch 'main' into feat/add-getdependencies-v3api
Harsh-6291 7032836
Merge branch 'main' into feat/add-getdependencies-v3api
Harsh-6291 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| package v3api | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "time" | ||
|
|
||
| api_v3 "github.com/jaegertracing/jaeger-idl/proto-gen/api_v3" | ||
| "github.com/jaegertracing/jaeger/internal/storage/v1/api/dependencystore" | ||
| "go.uber.org/zap" | ||
| "google.golang.org/grpc/codes" | ||
| "google.golang.org/grpc/status" | ||
| ) | ||
|
|
||
| // Handler implements api_v3.QueryServiceServer | ||
| type Handler struct { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. all handlers are already defined in cmd/query/app/apiv3 |
||
| api_v3.UnimplementedQueryServiceServer | ||
|
|
||
| depReader dependencystore.Reader | ||
| logger *zap.Logger | ||
| } | ||
|
|
||
| // HandlerOptions contains options for creating a new Handler | ||
| type HandlerOptions struct { | ||
| DependencyReader dependencystore.Reader | ||
| Logger *zap.Logger | ||
| } | ||
|
|
||
| // NewHandler creates a new v3 API handler | ||
| func NewHandler(options HandlerOptions) *Handler { | ||
| return &Handler{ | ||
| depReader: options.DependencyReader, | ||
| logger: options.Logger, | ||
| } | ||
| } | ||
|
|
||
| // GetDependencies retrieves service dependency links for a given time interval | ||
| func (h *Handler) GetDependencies( | ||
| ctx context.Context, | ||
| req *api_v3.GetDependenciesRequest, | ||
| ) (*api_v3.GetDependenciesResponse, error) { | ||
| // Validate request | ||
| if err := h.validateGetDependenciesRequest(req); err != nil { | ||
| h.logger.Error("Invalid GetDependencies request", zap.Error(err)) | ||
| return nil, err | ||
| } | ||
|
|
||
| endTime := req.EndTime.AsTime() | ||
| lookback := req.Lookback.AsDuration() | ||
|
|
||
| h.logger.Debug("Fetching dependencies", | ||
| zap.Time("end_time", endTime), | ||
| zap.Duration("lookback", lookback), | ||
| ) | ||
|
|
||
| // Fetch dependencies from storage | ||
| dependencies, err := h.depReader.GetDependencies(ctx, endTime, lookback) | ||
| if err != nil { | ||
| h.logger.Error("Failed to fetch dependencies from storage", zap.Error(err)) | ||
| return nil, status.Error( | ||
| codes.Internal, | ||
| fmt.Sprintf("failed to fetch dependencies: %v", err), | ||
| ) | ||
| } | ||
|
|
||
| // Convert model.DependencyLink to api_v3.DependencyLink | ||
| links := make([]*api_v3.DependencyLink, 0, len(dependencies)) | ||
| for _, dep := range dependencies { | ||
| links = append(links, &api_v3.DependencyLink{ | ||
| Parent: dep.Parent, | ||
| Child: dep.Child, | ||
| CallCount: dep.CallCount, | ||
| Source: dep.Source, | ||
| }) | ||
| } | ||
|
|
||
| h.logger.Debug("Successfully fetched dependencies", | ||
| zap.Int("count", len(links)), | ||
| ) | ||
|
|
||
| return &api_v3.GetDependenciesResponse{ | ||
| Dependencies: links, | ||
| }, nil | ||
| } | ||
|
|
||
| // validateGetDependenciesRequest validates the GetDependencies request parameters | ||
| func (h *Handler) validateGetDependenciesRequest(req *api_v3.GetDependenciesRequest) error { | ||
| if req == nil { | ||
| return status.Error(codes.InvalidArgument, "request cannot be nil") | ||
| } | ||
|
|
||
| if req.EndTime == nil { | ||
| return status.Error(codes.InvalidArgument, "end_time is required") | ||
| } | ||
|
|
||
| if req.Lookback == nil { | ||
| return status.Error(codes.InvalidArgument, "lookback is required") | ||
| } | ||
|
|
||
| endTime := req.EndTime.AsTime() | ||
| lookback := req.Lookback.AsDuration() | ||
|
|
||
| // Validate lookback is positive | ||
| if lookback <= 0 { | ||
| return status.Error( | ||
| codes.InvalidArgument, | ||
| "lookback must be a positive duration", | ||
| ) | ||
| } | ||
|
|
||
| // Validate end_time is not too far in the future (allow small clock skew) | ||
| maxFutureTime := time.Now().Add(1 * time.Hour) | ||
| if endTime.After(maxFutureTime) { | ||
| return status.Error( | ||
| codes.InvalidArgument, | ||
| "end_time cannot be more than 1 hour in the future", | ||
| ) | ||
| } | ||
|
|
||
| // Validate the time range is reasonable (not too far back) | ||
| startTime := endTime.Add(-lookback) | ||
| minTime := time.Unix(0, 0) | ||
| if startTime.Before(minTime) { | ||
| return status.Error( | ||
| codes.InvalidArgument, | ||
| "time range extends before Unix epoch", | ||
| ) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
query service doesn't return its underlying components, why is this necessary?