This repository has been archived by the owner on Apr 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #877 from mpuncel/mpuncel/rc-audit-logs
Mpuncel/rc audit logs
- Loading branch information
Showing
26 changed files
with
633 additions
and
85 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,44 @@ | ||
package audit | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
pc_fields "github.com/square/p2/pkg/pc/fields" | ||
"github.com/square/p2/pkg/types" | ||
"github.com/square/p2/pkg/util" | ||
) | ||
|
||
const ( | ||
// RcRetargetingEvent represents events in which an RC changes the set of | ||
// nodes that it is targeting. This can be used to log the set of nodes that | ||
// an RC or pod cluster manages over time | ||
RCRetargetingEvent EventType = "REPLICATION_CONTROLLER_RETARGET" | ||
) | ||
|
||
type RCRetargetingDetails struct { | ||
PodID types.PodID `json:"pod_id"` | ||
AvailabilityZone pc_fields.AvailabilityZone `json:"availability_zone"` | ||
ClusterName pc_fields.ClusterName `json:"cluster_name"` | ||
Nodes []types.NodeName `json:"nodes"` | ||
} | ||
|
||
func NewRCRetargetingEventDetails( | ||
podID types.PodID, | ||
az pc_fields.AvailabilityZone, | ||
name pc_fields.ClusterName, | ||
nodes []types.NodeName, | ||
) (json.RawMessage, error) { | ||
details := RCRetargetingDetails{ | ||
PodID: podID, | ||
AvailabilityZone: az, | ||
ClusterName: name, | ||
Nodes: nodes, | ||
} | ||
|
||
bytes, err := json.Marshal(details) | ||
if err != nil { | ||
return nil, util.Errorf("could not marshal rc retargeting details as json: %s", err) | ||
} | ||
|
||
return json.RawMessage(bytes), nil | ||
} |
This file contains 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,44 @@ | ||
package audit | ||
|
||
import ( | ||
"encoding/json" | ||
"reflect" | ||
"testing" | ||
|
||
pc_fields "github.com/square/p2/pkg/pc/fields" | ||
"github.com/square/p2/pkg/types" | ||
) | ||
|
||
func TestRCRetargetingEventDetails(t *testing.T) { | ||
podID := types.PodID("some_pod_id") | ||
clusterName := pc_fields.ClusterName("some_cluster_name") | ||
az := pc_fields.AvailabilityZone("some_availability_zone") | ||
nodes := []types.NodeName{"node1", "node2"} | ||
|
||
detailsJSON, err := NewRCRetargetingEventDetails(podID, az, clusterName, nodes) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
var details RCRetargetingDetails | ||
err = json.Unmarshal(detailsJSON, &details) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if details.PodID != podID { | ||
t.Errorf("expected pod id to be %s but was %s", podID, details.PodID) | ||
} | ||
|
||
if details.AvailabilityZone != az { | ||
t.Errorf("expected availability zone to be %s but was %s", az, details.AvailabilityZone) | ||
} | ||
|
||
if details.ClusterName != clusterName { | ||
t.Errorf("expected cluster name to be %s but was %s", clusterName, details.ClusterName) | ||
} | ||
|
||
if !reflect.DeepEqual(details.Nodes, nodes) { | ||
t.Errorf("expected node list to be %s but was %s", nodes, details.Nodes) | ||
} | ||
} |
This file contains 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 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 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 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 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
Oops, something went wrong.