Skip to content

Commit

Permalink
Add missing fields (#367)
Browse files Browse the repository at this point in the history
* Add missing fields

* TEST_NOT_WAIT_UNTIL_READY

* Generic type for State field

* Add custom unmarshall for State
  • Loading branch information
jwierzbo authored Feb 27, 2022
1 parent 11421c3 commit 344c139
Show file tree
Hide file tree
Showing 19 changed files with 136 additions and 19 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ __test_go_test:
--net=$(TEST_NET) \
-v "${ROOTDIR}":/usr/code ${TEST_RESOURCES_VOLUME} \
-e TEST_ENDPOINTS=$(TEST_ENDPOINTS) \
-e TEST_NOT_WAIT_UNTIL_READY=$(TEST_NOT_WAIT_UNTIL_READY) \
-e TEST_AUTHENTICATION=$(TEST_AUTHENTICATION) \
-e TEST_JWTSECRET=$(TEST_JWTSECRET) \
-e TEST_CONNECTION=$(TEST_CONNECTION) \
Expand Down Expand Up @@ -397,6 +398,7 @@ __test_v2_go_test:
--net=$(TEST_NET) \
-v "${ROOTDIR}":/usr/code:ro ${TEST_RESOURCES_VOLUME} \
-e TEST_ENDPOINTS=$(TEST_ENDPOINTS) \
-e TEST_NOT_WAIT_UNTIL_READY=$(TEST_NOT_WAIT_UNTIL_READY) \
-e TEST_AUTHENTICATION=$(TEST_AUTHENTICATION) \
-e TEST_JWTSECRET=$(TEST_JWTSECRET) \
-e TEST_MODE=$(TEST_MODE) \
Expand Down Expand Up @@ -458,6 +460,7 @@ run-tests-cluster-failover:
--privileged \
-v "${ROOTDIR}":/usr/code \
-e TEST_ENDPOINTS=http://127.0.0.1:7001,http://127.0.0.1:7006,http://127.0.0.1:7011 \
-e TEST_NOT_WAIT_UNTIL_READY=$(TEST_NOT_WAIT_UNTIL_READY) \
-e TEST_AUTHENTICATION=basic:root: \
-e GODEBUG=tls13=1 \
-w /usr/code/ \
Expand Down
1 change: 1 addition & 0 deletions client_databases_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func (c *client) DatabaseExists(ctx context.Context, name string) (bool, error)

type getDatabaseResponse struct {
Result []string `json:"result,omitempty"`
ArangoError
}

// Databases returns a list of all databases found by the client.
Expand Down
26 changes: 16 additions & 10 deletions client_server_admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ type ServerStatistics struct {
ClientUser ClientStats `json:"clientUser,omitempty"`
HTTP HTTPStats `json:"http"`
Server ServerStats `json:"server"`
ArangoError
}

// SystemStats contains statistical data about the system, this is part of
Expand Down Expand Up @@ -110,16 +111,18 @@ type ClientStats struct {

// HTTPStats contains statistics about the HTTP traffic.
type HTTPStats struct {
RequestsTotal int64 `json:"requestsTotal"`
RequestsAsync int64 `json:"requestsAsync"`
RequestsGet int64 `json:"requestsGet"`
RequestsHead int64 `json:"requestsHead"`
RequestsPost int64 `json:"requestsPost"`
RequestsPut int64 `json:"requestsPut"`
RequestsPatch int64 `json:"requestsPatch"`
RequestsDelete int64 `json:"requestsDelete"`
RequestsOptions int64 `json:"requestsOptions"`
RequestsOther int64 `json:"requestsOther"`
RequestsTotal int64 `json:"requestsTotal"`
RequestsAsync int64 `json:"requestsAsync"`
RequestsGet int64 `json:"requestsGet"`
RequestsHead int64 `json:"requestsHead"`
RequestsPost int64 `json:"requestsPost"`
RequestsPut int64 `json:"requestsPut"`
RequestsPatch int64 `json:"requestsPatch"`
RequestsDelete int64 `json:"requestsDelete"`
RequestsOptions int64 `json:"requestsOptions"`
RequestsOther int64 `json:"requestsOther"`
RequestsSuperuser int64 `json:"requestsSuperuser,omitempty"`
RequestsUser int64 `json:"requestsUser,omitempty"`
}

// TransactionStats contains statistics about transactions.
Expand All @@ -128,6 +131,7 @@ type TransactionStats struct {
Aborted int64 `json:"aborted"`
Committed int64 `json:"committed"`
IntermediateCommits int64 `json:"intermediateCommits"`
ReadOnly int64 `json:"readOnly,omitempty"`
}

// MemoryStats contains statistics about memory usage.
Expand All @@ -137,6 +141,7 @@ type MemoryStats struct {
CountOfTimes int64 `json:"countOfTimes"`
HeapMax int64 `json:"heapMax"`
HeapMin int64 `json:"heapMin"`
Invocations int64 `json:"invocations,omitempty"`
}

// V8ContextStats contains statistics about V8 contexts.
Expand All @@ -145,6 +150,7 @@ type V8ContextStats struct {
Busy int64 `json:"busy"`
Dirty int64 `json:"dirty"`
Free int64 `json:"free"`
Min int64 `json:"min,omitempty"`
Max int64 `json:"max"`
Memory []MemoryStats `json:"memory"`
}
Expand Down
1 change: 1 addition & 0 deletions client_server_admin_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

type serverModeResponse struct {
Mode ServerMode `json:"mode"`
ArangoError
}

type serverModeRequest struct {
Expand Down
1 change: 1 addition & 0 deletions client_server_info_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type roleResponse struct {
// Role of the server within a cluster
Role string `json:"role,omitempty"`
Mode string `json:"mode,omitempty"`
ArangoError
}

// asServerRole converts the response into a ServerRole
Expand Down
1 change: 1 addition & 0 deletions client_users_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func (c *client) UserExists(ctx context.Context, name string) (bool, error) {

type listUsersResponse struct {
Result []userData `json:"result,omitempty"`
ArangoError
}

// Users returns a list of all users found by the client.
Expand Down
43 changes: 43 additions & 0 deletions cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ package driver

import (
"context"
"encoding/json"
"fmt"
"reflect"
"time"
)

Expand Down Expand Up @@ -123,6 +126,46 @@ type DatabaseInventory struct {
Collections []InventoryCollection `json:"collections,omitempty"`
// Details of all views
Views []InventoryView `json:"views,omitempty"`
State State `json:"state,omitempty"`
Tick string `json:"tick,omitempty"`
}

type State struct {
Running bool `json:"running,omitempty"`
LastLogTick string `json:"lastLogTick,omitempty"`
LastUncommittedLogTick string `json:"lastUncommittedLogTick,omitempty"`
TotalEvents int64 `json:"totalEvents,omitempty"`
Time time.Time `json:"time,omitempty"`
}

// UnmarshalJSON marshals State to arangodb json representation
func (s *State) UnmarshalJSON(d []byte) error {
var internal interface{}

if err := json.Unmarshal(d, &internal); err != nil {
return err
}

if val, ok := internal.(string); ok {
if val != "unused" {
fmt.Printf("unrecognized State value: %s\n", val)
}
*s = State{}
return nil
} else {
type Alias State
out := Alias{}

if err := json.Unmarshal(d, &out); err != nil {
return &json.UnmarshalTypeError{
Value: string(d),
Type: reflect.TypeOf(s).Elem(),
}
}
*s = State(out)
}

return nil
}

// IsReady returns true if the IsReady flag of all collections is set.
Expand Down
5 changes: 5 additions & 0 deletions collection_documents.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,9 @@ type ImportDocumentStatistics struct {
Updated int64 `json:"updated,omitempty"`
// Ignored holds the number of failed but ignored insert operations (in case onDuplicate was set to ignore).
Ignored int64 `json:"ignored,omitempty"`
// if query parameter details is set to true, the result will contain a details attribute which is an array
// with more detailed information about which documents could not be inserted.
Details []string

ArangoError
}
3 changes: 2 additions & 1 deletion database.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,6 @@ func (t EngineType) String() string {

// EngineInfo contains information about the database engine being used.
type EngineInfo struct {
Type EngineType `json:"name"`
Type EngineType `json:"name"`
Supports map[string]interface{} `json:"supports,omitempty"`
}
1 change: 1 addition & 0 deletions database_arangosearch_analyzers_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ func (d *database) Analyzer(ctx context.Context, name string) (ArangoSearchAnaly

type analyzerListResponse struct {
Analyzer []ArangoSearchAnalyzerDefinition `json:"result,omitempty"`
ArangoError
}

// List returns a list of all analyzers
Expand Down
1 change: 1 addition & 0 deletions database_graphs_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func (d *database) GraphExists(ctx context.Context, name string) (bool, error) {

type getGraphsResponse struct {
Graphs []graphDefinition `json:"graphs,omitempty"`
ArangoError
}

// Graphs returns a list of all graphs in the database.
Expand Down
5 changes: 4 additions & 1 deletion database_views_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@ import (
)

type viewInfo struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Type ViewType `json:"type,omitempty"`
ArangoID
ArangoError
}

type getViewResponse struct {
Result []viewInfo `json:"result,omitempty"`

ArangoError
}

// View opens a connection to an existing view within the database.
Expand Down
1 change: 1 addition & 0 deletions graph_vertex_collections_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (

type listVertexCollectionResponse struct {
Collections []string `json:"collections,omitempty"`
ArangoError
}

// VertexCollection opens a connection to an existing edge-collection within the graph.
Expand Down
6 changes: 6 additions & 0 deletions id.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ import (
"strings"
)

// ArangoID is a generic Arango ID struct representation
type ArangoID struct {
ID string `json:"id,omitempty"`
GloballyUniqueId string `json:"globallyUniqueId,omitempty"`
}

// DocumentID references a document in a collection.
// Format: collection/_key
type DocumentID string
Expand Down
8 changes: 5 additions & 3 deletions meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ package driver

// DocumentMeta contains all meta data used to identifier a document.
type DocumentMeta struct {
Key string `json:"_key,omitempty"`
ID DocumentID `json:"_id,omitempty"`
Rev string `json:"_rev,omitempty"`
Name string `json:"name,omitempty"`
Key string `json:"_key,omitempty"`
ID DocumentID `json:"_id,omitempty"`
Rev string `json:"_rev,omitempty"`
OldRev string `json:"_oldRev,omitempty"`
}

// validateKey returns an error if the given key is empty otherwise invalid.
Expand Down
4 changes: 4 additions & 0 deletions test/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,10 @@ func createClient(t testEnv, waitUntilReady bool, disallowUnknownFields bool) dr
t.Fatalf("Failed to create new client: %s", describe(err))
}

if os.Getenv("TEST_NOT_WAIT_UNTIL_READY") != "" {
waitUntilReady = false
}

if waitUntilReady {
timeout := time.Minute
ctx, cancel := context.WithTimeout(context.Background(), timeout)
Expand Down
1 change: 1 addition & 0 deletions transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,6 @@ type transactionCollectionsRequest struct {
}

type transactionResponse struct {
ArangoError
Result interface{} `json:"result"`
}
1 change: 1 addition & 0 deletions user_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type userData struct {
Active bool `json:"active,omitempty"`
Extra *RawObject `json:"extra,omitempty"`
ChangePassword bool `json:"changePassword,omitempty"`
ArangoError
}

// relPath creates the relative path to this index (`_api/user/<name>`)
Expand Down
43 changes: 39 additions & 4 deletions view_arangosearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,17 @@ type ArangoSearchAnalyzerDefinition struct {
Type ArangoSearchAnalyzerType `json:"type,omitempty"`
Properties ArangoSearchAnalyzerProperties `json:"properties,omitempty"`
Features []ArangoSearchAnalyzerFeature `json:"features,omitempty"`
ArangoError
}

// ArangoSearchViewProperties contains properties an an ArangoSearch view.
type ArangoSearchViewBase struct {
Type ViewType `json:"type,omitempty"`
Name string `json:"name,omitempty"`
ArangoID
ArangoError
}

// ArangoSearchViewProperties contains properties on an ArangoSearch view.
type ArangoSearchViewProperties struct {
// CleanupIntervalStep specifies the minimum number of commits to wait between
// removing unused files in the data directory.
Expand Down Expand Up @@ -294,12 +302,38 @@ type ArangoSearchViewProperties struct {
WriteBufferSizeMax *int64 `json:"writebufferSizeMax,omitempty"`

// Links contains the properties for how individual collections
// are indexed in thie view.
// are indexed in the view.
// The key of the map are collection names.
Links ArangoSearchLinks `json:"links,omitempty"`

// PrimarySort describes how individual fields are sorted
PrimarySort []ArangoSearchPrimarySortEntry `json:"primarySort,omitempty"`

// PrimarySortCompression Defines how to compress the primary sort data (introduced in v3.7.1).
// ArangoDB v3.5 and v3.6 always compress the index using LZ4. This option is immutable.
PrimarySortCompression PrimarySortCompression `json:"primarySortCompression,omitempty"`

// StoredValues An array of objects to describe which document attributes to store in the View index (introduced in v3.7.1).
// It can then cover search queries, which means the data can be taken from the index directly and accessing the storage engine can be avoided.
// This option is immutable.
StoredValues []StoredValue `json:"storedValues,omitempty"`

ArangoSearchViewBase
}

// PrimarySortCompression Defines how to compress the primary sort data (introduced in v3.7.1)
type PrimarySortCompression string

const (
// PrimarySortCompressionLz4 (default): use LZ4 fast compression.
PrimarySortCompressionLz4 PrimarySortCompression = "lz4"
// PrimarySortCompressionNone disable compression to trade space for speed.
PrimarySortCompressionNone PrimarySortCompression = "none"
)

type StoredValue struct {
Fields []string `json:"fields,omitempty"`
Compression PrimarySortCompression `json:"compression,omitempty"`
}

// ArangoSearchSortDirection describes the sorting direction
Expand Down Expand Up @@ -368,10 +402,11 @@ type ArangoSearchConsolidationPolicyBytesAccum struct {

// ArangoSearchConsolidationPolicyTier contains fields used for ArangoSearchConsolidationPolicyTypeTier
type ArangoSearchConsolidationPolicyTier struct {
MinScore *int64 `json:"minScore,omitempty"`
// MinSegments specifies the minimum number of segments that will be evaluated as candidates for consolidation.
MinSegments *int64 `json:"minSegments,omitempty"`
MinSegments *int64 `json:"segmentsMin,omitempty"`
// MaxSegments specifies the maximum number of segments that will be evaluated as candidates for consolidation.
MaxSegments *int64 `json:"maxSegments,omitempty"`
MaxSegments *int64 `json:"segmentsMax,omitempty"`
// SegmentsBytesMax specifies the maxinum allowed size of all consolidated segments in bytes.
SegmentsBytesMax *int64 `json:"segmentsBytesMax,omitempty"`
// SegmentsBytesFloor defines the value (in bytes) to treat all smaller segments as equal for consolidation selection.
Expand Down

0 comments on commit 344c139

Please sign in to comment.