Skip to content

Commit

Permalink
[Issue #3149] Add DEPLOY_WHOAMI to deployment metadata (#3186)
Browse files Browse the repository at this point in the history
## Summary
Fixes #3149

### Time to review: __2 mins__

## Changes proposed
Add who did a deploy to the deployment metadata info

## Context for reviewers
In prod, this will basically always be `runner`, has some additional
usage for non-prod environments to see if someone overrode an
environment

## Additional information
Example response locally:
```json
{
  "data": {
    "commit_link": "ffaca64",
    "commit_sha": "ffaca647223e0b6e54344122eefa73401f5ec131",
    "deploy_whoami": "local-developer",
    "last_deploy_time": "2024-12-02T16:25:18-05:00",
    "release_notes_link": "https://github.com/HHS/simpler-grants-gov/releases"
  },
  "message": "Service healthy",
  "status_code": 200
}
```

---------

Co-authored-by: nava-platform-bot <[email protected]>
  • Loading branch information
chouinar and nava-platform-bot authored Dec 11, 2024
1 parent c4c7fba commit 0594fe0
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions api/local.env
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,4 @@ EXPORT_OPP_DATA_FILE_PATH=/tmp
DEPLOY_GITHUB_REF=main
DEPLOY_GITHUB_SHA=ffaca647223e0b6e54344122eefa73401f5ec131
DEPLOY_TIMESTAMP=2024-12-02T21:25:18Z
DEPLOY_WHOAMI=local-developer
8 changes: 6 additions & 2 deletions api/openapi.generated.yml
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,10 @@ components:
type: string
format: date-time
description: Latest deploy time in US/Eastern timezone
deploy_whoami:
type: string
description: The latest user to deploy the application
example: runner
HealthcheckResponse:
type: object
properties:
Expand Down Expand Up @@ -1080,7 +1084,7 @@ components:
- archived
type:
- string
AgencyFilterV11:
AgencySearchFilterV1:
type: object
properties:
one_of:
Expand Down Expand Up @@ -1223,7 +1227,7 @@ components:
type:
- object
allOf:
- $ref: '#/components/schemas/AgencyFilterV11'
- $ref: '#/components/schemas/AgencySearchFilterV1'
assistance_listing_number:
type:
- object
Expand Down
5 changes: 5 additions & 0 deletions api/src/api/healthcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ class HealthcheckMetadataSchema(Schema):
metadata={"description": "Latest deploy time in US/Eastern timezone"}
)

deploy_whoami = fields.String(
metadata={"description": "The latest user to deploy the application", "example": "runner"}
)


class HealthcheckResponseSchema(AbstractResponseSchema):
# We don't have any data to return with the healthcheck endpoint
Expand Down Expand Up @@ -71,6 +75,7 @@ def health(db_session: db.Session) -> response.ApiResponse:
"commit_link": metadata_config.deploy_commit,
"release_notes_link": metadata_config.release_notes,
"last_deploy_time": metadata_config.deploy_datetime_est,
"deploy_whoami": metadata_config.deploy_whoami,
}

return response.ApiResponse(message="Service healthy", data=data)
2 changes: 1 addition & 1 deletion api/src/api/opportunities_v1/opportunity_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ class OpportunitySearchFilterV1Schema(Schema):
.build()
)
agency = fields.Nested(
StrSearchSchemaBuilder("AgencyFilterV1Schema")
StrSearchSchemaBuilder("AgencySearchFilterV1Schema")
.with_one_of(example="USAID", minimum_length=2)
.build()
)
Expand Down
1 change: 1 addition & 0 deletions api/src/logging/flask_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def init_app(app_logger: logging.Logger, app: flask.Flask) -> None:
"environment": os.environ.get("ENVIRONMENT"),
"deploy_github_ref": deploy_metadata.deploy_github_ref,
"deploy_github_sha": deploy_metadata.deploy_github_sha,
"deploy_whoami": deploy_metadata.deploy_whoami,
}
)

Expand Down
1 change: 1 addition & 0 deletions api/src/util/deploy_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class DeployMetadataConfig(PydanticBaseEnvConfig):
deploy_github_ref: str | None = None # DEPLOY_GITHUB_REF
deploy_github_sha: str | None = None # DEPLOY_GITHUB_SHA
deploy_timestamp: datetime | None = None # DEPLOY_TIMESTAMP
deploy_whoami: str | None = None # DEPLOY_WHOAMI

def model_post_init(self, _context: typing.Any) -> None:
"""Run after __init__ sets above values from env vars"""
Expand Down
1 change: 1 addition & 0 deletions api/tests/src/api/test_healthcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def test_get_healthcheck_200(client, monkeypatch):
"https://github.com/HHS/simpler-grants-gov/releases"
)
assert datetime.fromisoformat(resp_json["data"]["last_deploy_time"]) is not None
assert resp_json["data"]["deploy_whoami"] == "local-developer"


def test_get_healthcheck_503_db_bad_state(client, monkeypatch):
Expand Down

0 comments on commit 0594fe0

Please sign in to comment.