A note on the compactness of the index set in convex optimization. Application to metric regularity