https://infracost.io logo
Title
b

brave-dinner-47346

02/25/2022, 3:09 PM
Hey everyone, does anyone have any issues with MR comments not updating? My pipeline keeps creating new comments despite passing the update bahavior perimeter. Ive tried changing the tagging as well from the default. This is my current gitlab-ci command:
- infracost comment gitlab
      --gitlab-server-url $CI_SERVER_URL
      --gitlab-token $GITLAB_TOKEN
      --path infracost.json
      --repo $CI_PROJECT_PATH
      --merge-request $CI_MERGE_REQUEST_IID
      --behavior update

Logs:
time="2022-02-25T14:44:44Z" level=info msg="Finding matching comments for tag infracost-comment"
time="2022-02-25T14:44:44Z" level=info msg="Found 0 matching comments"
time="2022-02-25T14:44:44Z" level=info msg="Creating new comment"
b

busy-agent-35515

02/25/2022, 3:31 PM
Hey Bryce! Interesting šŸ¤”
Can you see the text of the existing comments? At the very top they should have
[//]: <> (infracost-comment)
markdown comment. That's how we track them. It should be visible in comment's editor
b

brave-dinner-47346

02/25/2022, 3:42 PM
[//]: <> (infracost)

šŸ’° Infracost estimate: **monthly cost will not change**
<table>
  <thead>
    <td>Project</td>
    <td>Previous</td>
    <td>New</td>
    <td>Diff</td>
  </thead>
  <tbody>
    <tr>
      <td>mmsys/fed/EMR/terraform/test.json</td>
      <td align="right">$0</td>
      <td align="right">$0</td>
      <td>$0</td>
    </tr>
  </tbody>
</table>

<details>
<summary><strong>Infracost output</strong></summary>
b

busy-agent-35515

02/25/2022, 3:44 PM
Hm, okay. So this comment has the tag
infracost
. If you use the CI command without the
--tag infracost
flag, it will start searching for
infracost-comment
. So this one won't be matched.
Are there other comments?
b

brave-dinner-47346

02/25/2022, 3:47 PM
So I am trying this locally as well:
[//]: <> (infracost-comment)

šŸ’° Infracost estimate: **monthly cost will not change**
<table>
  <thead>
    <td>Project</td>
    <td>Previous</td>
    <td>New</td>
    <td>Diff</td>
  </thead>
  <tbody>
    <tr>
      <td>mmsys/fed/EMR/terraform/mmsys-preprod-plan.out.json</td>
      <td align="right">$0</td>
      <td align="right">$0</td>
      <td>$0</td>
    </tr>
  </tbody>
</table>

<details>
<summary><strong>Infracost output</strong></summary>
this comes from
infracost comment gitlab \ 
--gitlab-server-url <https://gitlab.com> \
--repo mmsys/fed/EMR \
--merge-request 10 \
--tag GITLAB_TOKEN_FED_EMR \
--path infracost.json \
--behavior update \
--gitlab-token $TOKEN \
--log-level debug
if I run this again I still see
time="2022-02-25T16:46:45+01:00" level=info msg="Finding matching comments for tag GITLAB_TOKEN_FED_EMR"
time="2022-02-25T16:46:45+01:00" level=info msg="Found 0 matching comments"
time="2022-02-25T16:46:45+01:00" level=info msg="Creating new comment"
b

busy-agent-35515

02/25/2022, 3:49 PM
Is
GITLAB_TOKEN_FED_EMR
and env var or a tag value?
b

brave-dinner-47346

02/25/2022, 3:50 PM
no its just a string
for testing purposes
b

busy-agent-35515

02/25/2022, 3:51 PM
From the command it will be treated as a string, and if there are no any other comments with
GITLAB_TOKEN_FED_EMR
in them, it won't match. Could you please change your TF file and push it again? Currently I'm seeing you using 3 different tags (default one,
infracost
and
GITLAB_TOKEN_FED_EMR
)
As you already have one comment with
infracost
tag, could you try to use
--tag infracost
?
BTW, I just tested the command on our demo app, it worked as expected. Although it's not a self-hosted version https://gitlab.com/infracost/gitlab-ci-demo/-/merge_requests/26#note_855633119
b

brave-dinner-47346

02/25/2022, 3:55 PM
Well, I've been cleaning up the multiple comments šŸ˜† and trying to experiment locally which is where the other tags came from
šŸ™‚ 1
I will try another build with the following commands:
- infracost breakdown --sync-usage-file
      --usage-file infracost-usage.yml
      --format json --path ${PLAN}.json
      --out-file infracost.json

    - infracost comment gitlab
      --gitlab-server-url $CI_SERVER_URL
      --gitlab-token $GITLAB_TOKEN
      --path infracost.json
      --tag infracost
      --repo $CI_PROJECT_PATH
      --merge-request $CI_MERGE_REQUEST_IID
      --behavior update
šŸ¤ž 1
creating a comment
[//]: <> (infracost)

šŸ’° Infracost estimate: **monthly cost will not change**
<table>
  <thead>
    <td>Project</td>
    <td>Previous</td>
    <td>New</td>
    <td>Diff</td>
  </thead>
  <tbody>
    <tr>
      <td>mmsys/fed/EMR/terraform/mmsys-preprod-plan.out.json</td>
      <td align="right">$0</td>
      <td align="right">$0</td>
      <td>$0</td>
    </tr>
  </tbody>
</table>

<details>
<summary><strong>Infracost output</strong></summary>
b

busy-agent-35515

02/25/2022, 3:58 PM
Okay, looks correct. Let's change a TF file and re-run the comment command šŸ™‚
b

brave-dinner-47346

02/25/2022, 3:58 PM
sure
b

busy-agent-35515

02/25/2022, 3:59 PM
FYI if there are no any changes in the output, the command won't post anything
b

brave-dinner-47346

02/25/2022, 4:02 PM
Just changing some s3 bucket names...
$ infracost comment gitlab --gitlab-server-url $CI_SERVER_URL --gitlab-token $GITLAB_TOKEN --path infracost.json --tag infracost --repo $CI_PROJECT_PATH --merge-request $CI_MERGE_REQUEST_IID --behavior update
time="2022-02-25T16:01:40Z" level=info msg="Finding matching comments for tag infracost"
time="2022-02-25T16:01:41Z" level=info msg="Found 0 matching comments"
time="2022-02-25T16:01:41Z" level=info msg="Creating new comment"
b

busy-agent-35515

02/25/2022, 4:03 PM
Seems like a bug. Do both comments have the
infracost
tag?
b

brave-dinner-47346

02/25/2022, 4:04 PM
yah, its the same build same commands adjusting some bucket names in the terraform code
image:
    name: infracost/infracost:ci-0.9
full comment, if it helps
[//]: <> (infracost)

šŸ’° Infracost estimate: **monthly cost will not change**
<table>
  <thead>
    <td>Project</td>
    <td>Previous</td>
    <td>New</td>
    <td>Diff</td>
  </thead>
  <tbody>
    <tr>
      <td>mmsys/fed/EMR/terraform/mmsys-preprod-plan.out.json</td>
      <td align="right">$0</td>
      <td align="right">$0</td>
      <td>$0</td>
    </tr>
  </tbody>
</table>

<details>
<summary><strong>Infracost output</strong></summary>
Project: mmsys/fed/EMR/terraform/mmsys-preprod-plan.out.json + module.s3_log_storage.aws_s3_bucket.default[0] Monthly cost depends on usage + Standard + Storage Monthly cost depends on usage +$0.0245 per GB + PUT, COPY, POST, LIST requests Monthly cost depends on usage +$0.0054 per 1k requests + GET, SELECT, and all other requests Monthly cost depends on usage +$0.00043 per 1k requests + Select data scanned Monthly cost depends on usage +$0.00225 per GB + Select data returned Monthly cost depends on usage +$0.0008 per GB + Standard - infrequent access + Storage Monthly cost depends on usage +$0.0135 per GB + PUT, COPY, POST, LIST requests Monthly cost depends on usage +$0.01 per 1k requests + GET, SELECT, and all other requests Monthly cost depends on usage +$0.001 per 1k requests + Retrievals Monthly cost depends on usage +$0.01 per GB + Select data scanned Monthly cost depends on usage +$0.00225 per GB + Select data returned Monthly cost depends on usage +$0.01 per GB + Glacier flexible retrieval + Storage Monthly cost depends on usage +$0.00405 per GB + PUT, COPY, POST, LIST requests Monthly cost depends on usage +$0.036 per 1k requests + GET, SELECT, and all other requests Monthly cost depends on usage +$0.00043 per 1k requests + Retrieval requests (standard) Monthly cost depends on usage +$0.036 per 1k requests + Retrievals (standard) Monthly cost depends on usage +$0.012 per GB + Select data scanned (standard) Monthly cost depends on usage +$0.0096 per GB + Select data returned (standard) Monthly cost depends on usage +$0.012 per GB + Retrieval requests (expedited) Monthly cost depends on usage +$12.00 per 1k requests + Retrievals (expedited) Monthly cost depends on usage +$0.036 per GB + Select data scanned (expedited) Monthly cost depends on usage +$0.024 per GB + Select data returned (expedited) Monthly cost depends on usage +$0.036 per GB + Select data scanned (bulk) Monthly cost depends on usage +$0.0012 per GB + Select data returned (bulk) Monthly cost depends on usage +$0.003 per GB + Early delete (within 90 days) Monthly cost depends on usage +$0.00405 per GB Monthly cost change for mmsys/fed/EMR/terraform/mmsys-preprod-plan.out.json Amount: $0.00 ($0.00 → $0.00) ────────────────────────────────── Key: ~ changed, + added, - removed 37 cloud resources were detected: āˆ™ 1 was estimated, 1 includes usage-based costs, see https://infracost.io/usage-file āˆ™ 1 wasn't estimated, report it in https://github.com/infracost/infracost: āˆ™ 1 x aws_emr_cluster āˆ™ 35 were free: āˆ™ 8 x aws_security_group_rule āˆ™ 5 x aws_security_group āˆ™ 3 x aws_iam_role āˆ™ 3 x aws_iam_role_policy_attachment āˆ™ 2 x aws_network_acl āˆ™ 2 x aws_route_table āˆ™ 2 x aws_route_table_association āˆ™ 2 x aws_subnet āˆ™ 1 x aws_default_security_group āˆ™ 1 x aws_iam_instance_profile āˆ™ 1 x aws_internet_gateway āˆ™ 1 x aws_key_pair āˆ™ 1 x aws_route āˆ™ 1 x aws_s3_bucket_public_access_block āˆ™ 1 x aws_vpc āˆ™ 1 x aws_vpc_endpoint
</details>

This comment will be updated when the cost estimate changes.

<sub>
  Is this comment useful? <a href="<https://www.infracost.io/feedback/submit/?value=yes>" rel="noopener noreferrer" target="_blank">Yes</a>, <a href="<https://www.infracost.io/feedback/submit/?value=no>" rel="noopener noreferrer" target="_blank">No</a>
</sub>
b

busy-agent-35515

02/25/2022, 4:11 PM
Thank you very much for helping with the debug! May I ask what version of GitLab you're using? Is it Enterprise Edition?
b

brave-dinner-47346

02/25/2022, 4:13 PM
GitLab Enterprise Edition 13.12.9-ee
b

busy-agent-35515

02/25/2022, 4:13 PM
We are using GitLab GraphQL API to fetch the MR comments. It works with the cloud version as I mentioned above, so I assume there might be something up with EE's API.
b

brave-dinner-47346

02/25/2022, 4:14 PM
the big sad 😭, in the meanwhile maybe I can post to slack or so instead
b

busy-agent-35515

02/25/2022, 4:17 PM
We always want to know more how our users use Infracost. May I ask how often do you push to the same MR and are the new comments too noisy for you?
If you have couple more minutes, maybe you'd be able to run a curl command to the API? Maybe we can see what it returns and pinpoint the issue
Also, maybe you know the API scope of the access token? It should be
api
for read and write requests
b

brave-dinner-47346

02/25/2022, 4:26 PM
This is a new project to move to gitlab from some legacy stuff, it will be used quite heavily in the future. I guess merge request can get quite noisy if it post a comment every commit push
the token is read/write for the repo and has full api access
šŸ‘ 1
I can maybe test a curl command or two šŸ˜Ž
b

busy-agent-35515

02/25/2022, 4:28 PM
Haha, nice. Thank you šŸ™ Let me prepare it and I'll get back to you asap.
b

brave-dinner-47346

02/25/2022, 4:28 PM
sure
b

busy-agent-35515

02/25/2022, 5:43 PM
Sorry for the delay. Here's the command
curl -X POST \
-H "Authorization: Bearer $GITLAB_TOKEN" \
-H "Content-Type: application/json" \
-d '{"query": "{project(fullPath: \"mmsys/fed/EMR\") {mergeRequest(iid: \"10\") {notes { nodes {id url createdAt body}}}}}"}' \
$CI_SERVER_URL
I think you just need to have the token and the url env vars set up and it should work. Well, we'll see šŸ˜„
b

brave-dinner-47346

02/28/2022, 1:27 PM
with that curl I am unfortunately getting a 404 return šŸ˜ž
<title>The page you're looking for could not be found (404)</title>
b

busy-agent-35515

02/28/2022, 1:32 PM
hey Bryce. My bad, the url should be
$CI_SERVER_URL/api/graphql
if it's the same as for the gitlab.com. Could you please try again?
b

brave-dinner-47346

02/28/2022, 1:34 PM
{"data":{"project":null}}%
b

busy-agent-35515

02/28/2022, 1:40 PM
Okay, this response can explain the 0 matching comments. Now need to figure out how to actually get something back
Will try to replicate same structure of the project with community edition, will see if it works there. Thanks for running the requests.
šŸ‘ 1
Hey Bryce! May I ask you how is the repo name formed? GitLab cloud/CE doesn't allow to use slashes in the name, and your full path has two. I suspect this may be an issue for the GraphQL API. However I'm confused as it worked for posting the comment apparently (we use REST API for posting). I've tried the curl request on an local CE server and that's how the result looks like for no results:
{"data":{"project":{"mergeRequest":{"notes":{"nodes":[]}}}}}%
and with one comment returned:
{"data":{"project":{"mergeRequest":{"notes":{"nodes":[{"id":"<gid://gitlab/Note/1>","url":"<http://gitlab.example.com/root/terraform-test/-/merge_requests/1#note_1>","createdAt":"2022-03-01T11:04:04Z","body":"foobar"}]}}}}}%
b

brave-dinner-47346

03/01/2022, 11:59 AM
.com/mmsys/fed/EMR
mr url
com/mmsys/fed/EMR/-/merge_requests/10
b

busy-agent-35515

03/01/2022, 12:26 PM
Is
mmsys
the org and
fed/EMR
a project name? Or
mmsys/fed
and
EMR
? Sorry, I don't have much experience with GitLab, so trying to understand where to investigate next šŸ™‚
b

brave-dinner-47346

03/01/2022, 1:28 PM
mmsys is the parent group, then a sub group of FED
šŸ‘ 1
EMR is the repo name
šŸ‘ 1
b

busy-agent-35515

03/01/2022, 4:29 PM
Reproduced the issue with replicated group/subgroup/repo project. First, I saw the same response you receive and thought something's wrong with the API. I tried
Project Access Tokens
with api or all scopes. Then I switched the test repo to be public and the curl request started to return proper data. And then I use
Personal Access Token
with api scope and private repo - it also worked. Here's the response
{"data":{"project":{"mergeRequest":{"notes":{"nodes":[{"id":"<gid://gitlab/Note/2>","url":"<http://gitlab.example.com/mssys/fed/emr/-/merge_requests/1#note_2>","createdAt":"2022-03-01T16:22:55Z","body":"foobar"}]}}}}}%
The
infracost comment
command also worked with that access token. Could you please double check what kind of token do you use?
b

brave-dinner-47346

03/02/2022, 10:01 AM
I was using a Repo user access token, but I can try with a personal token to verify
šŸ™Œ 1
Yah, so that works with my user access token in the ci/cd as well as locally. Strange
šŸ‘ 1
I'll see if i can get an application user to set this up without my personal user
b

busy-agent-35515

03/02/2022, 10:16 AM
I still don't know the reason why it's happening, but I hope it unblocks your work. If I find anything about it, I'll let you know. We also need to mention this case in our documentation's troubleshooting guide.
b

brave-dinner-47346

03/02/2022, 10:18 AM
its easier to get an application user regardless as gitlab doesnt seem to offer group level access tokens, only repo specific access tokens for api access
b

busy-agent-35515

03/02/2022, 10:20 AM
True, but it's still strange that the repo token doesn't have access to the repo in GraphQL, but REST API works fine. Might be a bug on GitLab side
b

brave-dinner-47346

03/02/2022, 10:30 AM
oh fake news, gitlab includes group level tokens in 14.7
b

busy-agent-35515

03/02/2022, 10:31 AM
But do they work for your repo? šŸ™‚
b

brave-dinner-47346

03/02/2022, 10:39 AM
well I guess ill learn that when we upgrade our gitlab server
šŸ¤ž 1
could also be a bug with my specific gitlab version
b

busy-agent-35515

03/02/2022, 10:45 AM
How do you see the update comment feature? Does it work as you expect?
b

brave-dinner-47346

03/02/2022, 10:47 AM
Yah, aside from using my personal token šŸ˜›
šŸ™‚ 1