Skip to content

Feature/add mis endpoints in query #696

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
wants to merge 22 commits into
base: master
Choose a base branch
from

Conversation

bluepal-prasanthi-moparthi
Copy link
Collaborator

This includes the following Query-related endpoints:

  1. GET - _db/{database-name}/_api/query/properties
  2. PUT - _db/{database-name}/_api/query/properties
  3. GET - _db/{database-name}/_api/query/current
  4. GET - _db/{database-name}/_api/query/slow
  5. DELETE - _db/{database-name}/_api/query/slow
  6. DELETE - _db/{database-name}/_api/query/{query-id}
  7. GET - _db/{database-name}/_api/query/rules
  8. GET - _db/{database-name}/_api/query-plan-cache
  9. DELETE - _db/{database-name}/_api/query-plan-cache
  10. GET - _db/{database-name}/_api/query-cache/entries
  11. DELETE - _db/{database-name}/_api/query-cache
  12. GET - _db/{database-name}/_api/query-cache/properties
  13. PUT - _db/{database-name}/_api/query-cache/properties
  14. POST - _db/{database-name}/_api/aqlfunction
  15. DELETE - _db/{database-name}/_api/aqlfunction/{name}
  16. GET - _db/{database-name}/_api/aqlfunction

@bluepal-prasanthi-moparthi bluepal-prasanthi-moparthi force-pushed the feature/add_mis_endpoints_in_query branch from 02974e4 to f6a6c13 Compare August 6, 2025 11:57
@jwierzbo jwierzbo requested a review from Copilot August 7, 2025 07:14
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds 16 missing query-related endpoints to the ArangoDB Go driver v2, enabling comprehensive query management, caching, optimizer rules, and user-defined functions functionality. The implementation includes comprehensive test coverage for all new endpoints.

  • Adds query properties management (GET/PUT endpoints)
  • Implements query monitoring and control (current/slow queries, kill operations)
  • Adds query caching and plan caching management endpoints
  • Integrates user-defined function management capabilities

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
v2/utils/type.go Adds ToJSONString utility function for debugging and logging
v2/tests/database_query_test.go Comprehensive test suite for all 16 new query endpoints
v2/arangodb/utils.go Adds RequiredFieldError utility for validation
v2/arangodb/database_query_impl.go Core implementation of all query-related endpoints
v2/arangodb/database_query.go Interface definitions and data structures for query operations
v2/CHANGELOG.md Documents the addition of missing query endpoints

Comment on lines 223 to 224
// Log the raw response for debugging (remove in production)
fmt.Printf("DEBUG: Raw response from %s: %s\n", endpoint, string(rawResult))
Copy link
Preview

Copilot AI Aug 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug logging statement should be removed from production code. Consider using a proper logging framework or removing this debug print statement.

Suggested change
// Log the raw response for debugging (remove in production)
fmt.Printf("DEBUG: Raw response from %s: %s\n", endpoint, string(rawResult))
// Raw response available in rawResult for debugging if needed

Copilot uses AI. Check for mistakes.

GetAllOptimizerRules(ctx context.Context) ([]OptimizerRules, error)

// GetQueryPlanCache returns a list of cached query plans.
// The result is a list of QueryPlanChcheRespObject objects.
Copy link
Preview

Copilot AI Aug 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in the comment on line 83: 'QueryPlanChcheRespObject' should be 'QueryPlanCacheRespObject'.

Suggested change
// The result is a list of QueryPlanChcheRespObject objects.
// The result is a list of QueryPlanCacheRespObject objects.

Copilot uses AI. Check for mistakes.

}

