1
0
Fork 0
mirror of https://github.com/arangodb/kube-arangodb.git synced 2024-12-14 11:57:37 +00:00

[Feature] Agency ArangoSync State check (#1165)

This commit is contained in:
Adam Janikowski 2022-11-02 10:32:09 -04:00 committed by GitHub
parent 8af2e617ac
commit 1ced857405
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 157 additions and 6 deletions

View file

@ -7,6 +7,7 @@
- (Refactoring) Extract kerrors package
- (Refactoring) Extract Inspector Definitions package
- (Bugfix) Fix PDBs Version discovery
- (Feature) Agency ArangoSync State check
## [1.2.20](https://github.com/arangodb/kube-arangodb/tree/1.2.20) (2022-10-25)
- (Feature) Add action progress

View file

@ -0,0 +1,81 @@
//
// DISCLAIMER
//
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//
package agency
import "encoding/json"
var (
_ json.Unmarshaler = &ArangoSyncLazy{}
)
// ArangoSyncLazy allows failure during load of the Sync state
type ArangoSyncLazy struct {
Error error
*ArangoSync
}
func (a *ArangoSyncLazy) UnmarshalJSON(bytes []byte) error {
var s ArangoSync
if err := json.Unmarshal(bytes, &s); err != nil {
a.ArangoSync = nil
a.Error = err
} else {
a.ArangoSync = &s
a.Error = nil
}
return nil
}
type ArangoSync struct {
State ArangoSyncState `json:"synchronizationState"`
}
func (a *ArangoSync) IsSyncInProgress() bool {
if a == nil {
return false
}
// Check Incoming
if s := a.State.Incoming.State; s != nil && *s != "inactive" && *s != "" {
return true
}
if a.State.Outgoing.Targets.Exists() {
return true
}
return false
}
type ArangoSyncState struct {
Incoming ArangoSyncIncomingState `json:"incoming"`
Outgoing ArangoSyncOutgoingState `json:"outgoing"`
}
type ArangoSyncIncomingState struct {
State *string `json:"state,omitempty"`
}
type ArangoSyncOutgoingState struct {
Targets StateExists `json:"targets,omitempty"`
}

View file

@ -0,0 +1,47 @@
//
// DISCLAIMER
//
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//
package agency
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/require"
)
func Test_Sync_Target(t *testing.T) {
var s DumpState
require.NoError(t, json.Unmarshal(syncSource, &s))
require.NotNil(t, s.Agency.ArangoDB.ArangoSync.ArangoSync)
require.True(t, s.Agency.ArangoDB.ArangoSync.ArangoSync.State.Outgoing.Targets.Exists())
require.True(t, s.Agency.ArangoDB.ArangoSync.IsSyncInProgress())
}
func Test_Sync_Source(t *testing.T) {
var s DumpState
require.NoError(t, json.Unmarshal(syncTarget, &s))
require.NotNil(t, s.Agency.ArangoDB.ArangoSync.ArangoSync)
require.NotNil(t, s.Agency.ArangoDB.ArangoSync.ArangoSync.State.Incoming.State)
require.Equal(t, "running", *s.Agency.ArangoDB.ArangoSync.ArangoSync.State.Incoming.State)
require.True(t, s.Agency.ArangoDB.ArangoSync.IsSyncInProgress())
}

View file

@ -32,4 +32,6 @@ func Test_Databases(t *testing.T) {
require.NoError(t, json.Unmarshal(agencyDump39HotBackup, &s))
require.Contains(t, s.Agency.Arango.Plan.Databases, "_system")
require.False(t, s.Agency.ArangoDB.ArangoSync.IsSyncInProgress())
}

View file

@ -88,12 +88,17 @@ type StateRoots []StateRoot
type StateRoot struct {
Arango State `json:"arango"`
ArangoDB StateDB `json:"arangodb,omitempty"`
}
type DumpState struct {
Agency StateRoot `json:"agency"`
}
type StateDB struct {
ArangoSync ArangoSyncLazy `json:"arangosync,omitempty"`
}
type State struct {
Supervision StateSupervision `json:"Supervision"`
Plan StatePlan `json:"Plan"`

View file

@ -20,7 +20,11 @@
package agency
import "github.com/arangodb/kube-arangodb/pkg/util"
import (
"crypto/sha256"
"github.com/arangodb/kube-arangodb/pkg/util"
)
type StateExists []byte
@ -42,10 +46,9 @@ func (d *StateExists) UnmarshalJSON(bytes []byte) error {
return nil
}
z := make([]byte, len(bytes))
data := sha256.Sum256(bytes)
allData := data[:]
copy(z, bytes)
*d = z
*d = allData
return nil
}

View file

@ -52,6 +52,12 @@ var agencyDump39Jobs []byte
//go:embed testdata/longdata.json
var longData []byte
//go:embed testdata/sync.source.json
var syncSource []byte
//go:embed testdata/sync.target.json
var syncTarget []byte
var (
data = map[string][]byte{
"3.6": agencyDump36,

View file

@ -35,11 +35,15 @@ func Test_Target_HotBackup(t *testing.T) {
require.True(t, s.Agency.Arango.Target.HotBackup.Create.Exists())
t.Log(s.Agency.Arango.Target.HotBackup.Create.time.String())
require.False(t, s.Agency.ArangoDB.ArangoSync.IsSyncInProgress())
})
t.Run("Does Not Exists", func(t *testing.T) {
var s DumpState
require.NoError(t, json.Unmarshal(agencyDump39Satellite, &s))
require.False(t, s.Agency.Arango.Target.HotBackup.Create.Exists())
require.False(t, s.Agency.ArangoDB.ArangoSync.IsSyncInProgress())
})
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long