Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@mouellet
Copy link
Member

@mouellet mouellet commented Jul 20, 2020

What does this PR accomplish?

Bug Fix | Feature | Documentation

All pipelines are pipeline instances whether they have instance_vars or not...

Changes proposed by this PR:

ATC

  • Adds a jsonb column in the pipelines table with unique partial index.
  • Replaced all pipelineName method parameter with atc.PipelineRef.
  • Adds an instance_vars attribute to the set_pipeline step.

API

  • Adds an optional instance_vars query param as html encoded raw json to all endpoints based on /api/v1/teams/:team_name/pipelines/:pipeline_name.

Fly commands

  • Adds --instance-var flag to set-pipeline command (e.g.: fly set-pipeline -p branch --instance-var branch=feature/foo)
  • Use json flatten in dot notation to identify pipeline instances in flaghelpers.*Flag
    e.g.:
fly ... -p pipeline-name/version:6.0.0,os:windows
fly ... -j pipeline-name/version:6.0.0,os:windows/job-name
fly ... -r pipeline-name/version:6.0.0,os:windows/resource-name

Also support complex json and numeric values as strings or numbers:

{
  "foo": {
    "bar": {
      "baz": 1,
      "qux": "2"
    }
  },
  "bar": [1, "2"]
}

fly ... -p 'pipeline-name/foo.bar.baz:1,foo.bar.qux:"2",bar.0:1,bar.1:"2"'

Notes to reviewer:

Pipeline Groups & UI changes are out of scope of this PR. I feature flagged the use of instance vars in the step and the api so we can merge asap as it is quite large.

Contributor Checklist

Reviewer Checklist

  • Code reviewed
  • Tests reviewed
  • Documentation reviewed
  • Release notes reviewed
  • PR acceptance performed
  • New config flags added? Ensure that they are added to the
    BOSH and
    Helm packaging; otherwise, ignored for
    the integration
    tests

    (for example, if they are Garden configs that are not displayed in the
    --help text).

@mouellet
Copy link
Member Author

Hey @vito, I've been playing around with fly commands for instanced pipeline and I think I've found a way to simplify the fly UX.

Instead of adding --instance-var with a colon (:) for partial filtering to almost all fly commands, I could modify the flaghelpers.*Flag to have an optional coma separated list of key:value pairs as suffix.

e.g.:

fly get-pipeline -p pipeline-group/version:6.0.0,os:windows
fly builds -j pipeline-group/job-name/version:6.0.0,os:windows
fly check-resource -r pipeline-group/resource-name/version:6.0.0,os:windows

Then :

  • The flaghelpers.PipelineFlag: could be like PIPELINE_GROUP/PIPELINE_INSTANCE_VARS
  • The flaghelpers.JobFlag could be like PIPELINE_GROUP/JOB/PIPELINE_INSTANCE_VARS
  • The flaghelpers.ResourceFlag could be like PIPELINE_GROUP/RESOURCE/PIPELINE_INSTANCE_VARS

This also simplifies group operations (like pausing all instances of a group). By just splitting the flag's value on "/", if there's an instance vars suffix we can easily distinguish between instanced and group operations.

What do you think?

@vito
Copy link
Member

vito commented Jul 28, 2020

@mouellet Good idea! Seems like a good use of the flag system, since in these cases the intent of the flag is to identify a single pipeline, and specifying the vars is necessary in order to do that.

One suggestion: the order of PIPELINE/JOB/PIPELINE_VARS feels unintuitive - could we do PIPELINE/PIPELINE_VARS/JOB instead?

@matthewpereira matthewpereira mentioned this pull request Jul 28, 2020
13 tasks
@aoldershaw
Copy link
Contributor

Sorry for the lack of feedback on this @mouellet. It looks really good so far! Was playing around with setting some pipelines, and noticed a couple things:

  1. You can create both a group of instanced pipelines and an individual pipeline with the same name:
$ fly -t dev sp -n -p prs -c pipeline.yml -i number=5896
... (succeeds)
$ fly -t dev sp -n -p prs -c pipeline.yml -i number=5897
... (succeeds)
$ fly -t dev sp -n -p prs -c pipeline.yml
... (succeeds)

I suspect we want to disallow the third fly sp (i.e. a team + pipeline name either refers to a single pipeline or to a group of pipeline instances). Is that true @vito?

  1. Not sure what practical implications this has, but saving a pipeline without instance_vars doesn't result in p.instance_vars being NULL in Postgres - instead, it's the jsonb value of null. At the very least, I think this UNIQUE INDEX won't be used at all:

