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

Version Endpoint #2009

Merged
merged 3 commits into from
Sep 29, 2021
Merged

Version Endpoint #2009

merged 3 commits into from
Sep 29, 2021

Conversation

SyntaxNode
Copy link
Contributor

Implements #1172

}{
Revision: revision,
Version: version,
})
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated the version endpoint to create a static response once at startup, mimicking the pattern used for the bidder info handler. Changed response structure to list the revision first to match PBS-Java. This is not a breaking change for the admin endpoint and we might as well make it match for the public debut.

@@ -310,6 +311,7 @@ func New(cfg *config.Configuration, rateConvertor *currency.RateConverter) (r *R
r.POST("/cookie_sync", endpoints.NewCookieSyncEndpoint(syncersByBidder, cfg, gdprPerms, r.MetricsEngine, pbsAnalytics, activeBidders).Handle)
r.GET("/status", endpoints.NewStatusEndpoint(cfg.StatusResponse))
r.GET("/", serveIndex)
r.Handler("GET", "/version", endpoints.NewVersionEndpoint(version.Ver, version.Rev))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The endpoint registration looks different because it's adapting to the http.Handle interface already in use by the admin endpoint. The r.GET call is just syntactical sugar around this anyway.

}
if revision == "" {
revision = versionNotSet
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: This could be a bit confusing. Ideally we should assign revisionNotSet and not versionNotSet to revision. Do you think renaming versionNotSet to either notSet or valueNotSet could be more straightforward?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed for clarity. I cannot rename it notSet or valueNotSet because it's in the same package (naming scope) as other endpoints.

})
if err != nil {
glog.Errorf("/version Critical error when trying to marshal versionModel: %v", err)
w.WriteHeader(http.StatusInternalServerError)
Copy link
Contributor

Choose a reason for hiding this comment

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

I see we are not using w.WriteHeader(http.StatusInternalServerError) in the new version. Why are we not writing this error anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved the json marshal outside of the endpoint, so that it happens only once at application startup. If it fails, PBS will panic. Thus, it's no longer possible for the error to occur within the endpoint.

version: "1.2.3",
revision: "d6cd1e2bd19e03a81132a23b2025920577f84e37",
expected: `{"revision":"d6cd1e2bd19e03a81132a23b2025920577f84e37","version":"1.2.3"}`,
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we include these additional two tests?

    {
        description: "Empty",
        version:     "1.2.3",
        revision:    "",
        expected:    `{"revision":"not-set","version":"1.2.3"}`,
    },
    {
    	description: "Populated",
    	version:     "",
    	revision:    "d6cd1e2bd19e03a81132a23b2025920577f84e37",
    	expected:    `{"revision":"d6cd1e2bd19e03a81132a23b2025920577f84e37","version":"not-set"}`,
    },

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure.

Copy link
Collaborator

@bsardo bsardo left a comment

Choose a reason for hiding this comment

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

LGTM

@bsardo bsardo merged commit 4908326 into prebid:master Sep 29, 2021
@SyntaxNode SyntaxNode deleted the version_endpoint branch October 5, 2021 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants