Skip to content

Commit

Permalink
added new screenshots, did bisect, better formatting, diff works agai…
Browse files Browse the repository at this point in the history
…n as it is able to compare slices.
  • Loading branch information
djarotech committed Aug 16, 2018
1 parent 4e58bb4 commit 87b952c
Show file tree
Hide file tree
Showing 13 changed files with 103 additions and 59 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,10 @@ kubectl.sh get --raw "/apis/kubeprovenance.cloudark.io/v1/namespaces/default/pos
kubectl.sh get --raw "/apis/kubeprovenance.cloudark.io/v1/namespaces/default/postgreses/client25/bisect?field1=username&value1=pallavi&field2=password&value2=pass123"
```
![alt text](https://github.com/cloud-ark/kubeprovenance/raw/master/docs/spechistory.png)
![alt text](https://github.com/cloud-ark/kubeprovenance/raw/master/docs/getdiff_databases.png)
![alt text](https://github.com/cloud-ark/kubeprovenance/raw/master/docs/getdiff_users.png)
![alt text](https://github.com/cloud-ark/kubeprovenance/raw/master/docs/nodiff.png)
![alt text](https://github.com/cloud-ark/kubeprovenance/raw/master/docs/getfulldiff.png)
![alt text](https://github.com/cloud-ark/kubeprovenance/raw/master/docs/getfielddiff.png)
![alt text](https://github.com/cloud-ark/kubeprovenance/raw/master/docs/versions.png)
![alt text](https://github.com/cloud-ark/kubeprovenance/raw/master/docs/bisect.png)

## Try it on Minikube

Expand Down
Binary file added docs/bisect.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/deployments.png
Binary file not shown.
Binary file removed docs/etcd-clusters.png
Binary file not shown.
Binary file removed docs/getdiff_databases.png
Binary file not shown.
Binary file removed docs/getdiff_users.png
Binary file not shown.
Binary file added docs/getfielddiff.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/getfulldiff.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/hello-minikube-deployment.png
Binary file not shown.
Binary file removed docs/nodiff.png
Binary file not shown.
Binary file modified docs/spechistory.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 2 additions & 5 deletions pkg/apiserver/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,15 +222,14 @@ func getHistory(request *restful.Request, response *restful.Response) {
fmt.Printf("Spec history starting with version %d and ending with version %d", startInt, endInt)
response.Write([]byte(intendedProvObj.ObjectFullHistory.SpecHistoryInterval(startInt, endInt)))
} else { //start and end
fmt.Printf("here")
response.Write([]byte(intendedProvObj.ObjectFullHistory.SpecHistory()))
}
}

}

func bisect(request *restful.Request, response *restful.Response) {
fmt.Println("Inside bisectaa")
fmt.Println("Inside bisect")
resourceName := request.PathParameter("resource-id")
requestPath := request.Request.URL.Path
resourcePathSlice := strings.Split(requestPath, "/")
Expand All @@ -249,8 +248,6 @@ func bisect(request *restful.Request, response *restful.Response) {

fmt.Printf("ProvenanceInfo:%v", provenanceInfo)

response.Write([]byte(provenanceInfo))

intendedProvObj := provenance.FindProvenanceObjectByName(resourceName, provenance.AllProvenanceObjects)
if intendedProvObj == nil {
s := fmt.Sprintf("Could not find any provenance history for resource name: %s", resourceName)
Expand Down Expand Up @@ -305,7 +302,7 @@ func getDiff(request *restful.Request, response *restful.Response) {
fmt.Printf("Diff for Field requested. Field:%s", field)
diffInfo = intendedProvObj.ObjectFullHistory.FieldDiff(field, startInt, endInt)
} else {
fmt.Println("Diff for Spec requested.")
fmt.Println("Diff for Full Spec requested.")
diffInfo = intendedProvObj.ObjectFullHistory.FullDiff(startInt, endInt)
}
}
Expand Down
149 changes: 98 additions & 51 deletions pkg/provenance/provenance.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,37 @@ func (o ObjectLineage) SpecHistory() string {
}
sort.Ints(s)
//get all versions, sort by version, make string array of them
specs := make([]string, 0)
specs := make([]Spec, 0)
for _, version := range s {
specs = append(specs, o[version]) //cast Spec to String
}

specStrings := make([]string, 0)
for _, spec := range specs {
specStrings = append(specStrings, spec.String())
}
return strings.Join(specStrings, "\n")
}

func (o ObjectLineage) SpecHistoryInterval(vNumStart, vNumEnd int) string {
//order keys so we append in order later, reference: https://blog.golang.org/go-maps-in-action#TOC_7.
s := make([]int, 0)
for _, value := range o {
s = append(s, value.Version)
}
sort.Ints(s)
//get all versions, sort by version, make string array of them
specs := make([]Spec, 0)
for _, version := range s {
specs = append(specs, fmt.Sprint(o[version])) //cast Spec to String
specs = append(specs, o[version]) //cast Spec to String
}
specStrings := make([]string, 0)
for _, spec := range specs {
specStrings = append(specStrings, spec.String())
}
return strings.Join(specs, "\n")
return strings.Join(specStrings, "\n")
}

func (o ObjectLineage) Bisect(field1, value1, field2, value2 string) string {
s := make([]int, 0)
for _, value := range o {
Expand Down Expand Up @@ -226,12 +251,12 @@ func (o ObjectLineage) Bisect(field1, value1, field2, value2 string) string {
fmt.Printf("Field %s not found.\n", field2)
return noSpecFound
}
users, ok1 := p.([]string)
users, ok1 := u.([]string)
if !ok1 {
fmt.Printf("Type assertion failed. Underlying data is incorrect and is not a slice of strings: %s\n", u)
return noSpecFound
}
passwords, ok2 := u.([]string)
passwords, ok2 := p.([]string)
if !ok2 {
fmt.Printf("Type assertion failed. Underlying data is incorrect and is not a slice of strings: %s\n", p)
return noSpecFound
Expand All @@ -248,54 +273,55 @@ func (o ObjectLineage) Bisect(field1, value1, field2, value2 string) string {
return noSpecFound
}

//TODO: add optional parameters to spechistory route in apiserver.go, and call this method.
// Right now it is actually unused
func (o ObjectLineage) SpecHistoryInterval(vNumStart, vNumEnd int) string {
//order keys so we append in order later, reference: https://blog.golang.org/go-maps-in-action#TOC_7.
s := make([]int, 0)
for _, value := range o {
s = append(s, value.Version)
}
sort.Ints(s)
//get all versions, sort by version, make string array of them
specs := make([]Spec, 0)
for _, version := range s {
specs = append(specs, o[version]) //cast Spec to String
}
specStrings := make([]string, 0)
for _, spec := range specs {
if spec.Version >= vNumStart && spec.Version <= vNumEnd {
specStrings = append(specStrings, spec.String())
}
}
return strings.Join(specStrings, "\n")
}

func (o ObjectLineage) FullDiff(vNumStart, vNumEnd int) string {
var b strings.Builder
sp1 := o[vNumStart]
sp2 := o[vNumEnd]
for attribute, data1 := range sp1.AttributeToData {
if data2, ok := sp2.AttributeToData[attribute]; ok {
if data1 != data2 {
fmt.Fprintf(&b, "FOUND DIFF")
fmt.Fprintf(&b, "Spec version %d:\n %s\n", vNumStart, data1)
fmt.Fprintf(&b, "Spec version %d:\n %s\n", vNumEnd, data2)
var stringSlice1, stringSlice2 string

sliceStringData1, okTypeAssertion1 := data1.([]string)
if okTypeAssertion1 {
stringSlice1 = strings.Join(sliceStringData1, " ")
}

data2, ok := sp2.AttributeToData[attribute] //check if the attribute even exists
if ok {

sliceStringData2, okTypeAssertion2 := data2.([]string) //type assertion to compare slices
if okTypeAssertion2 {
stringSlice2 = strings.Join(sliceStringData2, " ")
}

if okTypeAssertion1 && okTypeAssertion2 {
if stringSlice1 != stringSlice2 {
fmt.Fprintf(&b, "Found diff on attribute %s:\n", attribute)
fmt.Fprintf(&b, "\tVersion %d: %s\n", vNumStart, stringSlice1)
fmt.Fprintf(&b, "\tVersion %d: %s\n", vNumEnd, stringSlice2)
} else {
// fmt.Fprintf(&b, "No difference for attribute %s \n", attribute)
}
} else {
fmt.Fprintf(&b, "No difference for attribute %s \n", attribute)
if data1 != data2 {
fmt.Fprintf(&b, "Found diff on attribute %s:\n", attribute)
fmt.Fprintf(&b, "\tVersion %d: %s\n", vNumStart, data1)
fmt.Fprintf(&b, "\tVersion %d: %s\n", vNumEnd, data2)
} else {
// fmt.Fprintf(&b, "No difference for attribute %s \n", attribute)
}
}
} else { //for the case where a key exists in spec 1 that doesn't exist in spec 2
fmt.Fprintf(&b, "FOUND DIFF")
fmt.Fprintf(&b, "Spec version %d:\n %s\n", vNumStart, data1)
fmt.Fprintf(&b, "Spec version %d:\n %s\n", vNumEnd, "No attribute found.")
fmt.Fprintf(&b, "Found diff on attribute %s:\n", attribute)
fmt.Fprintf(&b, "\tVersion %d: %s\n", vNumStart, data1)
fmt.Fprintf(&b, "\tVersion %d: %s\n", vNumEnd, "No attribute found.")
}
}
//for the case where a key exists in spec 2 that doesn't exist in spec 1
for attribute, data1 := range sp2.AttributeToData {
if _, ok := sp2.AttributeToData[attribute]; !ok {
fmt.Fprintf(&b, "FOUND DIFF")
fmt.Fprintf(&b, "Spec version %d:\n %s\n", vNumStart, "No attribute found.")
fmt.Fprintf(&b, "Spec version %d:\n %s\n", vNumEnd, data1)
fmt.Fprintf(&b, "Found diff on attribute %s:\n", attribute)
fmt.Fprintf(&b, "\tVersion %d: %s\n", vNumStart, "No attribute found.")
fmt.Fprintf(&b, "\tVersion %d: %s\n", vNumEnd, data1)
}
}
return b.String()
Expand All @@ -305,23 +331,44 @@ func (o ObjectLineage) FieldDiff(fieldName string, vNumStart, vNumEnd int) strin
var b strings.Builder
data1, ok1 := o[vNumStart].AttributeToData[fieldName]
data2, ok2 := o[vNumEnd].AttributeToData[fieldName]
var stringSlice1, stringSlice2 string

sliceStringData1, okTypeAssertion1 := data1.([]string)
if okTypeAssertion1 {
stringSlice1 = strings.Join(sliceStringData1, " ")
}
sliceStringData2, okTypeAssertion2 := data2.([]string) //type assertion to compare slices
if okTypeAssertion2 {
stringSlice2 = strings.Join(sliceStringData2, " ")
}

switch {
case ok1 && ok2:
if data1 != data2 {
fmt.Fprintf(&b, "FOUND DIFF\n")
fmt.Fprintf(&b, "Spec version %d:\n %s\n", vNumStart, data1)
fmt.Fprintf(&b, "Spec version %d:\n %s\n", vNumEnd, data2)
if okTypeAssertion1 && okTypeAssertion2 {
if stringSlice1 != stringSlice2 {
fmt.Fprintf(&b, "Found diff on attribute %s:\n", fieldName)
fmt.Fprintf(&b, "\tVersion %d: %s\n", vNumStart, stringSlice1)
fmt.Fprintf(&b, "\tVersion %d: %s\n", vNumEnd, stringSlice2)
} else {
// fmt.Fprintf(&b, "No difference for attribute %s \n", attribute)
}
} else {
fmt.Fprintf(&b, "No difference for attribute %s \n", fieldName)
if data1 != data2 {
fmt.Fprintf(&b, "Found diff on attribute %s:\n", fieldName)
fmt.Fprintf(&b, "\tSpec version %d: %s\n", vNumStart, data1)
fmt.Fprintf(&b, "\tSpec version %d: %s\n", vNumEnd, data2)
} else {
// fmt.Fprintf(&b, "No difference for attribute %s \n", fieldName)
}
}
case !ok1 && ok2:
fmt.Fprintf(&b, "FOUND DIFF")
fmt.Fprintf(&b, "Spec version %d:\n %s\n", vNumStart, "No attribute found.")
fmt.Fprintf(&b, "Spec version %d:\n %s\n", vNumEnd, data2)
fmt.Fprintf(&b, "Found diff on attribute %s:\n", fieldName)
fmt.Fprintf(&b, "\tVersion %d: %s\n", vNumStart, "No attribute found.")
fmt.Fprintf(&b, "\tVersion %d: %s\n", vNumEnd, data2)
case ok1 && !ok2:
fmt.Fprintf(&b, "FOUND DIFF")
fmt.Fprintf(&b, "Spec version %d:\n %s\n", vNumStart, data1)
fmt.Fprintf(&b, "Spec version %d:\n %s\n", vNumEnd, "No attribute found.")
fmt.Fprintf(&b, "Found diff on attribute %s:\n", fieldName)
fmt.Fprintf(&b, "\tVersion %d: %s\n", vNumStart, data1)
fmt.Fprintf(&b, "\tVersion %d: %s\n", vNumEnd, "No attribute found.")
case !ok1 && !ok2:
fmt.Fprintf(&b, "Attribute not found in either version %d or %d", vNumStart, vNumEnd)
}
Expand Down

0 comments on commit 87b952c

Please sign in to comment.