We understand that we derive Lagrange equations, $$\frac{d}{dt}\left(\frac{\partial L}{\partial \dot{q}_j}\right)-\frac{\partial L}{\partial q_j}=0, \tag{1}$$ starting from d'Alembert's principle of virtual work being zero, which is, $$({\bf F}_i-\dot{{\bf p}_i})\cdot\delta {\bf r}_i=0, \tag{2}$$ with the help of generalized coordinates.
In the same spirit, from the calculus of variations, starting from optimizing the action (Hamilton's principle), and for a generic function, $f(y,\dot{y},x)$, we obtain the differential equation, $$\frac{d}{dx}\left(\frac{\partial f}{\partial \dot{y}}\right)-\frac{\partial f}{\partial y}=0. \tag{3}$$
In the spirit of Goldstein's Classical Mechanics, we simply identify Euler-Lagrange equations as follows,
$$x \rightarrow t,$$ $$y \rightarrow q_j,$$ $$f \rightarrow L.$$ How do we recognize this last identification? Is it from the semblance of the eqs. (1) and (3)? Or is there any other reasoning involved? Like, if we didn't know the d'Alembert's principle, then, how do we know for sure that "Lagrangian is the function that extremizes the action functional"?