structurizr / java

Structurizr for Java
https://docs.structurizr.com/java
Apache License 2.0
1.01k stars 288 forks source link

->container-> expression does not work as expected in deployment view #347

Closed telune closed 2 weeks ago

telune commented 2 weeks ago

Expected

When I define a deployment view, and I use element expressions to include elements, I would expect all element expressions to work.

Actual

If I use element expressions to include the specific element I want, afferent and efferent couplings are not shown; however, they are shown if I include the element I want via a tag.

Steps to reproduce

Here is a sample workspace to illustrate the bug:

workspace "deploymentDiagramBug" {

  !identifiers hierarchical

  model {
    # Software Systems
    ss = softwareSystem "Sample Software System" "" {
      sc1 = container "Sample Container 1" "Does something interesting with 1" "" "TAG1"
      sc2 = container "Sample Container 2" "Does something interesting with 2" "" "TAG2"
    }

    # Relationships
    ss.sc1 -> ss.sc2 "Sends data from 1 to 2"
    ss.sc2 -> ss.sc1 "Sends data from 2 to 1"

    # Deployment environments
    prod = deploymentEnvironment "Production" {
      softwareSystemNode = deploymentNode "Software System Deployment Infrastructure" {
        sc1_vm = deploymentNode "SC1 VM" "" "" {
          sc1_instance = containerInstance ss.sc1
        }
        sc2_vm = deploymentNode "SC2 VM" "" "" {
          sc2_instance = containerInstance ss.sc2
        }
      }
    }
  }

  views {
    deployment ss prod "SC1DeploymentProdViewBug1" "SC1 Deployment View (BUGGED 1)" {
      include "->ss.sc1->"
      autolayout tb
    }
    deployment ss prod "SC1DeploymentProdViewBug2" "SC1 Deployment View (BUGGED 2)" {
      include "element==->ss.sc1->"
      autolayout tb
    }
    deployment ss prod "SC1DeploymentProdViewWork" "SC1 Deployment View (WORKING)" {
      include "->element.tag==TAG1->"
      autolayout tb
    }

    theme default
  }
}

Both "SC1DeploymentProdViewBug1" and "SC1DeploymentProdViewBug2" do not show afferent and efferent couplings:

image

While "SC1DeploymentProdViewWork" shows afferent and efferent couplings:

image

Version/build information

I am using Structurizr Lite version 2024.09.19, taken from Docker Hub (docker.io/structurizr/lite:2024.09.19)

Severity

Minor

Priority

I have no budget and there's no rush, please fix this for free

More information

No response

simonbrowndotje commented 2 weeks ago

I can see why this is failing ... a workaround is to specify the container instances rather than the containers:

    deployment ss prod "SC1DeploymentProdViewBug1" "SC1 Deployment View (BUGGED 1)" {
      include "->prod.softwareSystemNode.sc1_vm.sc1_instance->"
      autolayout tb
    }
telune commented 2 weeks ago

Thanks @simonbrowndotje, the workaround works perfectly. For some reason, I didn't think of that. Is this expected? I mean, is it expected that in deployment views you should reference container instances? Is this documented somewhere? If not, wouldn't it be better to document this in https://docs.structurizr.com/dsl/expressions#element-expressions?

The thing that bothers me is that, if I use the container, it draws the container instance, but not the couplings. So it seems like something is missing somewhere.

simonbrowndotje commented 2 weeks ago

The thing that bothers me is that, if I use the container, it draws the container instance, but not the couplings. So it seems like something is missing somewhere.

It was ... I've added some code to make this work as expected (the commit is linked above).

telune commented 2 weeks ago

Sorry, my bad... I didn't see it was "completed", I thought you closed the issue as the expected behavior was to indicate container instances. I'm not used to such rapid fixes! Kudos!