CREATE UNIQUE INDEX pipelines_name_team_id
ON pipelines (name, team_id)
WHERE instance_vars IS NULL;

@vito
Copy link
Member

vito commented Jul 29, 2020

I suspect we want to disallow the third fly sp (i.e. a team + pipeline name either refers to a single pipeline or to a group of pipeline instances). Is that true @vito?

Yeah that's a good point, the RFC doesn't really make this clear. 🤔 I think we should disallow it; seems pretty sneaky.

@mouellet
Copy link
Member Author

I suspect we want to disallow the third fly sp (i.e. a team + pipeline name either refers to a single pipeline or to a group of pipeline instances). Is that true @vito?

I had the same question, but for now I see all pipelines as pipeline instances whether they have instance vars or not... The Pipeline Groups concept hasn't been introduced yet and I think it's somewhat related to that. BTW, we should have a discussion about that soon!

  1. Not sure what practical implications this has, but saving a pipeline without instance_vars doesn't result in p.instance_vars being NULL in Postgres - instead, it's the jsonb value of null. At the very least, I think this UNIQUE INDEX won't be used at all:

Expect this to be working in the next commits (still WIP...)

@aoldershaw
Copy link
Contributor

I had the same question, but for now I see all pipelines as pipeline instances whether they have instance vars or not

Hmm, that's interesting! All of the UI designs that @matthewpereira has mocked up are under the assumption that all pipeline instances sharing a name would have the same set of instance variables, but I'm realizing now that isn't necessarily the case. Pipeline instances sharing a name may not have the same pipeline configuration, either. Granted, the use case of the across step + set_pipeline with instance vars will result in uniform pipeline instances - but this isn't the only way to create pipeline instances, clearly. I wonder if this changes anything from a design perspective

@mouellet
Copy link
Member Author

I wonder if this changes anything from a design perspective

Hey @aoldershaw , right now I'm focusing on replacing the pipelineName param for (almost) all method and api calls with a new atc.PipelineRef parameter object. This way we'll be able to query, visualize and take actions on individual pipeline instances (e.g. watch the build of a pipeline instance...).

It does allow for everything that you said, and it alone doesn't resolve the rfc... But I think it'll make it flexible enough for which ever design we pick fo the Pipeline Groups as well as pipeline group operations.

Maybe the fly set-pipeline command should remain as-is and a new fly command is needed for setting pipeline groups or templates..?

@mouellet mouellet force-pushed the 5808-instanced-pipelines branch from 823e62c to 2834a51 Compare July 31, 2020 16:59
@aoldershaw
Copy link
Contributor