type QueryCacheProperties struct {
// IncludesSystem indicates whether the query cache includes system collections.
Copy link
Preview

Copilot AI Aug 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment inconsistency: the comment says 'IncludesSystem' but the field name is 'IncludeSystem'. The comment should match the field name.

Suggested change
// IncludesSystem indicates whether the query cache includes system collections.
// IncludeSystem indicates whether the query cache includes system collections.

Copilot uses AI. Check for mistakes.

Comment on lines +161 to +189
func validateQueryPropertiesFields(options QueryProperties) error {
if options.Enabled == nil {
return RequiredFieldError("enabled")
}
if options.TrackSlowQueries == nil {
return RequiredFieldError("trackSlowQueries")
}
if options.TrackBindVars == nil {
return RequiredFieldError("trackBindVars")
}
if options.MaxSlowQueries == nil {
return RequiredFieldError("maxSlowQueries")
}
if options.SlowQueryThreshold == nil {
return RequiredFieldError("slowQueryThreshold")
}
if options.MaxQueryStringLength == nil {
return RequiredFieldError("maxQueryStringLength")
}
return nil
}

func (d databaseQuery) UpdateQueryProperties(ctx context.Context, options QueryProperties) (QueryProperties, error) {
url := d.db.url("_api", "query", "properties")

// Validate all fields are set
if err := validateQueryPropertiesFields(options); err != nil {
return QueryProperties{}, err
}
Copy link
Preview

Copilot AI Aug 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The validation function requires all fields to be non-nil, but this may be overly restrictive for partial updates. Consider allowing optional fields or having separate validation for create vs update operations.

Suggested change
func validateQueryPropertiesFields(options QueryProperties) error {
if options.Enabled == nil {
return RequiredFieldError("enabled")
}
if options.TrackSlowQueries == nil {
return RequiredFieldError("trackSlowQueries")
}
if options.TrackBindVars == nil {
return RequiredFieldError("trackBindVars")
}
if options.MaxSlowQueries == nil {
return RequiredFieldError("maxSlowQueries")
}
if options.SlowQueryThreshold == nil {
return RequiredFieldError("slowQueryThreshold")
}
if options.MaxQueryStringLength == nil {
return RequiredFieldError("maxQueryStringLength")
}
return nil
}
func (d databaseQuery) UpdateQueryProperties(ctx context.Context, options QueryProperties) (QueryProperties, error) {
url := d.db.url("_api", "query", "properties")
// Validate all fields are set
if err := validateQueryPropertiesFields(options); err != nil {
return QueryProperties{}, err
}
// Validation for all fields is no longer required; partial updates are allowed.
func (d databaseQuery) UpdateQueryProperties(ctx context.Context, options QueryProperties) (QueryProperties, error) {
url := d.db.url("_api", "query", "properties")
// Partial updates are allowed; no need to validate all fields are set

Copilot uses AI. Check for mistakes.

Comment on lines 265 to 267
MaxSlowQueries: utils.NewType(*res.MaxSlowQueries + *utils.NewType(1)),
SlowQueryThreshold: utils.NewType(*res.SlowQueryThreshold + *utils.NewType(0.1)),
MaxQueryStringLength: utils.NewType(*res.MaxQueryStringLength + *utils.NewType(100)),
Copy link
Preview

Copilot AI Aug 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Complex pointer arithmetic with nested NewType calls makes the code hard to read. Consider simplifying: utils.NewType(*res.MaxSlowQueries + 1).

Suggested change
MaxSlowQueries: utils.NewType(*res.MaxSlowQueries + *utils.NewType(1)),
SlowQueryThreshold: utils.NewType(*res.SlowQueryThreshold + *utils.NewType(0.1)),
MaxQueryStringLength: utils.NewType(*res.MaxQueryStringLength + *utils.NewType(100)),
MaxSlowQueries: utils.NewType(*res.MaxSlowQueries + 1),
SlowQueryThreshold: utils.NewType(*res.SlowQueryThreshold + 0.1),
MaxQueryStringLength: utils.NewType(*res.MaxQueryStringLength + 100),

Copilot uses AI. Check for mistakes.


for cursor.HasMore() {
var doc map[string]interface{}
cursor.ReadDocument(ctx, &doc)
Copy link
Preview

Copilot AI Aug 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error from ReadDocument is being ignored, which could mask issues during cursor iteration. The error should be handled properly.

Suggested change
cursor.ReadDocument(ctx, &doc)
err := cursor.ReadDocument(ctx, &doc)
require.NoError(t, err)

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant