Skip to content

cmd/ctr/commands/tasks: build metrics with target platform#8234

Closed
fuweid wants to merge 1 commit intocontainerd:mainfrom
fuweid:fix-dep-issue-cgroups
Closed

cmd/ctr/commands/tasks: build metrics with target platform#8234
fuweid wants to merge 1 commit intocontainerd:mainfrom
fuweid:fix-dep-issue-cgroups

Conversation

@fuweid
Copy link
Copy Markdown
Member

@fuweid fuweid commented Mar 8, 2023

The windows container is using containerd/cgroups@v1.1.0 for metrics while the linux container is using containerd/cgroups@v3.0.1. They are two different packages but the metric fields in proto share the same name. For instance, the Metrics type:

  • in cgroups@v1.1.0, it is named by io.containerd.cgroups.v1.Metrics[1].
  • in cgroups@v3.0.1, it's also named by io.containerd.cgroups.v1.Metrics[2].

It's hard to tell the real type, even if both types are compatible. According to typeurl/v2@v2.1.0's behavior[3], it will check the type registed by the RegisterType first. Let's see a case.

If the data is marshaled by containerd/cgroups@v3.0.1 and the typeurl is io.containerd.cgroups.v1.Metrics, ideally the receiver should use the same type to unmarshal it. However, if the receiver has a dependency using the cgroups@v1.1.0, the cgroups@v1.1.0 package will register the type with io.containerd.cgroups.v1.Metrics by gogo.RegisterType. And the receiver will cgroups@v1.1.0's type to unmarshal the data. It's compatible but it is unexpected because the receiver will use the cgroups@v3.0.1 to do the type assertion, like what nerdctl pr[4] does. They will fail to do assertion.

Currently, the windows container metrics is using
containerd/cgroups@v1.1.0, which impacts nerdctl to do release. So I would like to file this pr to build metrics with target platform.

REF:
[1]: https://github.com/containerd/cgroups/blob/v1.1.0/stats/v1/metrics.pb.go#L705
[2]: https://github.com/containerd/cgroups/blob/v3.0.1/cgroup1/stats/metrics.pb.go#L1705
[3]: https://github.com/containerd/typeurl/blob/v2.1.0/types.go#L238-L264
[4]: containerd/nerdctl#1952

@fuweid fuweid requested a review from AkihiroSuda March 8, 2023 12:01
@fuweid fuweid force-pushed the fix-dep-issue-cgroups branch from e7852cf to 52ab6f8 Compare March 8, 2023 12:09
@fuweid fuweid force-pushed the fix-dep-issue-cgroups branch from 52ab6f8 to 24097cd Compare March 8, 2023 12:14
Copy link
Copy Markdown
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

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

Thanks

The windows container is using containerd/cgroups@v1.1.0 for metrics
while the linux container is using containerd/cgroups@v3.0.1. They are
two different packages but the metric fields in proto share the same
name. For instance, the `Metrics` type:

* in cgroups@v1.1.0, it is named by io.containerd.cgroups.v1.Metrics[1].
* in cgroups@v3.0.1, it's also named by io.containerd.cgroups.v1.Metrics[2].

It's hard to tell the real type, even if both types are compatible.
According to typeurl/v2@v2.1.0's behavior[3], it will check the type
registed by the `RegisterType` first. Let's see a case.

If the data is marshaled by containerd/cgroups@v3.0.1 and the typeurl is
`io.containerd.cgroups.v1.Metrics`, ideally the receiver should use the
same type to unmarshal it. However, if the receiver has a dependency
using the cgroups@v1.1.0, the cgroups@v1.1.0 package will register the
type with `io.containerd.cgroups.v1.Metrics` by `gogo.RegisterType`. And
the receiver will cgroups@v1.1.0's type to unmarshal the data. It's
compatible but it is unexpected because the receiver will use the
`cgroups@v3.0.1` to do the type assertion, like what nerdctl pr[4] does.
They will fail to do assertion.

Currently, the windows container metrics is using
containerd/cgroups@v1.1.0, which impacts nerdctl to do release. So I
would like to file this pr to build metrics with target platform.

REF:
[1]: https://github.com/containerd/cgroups/blob/v1.1.0/stats/v1/metrics.pb.go#L705
[2]: https://github.com/containerd/cgroups/blob/v3.0.1/cgroup1/stats/metrics.pb.go#L1705
[3]: https://github.com/containerd/typeurl/blob/v2.1.0/types.go#L238-L264
[4]: containerd/nerdctl#1952

Signed-off-by: Wei Fu <fuweid89@gmail.com>
@fuweid fuweid force-pushed the fix-dep-issue-cgroups branch from 24097cd to 3f14890 Compare March 8, 2023 12:22
@dmcgowan
Copy link
Copy Markdown
Member

dmcgowan commented Mar 8, 2023

Is this intended as a temporary fix until the Windows container metrics or cgroups package can be updated? Splitting apart the compiled Windows/Linux logic like this is the opposite direction we have been trying go in to unify our cross platform logic.

@fuweid
Copy link
Copy Markdown
Member Author

fuweid commented Mar 8, 2023

Is this intended as a temporary fix until the Windows container metrics or cgroups package can be updated? Splitting apart the compiled Windows/Linux logic like this is the opposite direction we have been trying go in to unify our cross platform logic.

@dmcgowan it is temporary fix for nerdctl release. No sure that when windows container can be updated...

@AkihiroSuda
Copy link
Copy Markdown
Member

For nerdctl release I think we can just copy cmd/ctr/commands/tasks pkg to the nerdctl repo and call it a day.

@fuweid
Copy link
Copy Markdown
Member Author

fuweid commented Mar 9, 2023

@AkihiroSuda sounds 👍. I close this. Thanks

@fuweid fuweid closed this Mar 9, 2023
@fuweid fuweid deleted the fix-dep-issue-cgroups branch March 9, 2023 00:23
@AkihiroSuda
Copy link
Copy Markdown
Member

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.

3 participants