Skip to content
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

Feat/#661 - Exposing creationTime and modificationTime #677

Merged
merged 32 commits into from
Apr 27, 2020

Conversation

tharun208
Copy link
Contributor

Summary

Exposed creationTime and modifiedTime from rest-api

Full changelog

  • Changed resource to expose creationTime and modificationTime
  • Updated tests

Issues resolved

Fix #661

* added creationTime and modificationTime in resource
Feature kumahq#661
* fixed remote store create and update function and updated tests
Feature kumahq#661
@tharun208 tharun208 marked this pull request as ready for review April 14, 2020 18:41
@tharun208 tharun208 requested a review from a team April 14, 2020 18:41
@tharun208 tharun208 marked this pull request as draft April 14, 2020 18:43
@tharun208 tharun208 marked this pull request as ready for review April 15, 2020 07:18
@tharun208 tharun208 changed the title Feat/#661 Feat/#661 - Exposing creationTime and modificationTime Apr 15, 2020
@tharun208 tharun208 marked this pull request as draft April 15, 2020 13:59
@tharun208 tharun208 marked this pull request as ready for review April 15, 2020 15:18
Type: string(res.GetType()),
Name: opts.Name,
Mesh: opts.Mesh,
CreationTime: opts.CreationTime,
Copy link
Contributor

Choose a reason for hiding this comment

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

This should not be set by the client. CreationTime is set on the server side.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

then during creation or modification, I need to remove the createdAt and modifiedAt in kumactl apply right ?

Copy link
Contributor

Choose a reason for hiding this comment

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

correct

Copy link
Contributor Author

@tharun208 tharun208 Apr 21, 2020

Choose a reason for hiding this comment

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

removed

Type: string(res.GetType()),
Name: res.GetMeta().GetName(),
Mesh: res.GetMeta().GetMesh(),
ModificationTime: opts.ModificationTime,
Copy link
Contributor

Choose a reason for hiding this comment

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

This should not be set by the client. ModificationTime is set on the server side.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

@@ -222,9 +224,9 @@ func (m meta) GetMesh() string {
}

func (m meta) GetCreationTime() time.Time {
return time.Unix(0, 0) // the date doesn't matter since it is set on server side anyways
return m.CreationTime
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment is still relevant. This should be set on the server-side.

@jakubdyszkiewicz
Copy link
Contributor

Hey, I tested this functionality and I found some issues that creation and modification time is always zero. After debugging it a bit I found the solution.

Index: pkg/plugins/resources/remote/unmarshalling.go
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- pkg/plugins/resources/remote/unmarshalling.go	(revision 93171c8dfd9c82eb6b2f1d26e9f36afcef3f4501)
+++ pkg/plugins/resources/remote/unmarshalling.go	(date 1587544615198)
@@ -43,10 +43,11 @@
 		return err
 	}
 	res.SetMeta(remoteMeta{
-		Name:    restResource.Meta.Name,
-		Mesh:    restResource.Meta.Mesh,
-		Version: "",
-		// todo(jakubdyszkiewicz) creation and modification time is not set because it's not exposed in API yet
+		Name:             restResource.Meta.Name,
+		Mesh:             restResource.Meta.Mesh,
+		Version:          "",
+		CreationTime:     restResource.Meta.CreationTime,
+		ModificationTime: restResource.Meta.ModificationTime,
 	})
 	return nil
 }
@@ -64,10 +65,11 @@
 			return err
 		}
 		r.SetMeta(&remoteMeta{
-			Name:    ri.Meta.Name,
-			Mesh:    ri.Meta.Mesh,
-			Version: "",
-			// todo(jakubdyszkiewicz) creation and modification time is not set because it's not exposed in API yet
+			Name:             ri.Meta.Name,
+			Mesh:             ri.Meta.Mesh,
+			Version:          "",
+			CreationTime:     ri.Meta.CreationTime,
+			ModificationTime: ri.Meta.ModificationTime,
 		})
 		_ = rs.AddItem(r)
 	}
Index: pkg/core/resources/manager/manager.go
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- pkg/core/resources/manager/manager.go	(revision 93171c8dfd9c82eb6b2f1d26e9f36afcef3f4501)
+++ pkg/core/resources/manager/manager.go	(date 1587544457296)
@@ -47,13 +47,13 @@
 	if err := resource.Validate(); err != nil {
 		return err
 	}
-	opts := store.NewCreateOptions(append(fs, store.CreatedAt(time.Now()))...)
+	opts := store.NewCreateOptions(fs...)
 	if resource.GetType() != mesh.MeshType {
 		if err := r.ensureMeshExists(ctx, opts.Mesh); err != nil {
 			return err
 		}
 	}
-	return r.Store.Create(ctx, resource, fs...)
+	return r.Store.Create(ctx, resource, append(fs, store.CreatedAt(time.Now()))...)
 }
 
 func (r *resourcesManager) ensureMeshExists(ctx context.Context, meshName string) error {

here is a patch for it.
Also please add tests to pkg/plugins/resources/remote/store_test.go to ensure that unmarshalling the times actually works. Thank you.

Copy link
Contributor

@jakubdyszkiewicz jakubdyszkiewicz left a comment

Choose a reason for hiding this comment

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

Also include CHANGELOG. Thanks.

Name string
Mesh string
CreationTime time.Time
ModificationTime time.Time
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it needed though? I think we can revert this file to master

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but not sure if I revert it to master, GetCreationTime() is time.Unix and it will be different for each machine and the test will fail in ci.

Copy link
Contributor

Choose a reason for hiding this comment

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

time.Unix(0, 0) indicates the constant time

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed

BeforeEach(func() {

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you revert such files (I see a couple of them) with an empty line change to master?
It's easier to review and less potential conflicts

@tharun208
Copy link
Contributor Author

Hey, I tested this functionality and I found some issues that creation and modification time is always zero. After debugging it a bit I found the solution.

Index: pkg/plugins/resources/remote/unmarshalling.go
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- pkg/plugins/resources/remote/unmarshalling.go	(revision 93171c8dfd9c82eb6b2f1d26e9f36afcef3f4501)
+++ pkg/plugins/resources/remote/unmarshalling.go	(date 1587544615198)
@@ -43,10 +43,11 @@
 		return err
 	}
 	res.SetMeta(remoteMeta{
-		Name:    restResource.Meta.Name,
-		Mesh:    restResource.Meta.Mesh,
-		Version: "",
-		// todo(jakubdyszkiewicz) creation and modification time is not set because it's not exposed in API yet
+		Name:             restResource.Meta.Name,
+		Mesh:             restResource.Meta.Mesh,
+		Version:          "",
+		CreationTime:     restResource.Meta.CreationTime,
+		ModificationTime: restResource.Meta.ModificationTime,
 	})
 	return nil
 }
@@ -64,10 +65,11 @@
 			return err
 		}
 		r.SetMeta(&remoteMeta{
-			Name:    ri.Meta.Name,
-			Mesh:    ri.Meta.Mesh,
-			Version: "",
-			// todo(jakubdyszkiewicz) creation and modification time is not set because it's not exposed in API yet
+			Name:             ri.Meta.Name,
+			Mesh:             ri.Meta.Mesh,
+			Version:          "",
+			CreationTime:     ri.Meta.CreationTime,
+			ModificationTime: ri.Meta.ModificationTime,
 		})
 		_ = rs.AddItem(r)
 	}
Index: pkg/core/resources/manager/manager.go
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- pkg/core/resources/manager/manager.go	(revision 93171c8dfd9c82eb6b2f1d26e9f36afcef3f4501)
+++ pkg/core/resources/manager/manager.go	(date 1587544457296)
@@ -47,13 +47,13 @@
 	if err := resource.Validate(); err != nil {
 		return err
 	}
-	opts := store.NewCreateOptions(append(fs, store.CreatedAt(time.Now()))...)
+	opts := store.NewCreateOptions(fs...)
 	if resource.GetType() != mesh.MeshType {
 		if err := r.ensureMeshExists(ctx, opts.Mesh); err != nil {
 			return err
 		}
 	}
-	return r.Store.Create(ctx, resource, fs...)
+	return r.Store.Create(ctx, resource, append(fs, store.CreatedAt(time.Now()))...)
 }
 
 func (r *resourcesManager) ensureMeshExists(ctx context.Context, meshName string) error {

here is a patch for it.
Also please add tests to pkg/plugins/resources/remote/store_test.go to ensure that unmarshalling the times actually works. Thank you.

Hi Jakub, Can I update the existing tests with unmarshalling for unmarshalling the time? or add separate tests.

@jakubdyszkiewicz
Copy link
Contributor

Hi Jakub, Can I update the existing tests with unmarshalling for unmarshalling the time? or add separate tests.

Update existing please

@jakubdyszkiewicz jakubdyszkiewicz merged commit 7aa8726 into kumahq:master Apr 27, 2020
@tharun208 tharun208 deleted the feat/#661 branch April 27, 2020 08:27
@jakubdyszkiewicz
Copy link
Contributor

thank you for the contribution

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

Successfully merging this pull request may close these issues.

Store creation date of every entity
2 participants