← Back to Pull requests

grater: add basic interface to interact with docker. #1758

Merged
amishhhaaaa merged 8 files (577 lines) on Apr 23, 2026 08:06 UTC
View on GitHub
amishhhaaaa amishhhaaaa commented on Apr 14, 2026 19:35 UTC
Author

Part of #1528.

  • Add a new interface controller.

  • Docker controller struct can create containers, hold references of all volumes and execute commands inside containers.

  • ExecuteCommand method reports back the output.

  • Mock Docker Controller implements interface with mock methods. Used for slow tests.
  • Diff: 577 lines (+571 / -6) across 8 files Reviewer: dmathieu Review duration: 12271m
    All Vouch review confidence checks passed
    Residual risk 0.06 = Change Risk (0.51) × (1 − Review Confidence (0.88)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.51 · 577 lines diff across 8 files
    0.51
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.84 · 5 substantive comment(s)
    0.84
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    87%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.380
    Real PR Conversation Timeline
    17 items
    codecov[bot] codecov[bot] commented on Apr 14, 2026 19:37 UTC
    Bot

    Codecov Report


    :x: Patch coverage is 71.56863% with 29 lines in your changes missing coverage. Please review.
    :white_check_mark: Project coverage is 62.85%. Comparing base (b15d339) to head (4723c2e).
    :warning: Report is 1 commits behind head on main.

    | Files with missing lines | Patch % | Lines |
    |---|---|---|
    | grater/internal/dockercontainer/dockercontainer.go | 69.41% | 17 Missing and 9 partials :warning: |
    | ...ater/internal/mockcontainer/mockdockercontainer.go | 82.35% | 3 Missing :warning: |

    <details><summary>Additional details and impacted files</summary>

    @@            Coverage Diff             @@
    ##             main    #1758      +/-   ##
    ==========================================
    + Coverage   62.65%   62.85%   +0.20%     
    ==========================================
      Files          71       73       +2     
      Lines        4378     4480     +102     
    ==========================================
    + Hits         2743     2816      +73     
    - Misses       1388     1408      +20     
    - Partials      247      256       +9     
    

    </details>

    :umbrella: View full report in Codecov by Sentry.
    :loudspeaker: Have feedback on the report? Share it here.
    <details><summary> :rocket: New features to boost your workflow: </summary>

  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

  • </details>

    dmathieu dmathieu commented on Apr 17, 2026 07:50 UTC
    Contributor

    This implementation sounds good. But this doesn't include an interface, only the docker struct.
    We mentioned having (and using) a Container interface that would allow having multiple implementation structs (including a mock one), and only use actual docker when we really need it.

    dmathieu dmathieu commented on code on Apr 17, 2026 13:19 UTC
    Code Review
    grater/internal/controller/controller.go:1
    @@ -0,0 +1,16 @@
    +// Copyright The OpenTelemetry Authors
    +// SPDX-License-Identifier: Apache-2.0
    +
    +// Package controller provides an interface for managing Docker containers and volumes.
    +package controller
    +
    +import (
    +    "github.com/docker/docker/api/types/container"
    +)
    +
    +// Controller is an interface for managing Docker containers and volumes.
    +type Controller interface {

    IMHO, Controller is too generic. It could be many things. I would name this Container, even though it may not actually be a "container" in the docker sense.

    amishhhaaaa amishhhaaaa commented on code on Apr 17, 2026 14:17 UTC
    Code Review
    grater/internal/controller/controller.go:1
    @@ -0,0 +1,16 @@
    +// Copyright The OpenTelemetry Authors
    +// SPDX-License-Identifier: Apache-2.0
    +
    +// Package controller provides an interface for managing Docker containers and volumes.
    +package controller
    +
    +import (
    +    "github.com/docker/docker/api/types/container"
    +)
    +
    +// Controller is an interface for managing Docker containers and volumes.
    +type Controller interface {

    Renamed the struct to Container, however the package controller cannot be renamed to container as it was causing a import conflict with docker/container.
    Troublesome import pattern:

    "github.com/docker/docker/api/types/container"

    "go.opentelemetry.io/build-tools/grater/internal/container"

    Now:

    "github.com/docker/docker/api/types/container"

    "go.opentelemetry.io/build-tools/grater/internal/controller"

    dmathieu dmathieu commented on code on Apr 17, 2026 14:21 UTC
    Code Review
    grater/internal/controller/controller.go:1
    @@ -0,0 +1,16 @@
    +// Copyright The OpenTelemetry Authors
    +// SPDX-License-Identifier: Apache-2.0
    +
    +// Package controller provides an interface for managing Docker containers and volumes.
    +package controller
    +
    +import (
    +    "github.com/docker/docker/api/types/container"
    +)
    +
    +// Controller is an interface for managing Docker containers and volumes.
    +type Controller interface {

    You could import the docker container package with a specific name.

    dockerContainer "github.com/docker/docker/api/types/container"
    "go.opentelemetry.io/build-tools/grater/internal/container"
    

    dmathieu dmathieu commented on code on Apr 17, 2026 15:08 UTC
    Code Review
    grater/internal/container/container.go:1
    @@ -0,0 +1,19 @@
    +// Copyright The OpenTelemetry Authors
    +// SPDX-License-Identifier: Apache-2.0
    +
    +//go:build integration
    +// +build integration

    Only tests should have the integration build. Otherwise. We can't use them at runtime.

    dmathieu dmathieu commented on code on Apr 20, 2026 08:01 UTC
    Code Review
    grater/internal/dockercontroller/mockdockercontroller.go:1
    @@ -0,0 +1,49 @@
    +// Copyright The OpenTelemetry Authors
    +// SPDX-License-Identifier: Apache-2.0
    +
    +// Package dockercontroller provides a mock implementation of the DockerController interface.
    +package dockercontroller

    This is a mock container, not specific to docker. How about having it in grater/internal/mockcontainer?

    dmathieu dmathieu commented on code on Apr 20, 2026 08:01 UTC
    Code Review
    grater/internal/dockercontainer/dockercontroller.go:1
    @@ -0,0 +1,135 @@
    +// Copyright The OpenTelemetry Authors
    +// SPDX-License-Identifier: Apache-2.0
    +
    +// Package dockercontroller provides a controller for managing Docker.
    +package dockercontroller

    package dockercontainer
    

    dmathieu dmathieu commented on code on Apr 21, 2026 07:38 UTC
    Code Review
    grater/internal/mockcontainer/mockdockercontroller.go:1
    @@ -0,0 +1,49 @@
    +// Copyright The OpenTelemetry Authors
    +// SPDX-License-Identifier: Apache-2.0
    +
    +// Package mockcontainer provides a mock implementation of the DockerController interface.

    // Package mockcontainer provides a mock implementation of the Container interface.
    

    dmathieu dmathieu commented on code on Apr 21, 2026 07:38 UTC
    Code Review
    grater/internal/mockcontainer/mockdockercontroller.go:1
    @@ -0,0 +1,49 @@
    +// Copyright The OpenTelemetry Authors
    +// SPDX-License-Identifier: Apache-2.0
    +
    +// Package mockcontainer provides a mock implementation of the DockerController interface.
    +package mockcontainer
    +
    +import (
    +	"github.com/moby/moby/client"
    +
    +	"go.opentelemetry.io/build-tools/grater/internal/container"
    +)
    +
    +// MockDockerContainer is a mock implementation of the DockerContainer interface.

    // MockDockerContainer is a mock implementation of the Container interface.
    

    dmathieu dmathieu commented on code on Apr 21, 2026 07:39 UTC
    Code Review
    grater/internal/container/container.go:1
    @@ -0,0 +1,14 @@
    +// Copyright The OpenTelemetry Authors
    +// SPDX-License-Identifier: Apache-2.0
    +
    +// Package container provides an interface for managing Docker containers and volumes.
    +package container
    +
    +import "github.com/moby/moby/client"
    +
    +// Container defines the interface for managing Docker containers and volumes.
    +type Container interface {
    +	CreateVolume(volumeName string) (func(), error)
    +	UseContainer(imageName string, volumeNames []string) (string, func(), error)
    +	ExecuteCommand(containerID string, cmd []string) (string, client.ExecInspectResult, error)

    This interface shouldn't have a dependency on moby, it should be generic (only one implementation will use moby).
    Also, we can improve that later, but I'd return structs rather than func or string, to make things more generic as well.

    dmathieu dmathieu commented on Apr 21, 2026 07:39 UTC
    Reviewer

    We're getting there 😸

    amishhhaaaa amishhhaaaa commented on code on Apr 21, 2026 13:38 UTC
    Code Review
    grater/internal/container/container.go:1
    @@ -0,0 +1,14 @@
    +// Copyright The OpenTelemetry Authors
    +// SPDX-License-Identifier: Apache-2.0
    +
    +// Package container provides an interface for managing Docker containers and volumes.
    +package container
    +
    +import "github.com/moby/moby/client"
    +
    +// Container defines the interface for managing Docker containers and volumes.
    +type Container interface {
    +	CreateVolume(volumeName string) (func(), error)
    +	UseContainer(imageName string, volumeNames []string) (string, func(), error)
    +	ExecuteCommand(containerID string, cmd []string) (string, client.ExecInspectResult, error)

    Instead of client.ExecInspectResult I have updated to return int of exitcode as the usecase of this was to eventually know the exitcode of commands only, as we already return out separately as string.

    amishhhaaaa amishhhaaaa commented on code on Apr 21, 2026 14:00 UTC
    Code Review
    grater/internal/container/container.go:1
    @@ -0,0 +1,14 @@
    +// Copyright The OpenTelemetry Authors
    +// SPDX-License-Identifier: Apache-2.0
    +
    +// Package container provides an interface for managing Docker containers and volumes.
    +package container
    +
    +import "github.com/moby/moby/client"
    +
    +// Container defines the interface for managing Docker containers and volumes.
    +type Container interface {
    +	CreateVolume(volumeName string) (func(), error)
    +	UseContainer(imageName string, volumeNames []string) (string, func(), error)
    +	ExecuteCommand(containerID string, cmd []string) (string, client.ExecInspectResult, error)

    Yes, its better to make a generic struct response like, ExecuteCommandResponse, which we can extend and modify as we want in future, how about we make a follow up PR for this?

    dmathieu dmathieu approved these changes on Apr 21, 2026 15:38 UTC
    Approved Reviewer

    Approved these changes.

    mx-psi mx-psi approved these changes on Apr 23, 2026 07:57 UTC
    Approved Reviewer

    Approved these changes.

    Reviewers
    Assignees
    amishhhaaaa amishhhaaaa
    Labels
    risk: low confidence: 87.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 51.3% (MEDIUM) · Higher = larger blast radius
    51.3%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 87.5% · Lower = rushed or shallow review
    87.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 6.4% · Safe to merge
    6.4%