Hey @mouellet, sorry, I was mostly just thinking out loud as it's something I hadn't really thought of (and wasn't sure if our designer was aware of it or not).

I think the approach you're taking now makes sense!

@mouellet mouellet force-pushed the 5808-instanced-pipelines branch from e9f808f to e8e4984 Compare August 9, 2020 14:55
@mouellet
Copy link
Member Author

One suggestion: the order of PIPELINE/JOB/PIPELINE_VARS feels unintuitive - could we do PIPELINE/PIPELINE_VARS/JOB instead?

Hey @vito, I implemented this and it works great! Definitely more intuitive.

There is one thing however, unmarshalling the flag is a little tricky...

Both pipeline name and job/resource name should be valid identifiers, but not the instance vars with its colon. And dealing with the cases where someone forgot to add the job/resource name at the end (e.g. pipeline-name/branch:master)...

So I added an error when the job/resource name is not a valid identifier even if we only emit warnings for now. Is that ok or should we wait for the valid identifiers to be enforced?

@vito
Copy link
Member

vito commented Aug 10, 2020

So I added an error when the job/resource name is not a valid identifier even if we only emit warnings for now. Is that ok or should we wait for the valid identifiers to be enforced?

Hmm, good question. I think we might have to leave it as a warning for now, since we don't want it to break for someone who has an existing job with invalid characters and was able to use the foo/bar notation up until this point. 🤔

@mouellet mouellet force-pushed the 5808-instanced-pipelines branch 2 times, most recently from 46bd19b to 9a67bde Compare August 18, 2020 17:24
@mouellet mouellet changed the title [WIP] instanced pipelines Instanced pipelines - Add instance vars as part of the pipeline identifier Aug 18, 2020
@mouellet mouellet marked this pull request as ready for review August 18, 2020 17:25
@mouellet mouellet force-pushed the 5808-instanced-pipelines branch 3 times, most recently from d380c99 to 76180f6 Compare August 18, 2020 18:57
@mouellet
Copy link
Member Author

@vito, should I also update the logging, tracing and metrics w/ the pipeline instance vars?

We could use the whole atc.PipelineRef with lager.Data (or anything that takes and interface{} or json) and it would look something like this:

{...,"data":{"pipeline":{"name":"p1","instance_vars":{"branch":"master"}},...}}

Maybe could use the dot notations when it's only a string, like with tracing.Attrs...

What do you think?

@vito
Copy link
Member

vito commented Aug 19, 2020

@mouellet Hmm I wonder if it would be better to just log IDs. Logging pipeline names implies we need to also log e.g. team name/ID, project name/ID (later), and other things to disambiguate since names are non-unique at various levels.

It adds an extra step if you're e.g. trying to search for logs of pipeline XYZ, but on the other hand it's precise, less verbose, and won't involve false positives or additional filtering. 🤔

What do you think?

Side note: maybe we should start a pattern of adding a method like LogData() lager.Data to objects so there's a single place to change this and to make sure everything's using consistent data field names? (e.g. pipeline_id instead of pipeline) Then we can do e.g. log.WithData(pipeline.LogData()) everywhere pipeline-related.

@mouellet
Copy link
Member Author

@vito, maybe this is out of scope for the current PR? It's already quite large and feature flagged...

I suggest we open an issue for that, replacing all names with IDs. In logging, at the API level, etc.

@vito
Copy link
Member

vito commented Aug 20, 2020

@mouellet 👍 yeah sounds wise, that would probably be a bigger change

When the feature is disabled, the flag is only hidden in the 'fly set-pipeline'
command, but the api will error if a instance-vars was specified.

Also, the set_pipeline step will error on validation if instance_vars are specified.

concourse#5808

Signed-off-by: Mathieu Ouellet <[email protected]>
So that we don't get 404 in the UI for instanced pipelines.

concourse#5808

Signed-off-by: Mathieu Ouellet <[email protected]>
nil instance_vars were created as json 'null' and not
Postgres 'NULL', so the partial index wouldn't have worked.

concourse#5808

Signed-off-by: Mathieu Ouellet <[email protected]>
Revert "web: make ordering pipelines working with instanced pipelines"

This reverts commit 9974c92

Revert "web: add instance vars in elm's pipeline identifier"

This reverts commit 9158d34

Revert "web: fix elm-analyse issues & elm benchmarks compilation"

This reverts commit d3d22ba

Signed-off-by: Mathieu Ouellet <[email protected]>
@mouellet mouellet force-pushed the 5808-instanced-pipelines branch from da82019 to 2229139 Compare September 26, 2020 13:52
BaseResourceType *VolumeBaseResourceType `json:"base_resource_type"`
PipelineID int `json:"pipeline_id"`
PipelineName string `json:"pipeline_name"`
PipelineInstanceVars InstanceVars `json:"pipeline_instance_vars"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe omitempty?


func (flag *InstanceVarPairFlag) UnmarshalFlag(value string) error {
flag.Value = atc.DotNotation{}
for _, v := range strings.Split(value, ",") {
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we can get rid of this splitting - it's nice to be able to define vars using dot notation as it avoid shell semantics with {}, but sometimes it may be more convenient to just provide raw YAML surrounded by quotes.

Writing -i foo.bar=1 -i foo.baz=2 isn't that much more annoying than -i foo.bar=1,foo.baz=2, and allowing you do put -i 'foo={bar: 1, baz: 2}' or -i "foo=$(jq ...)" is pretty nice IMO


func unmarshalDotNotation(value string) (atc.DotNotation, error) {
dn := atc.DotNotation{}
for _, v := range strings.Split(value, ",") {
Copy link
Contributor

Choose a reason for hiding this comment

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

It would also be nice to not require dot notation for querying, but that's not so obvious to me how to do that, so I'm fine with this

Copy link
Contributor

@aoldershaw aoldershaw left a comment

Choose a reason for hiding this comment

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

Thanks again for the awesome contribution and sorry for the delay! We really appreciate your patience!

I'm going to merge this now - any updates can be handled in another PR (no pressure to address any of the comments I left - we're happy to do this)

@aoldershaw aoldershaw merged commit f558f86 into concourse:master Sep 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants