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

Metrics Fixes #2319

Merged
merged 12 commits into from
Mar 11, 2022
Merged

Metrics Fixes #2319

merged 12 commits into from
Mar 11, 2022

Conversation

maroshii
Copy link
Contributor

@maroshii maroshii commented Mar 6, 2022

Send the deploy origin in the deploy mutation. Adding a special source: okteto-deploy used for deploy commands ran from within another okteto deploy

@maroshii maroshii requested a review from a team March 6, 2022 00:12
@derek
Copy link

derek bot commented Mar 6, 2022

Thank you for your contribution. unfortunately, one or more of your commits are missing the required "Signed-off-by:" statement. Signing off is part of the Developer Certificate of Origin (DCO) which is used by this project.

Read the DCO and project contributing guide carefully, and amend your commits using the git CLI. Note that this does not require any cryptography, keys or special steps to be taken.

💡 Shall we fix this?

This will only take a few moments.

First, clone your fork and checkout this branch using the git CLI.

Next, set up your real name and email address:

git config --global user.name "Your Full Name"
git config --global user.email "you@domain.com"

Finally, run one of these commands to add the "Signed-off-by" line to your commits.

If you only have one commit so far then run: git commit --amend --signoff and then git push --force.
If you have multiple commits, watch this video.

Check that the message has been added properly by running "git log".

@derek derek bot added the no-dco label Mar 6, 2022
@codecov-commenter
Copy link

codecov-commenter commented Mar 6, 2022

Codecov Report

Merging #2319 (289c304) into master (fea9900) will decrease coverage by 0.10%.
The diff coverage is 1.21%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2319      +/-   ##
==========================================
- Coverage   32.05%   31.94%   -0.11%     
==========================================
  Files         149      149              
  Lines       17133    17194      +61     
==========================================
+ Hits         5492     5493       +1     
- Misses      11009    11069      +60     
  Partials      632      632              
Impacted Files Coverage Δ
pkg/analytics/track.go 5.98% <0.00%> (-0.27%) ⬇️
pkg/config/config.go 18.75% <0.00%> (-1.64%) ⬇️
pkg/okteto/context.go 18.72% <0.00%> (ø)
pkg/okteto/pipeline.go 0.00% <0.00%> (ø)
pkg/okteto/preview.go 0.00% <0.00%> (ø)
cmd/deploy/deploy.go 24.39% <4.54%> (-0.71%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fea9900...289c304. Read the comment docs.

@@ -58,6 +61,7 @@ func (c *OktetoClient) DeployPipeline(ctx context.Context, name, repository, bra
"branch": graphql.String(branch),
"variables": variablesVariable,
"filename": graphql.String(filename),
"source": graphql.String(origin),
}

err := mutate(ctx, &mutation, queryVariables, c.client)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we check if the mutation returns the new error "Unknown argument \"source\" on type \"GitDeploy\"") so we can run the deprecated version of deployPipeline

Copy link
Member

Choose a reason for hiding this comment

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

yes, I think we should do it because the source parameter was released on the OE 0.10.7 and probably there are still OE in previous versions. @pchico83 Can you confirm is there is any OE in version < 0.10.7?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, this change should be backward compatible. One option is to pass this value as an envvar of the pipeline deployment, not sure if that makes things easier or not

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it. If we use the deprecatedDeploy tho it would send all deploys on 0.10.7 to the deprecated path of 0.10.0, right? I'll try to send it as an envvar as Pablo suggests

}
// deploys within another okteto deploy take precedence as a deploy origin.
// This is running okteto pipeline deploy as a step of another okteto deploy
if os.Getenv(model.OktetoWithinDeployCommandContextEnvVar) == "true" {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we need to revisit the places where we are checking this env var. Deploy command sets it as false almost at the beginning of the command: https://github.com/okteto/okteto/blob/master/cmd/deploy/deploy.go#L131

I see several checks that I'm not sure they are working as expected

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This works for multi repo with okteto pipeline deploy. Eg: https://github.com/okteto/movies-api/blob/main/okteto-pipeline.yml#L3

Not sure if okteto deploy inside another okteto deploy is a thing? If so the metrics will be somewhat skewed but not sure how many of these occurrences there will be. I can always create another envvar

Copy link
Member

Choose a reason for hiding this comment

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

I don't think it will be frequent. For now I wouldn't consider that case until users start using it.

There is one case that I'm not sure which should be the right value for the metric. If you execute okteto deploy -b master or okteto deploy -r https://github.com/okteto/movies, it will execute directly a pipeline https://github.com/okteto/okteto/blob/master/cmd/deploy/deploy.go#L116 but it wouldn't be considered within an okteto deploy command. Which honestly, not sure if it is right or not.

Also, bear in mind that a pipeline is executed in the backend as an okteto deploy, in case it affects somehow the metrics

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ifbyol can you take another look? I added OKTETO_SKIP_CONFIG_CREDENTIALS_UPDATE for the proxy case you describe and kept the origin OKTETO_WITHIN_DEPLOY_COMMAND_CONTEXT independent from all that so we can use it safely everywhere else knowing it will not change

Copy link
Member

Choose a reason for hiding this comment

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

@maroshii looks good to me, but there are other places where that variable was using before and not sure if they should use the new one or the old one. Looking in to the code, I would say they have to use OKTETO_WITHIN_DEPLOY_COMMAND_CONTEXT, but @jLopezbarb can you double check, please? If you have doubts about what we are talking about, let me know and we can do a quick call

@@ -58,6 +61,7 @@ func (c *OktetoClient) DeployPipeline(ctx context.Context, name, repository, bra
"branch": graphql.String(branch),
"variables": variablesVariable,
"filename": graphql.String(filename),
"source": graphql.String(origin),
}

err := mutate(ctx, &mutation, queryVariables, c.client)
Copy link
Member

Choose a reason for hiding this comment

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

yes, I think we should do it because the source parameter was released on the OE 0.10.7 and probably there are still OE in previous versions. @pchico83 Can you confirm is there is any OE in version < 0.10.7?

@maroshii maroshii force-pushed the fran/deploy-origin branch 2 times, most recently from ea9264b to 02ef72d Compare March 7, 2022 20:16
Duration: time.Since(startTime),
PipelineType: c.PipelineType,
DeployType: deployType,
IsPreview: false, // TODO: How should we get this value?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jLopezbarb is there a way to know this here?

Copy link
Contributor

Choose a reason for hiding this comment

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

The only thing I can think of is checking if its an okteto cluster and then call to the API to check if exists the namespace as preview or namespace

Copy link
Member

Choose a reason for hiding this comment

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

Possible options I see are:

  • Use client-go library to get the ns information and check annotations/labels (scope). I don't like it because we would be coupling the CLI with the logic of checking the scope to know if it is a preview env or a normal namespace and it would be harder to remove the scope in the future
  • Pass an environment variable to the pipeline job specifying if it is a normal pipeline or a preview environment. In that way, that environment variable would be injected in the okteto deploy command and it would be available here to check

@maroshii
Copy link
Contributor Author

maroshii commented Mar 7, 2022

NOTE TO SELF: we are still missing to track and send OKTETO_ORIGIN as a variable in the deployPreview mutation

Duration: time.Since(startTime),
PipelineType: c.PipelineType,
DeployType: deployType,
IsPreview: false, // TODO: How should we get this value?
Copy link
Member

Choose a reason for hiding this comment

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

Possible options I see are:

  • Use client-go library to get the ns information and check annotations/labels (scope). I don't like it because we would be coupling the CLI with the logic of checking the scope to know if it is a preview env or a normal namespace and it would be harder to remove the scope in the future
  • Pass an environment variable to the pipeline job specifying if it is a normal pipeline or a preview environment. In that way, that environment variable would be injected in the okteto deploy command and it would be available here to check

// TrackDeploy sends a tracking event to mixpanel when the user deploys a pipeline
func TrackDeploy(m TrackDeployMetadata) {
// skip deploys from nested okteto deploys and manifest dependencies
if config.GetDeployOrigin() == "okteto-deploy" {
Copy link
Member

Choose a reason for hiding this comment

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

👍

@@ -49,7 +49,7 @@ const (
doctorEvent = "Doctor"
buildEvent = "Build"
buildTransientErrorEvent = "BuildTransientError"
deployEvent = "Deploy"
deployEvent = "OktetoDeploy"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rlamana this is the new event name. Between this change and the recent backend change we'll no longer get the Deploy event. Just confirming we are ok with this

Copy link
Contributor

Choose a reason for hiding this comment

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

So, is this the event for the nested ones? Or in general? If we end up starting a new mixpanel project like we've been discussing, I want this event to still be Deploy. And if we end up using a prefix, I think all these events (UP, CONTEXT, etc..) should have the same prefix.

@maroshii maroshii changed the title Add deploy origin Track Deploy Mar 9, 2022
pkg/analytics/track.go Outdated Show resolved Hide resolved
@maroshii maroshii changed the title Track Deploy Metrics Fixes Mar 9, 2022
@maroshii
Copy link
Contributor Author

maroshii commented Mar 9, 2022

With the latest changes this PR tracks all the metrics needed as per business requirements.
It takes into account OKTETO_ORIGIN from other sources like vscode, github actions, etc. This wasn't properly forwarded for previews for eg.

@maroshii maroshii requested a review from rlamana March 9, 2022 17:02
Copy link
Member

@ifbyol ifbyol left a comment

Choose a reason for hiding this comment

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

LGTM with the context I have

@maroshii maroshii merged commit 9ab9c9d into master Mar 11, 2022
@maroshii maroshii deleted the fran/deploy-origin branch March 11, 2022 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants